利用LR测试程序基类的性能

上一篇 / 下一篇  2006-12-07 20:14:27 / 个人分类:LoadRunner

Note: posted on 2006-10-12 13:34 北北

在VUSERCLASS中写方法,在METHOD中写参数调用,等于参数化了。

VuserClass代码如下 :

using System;
using System.Collections;
using System.Diagnostics;
using System.EnterpriseServices;
using System.Runtime.InteropServices;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Data;
using System.Web;
using System.Reflection;

using Common;
using Proxy;
using DAT;
using ShangXin;
using ShangXin.Data;
using ShangXinInterface;
namespace LRQueryCustomer
{
 ///


 /// Summary descrīption for VuserClass.
 ///

 [ClassInterface(ClassInterfaceType.AutoDual)]
 public class VuserClass
 { 
  public static string ifCanCreatePuDongOrderWithBiz = "";
  Proxy.LoginProxy loginProxy;
  Method methodLR = new Method();
  LoadRunner.LrApi lr;

  public VuserClass()
  {
   // LoadRunner Standard API Interface ::             DO NOT REMOVE!!!
   lr = new LoadRunner.LrApi();
  }

  // ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  public int Initialize()
  {
  try
   {
   RemotingConfiguration.Configure(@"D:\Escalade liunx\CODE_20051020100023\Code\OAERP\ShangXin.OAERP.App\bin\Debug\App.exe.config");

   lr.start_transaction("init");
   lr.start_transaction("GetLoginByLoginNameAndPassword");
   loginProxy = new LoginProxy();
   LoginData loginData = loginProxy.GetLoginByLoginNameAndPassword("administrator","");
   lr.end_transaction("GetLoginByLoginNameAndPassword",lr.PASS);

   Proxy.EmployeeProxy employeeProxy = new EmployeeProxy();
   CertificationInfo CI = new CertificationInfo();
   Common.CertificationInfo ci= PersonalCertificationInfo.GetCertificationInfo();

   CI.LoginName = SXConvert.ToString(loginData.Rows[0][LoginData.LOGINNAME]);
   CI.Password = SXConvert.ToString(loginData.Rows[0][LoginData.PASSWORD]);
   CI.EmployeeId = SXConvert.ToInt32(loginData.Rows[0][LoginData.EMPLOYEEID]);
   CI.EmployeeName = employeeProxy.GetEmployeeDataByPKID(SXConvert.ToInt32(loginData.Rows[0][LoginData.EMPLOYEEID])).Rows[0][EmployeeData.NAME].ToString();
   CI.RecordCount = SXConvert.ToInt32(loginData.Rows[0][LoginData.RECORDCOUNT]);

   lr.start_transaction("GetAllAuthsByLoginId");
   int loginID = SXConvert.ToInt32(loginData.Rows[0][LoginData.PKID]);
   AuthData ad = loginProxy.GetAllAuthsByLoginId(loginID);
   methodLR.SetAuth(ad,CI);
   lr.end_transaction("GetAllAuthsByLoginId",lr.PASS);

   lr.start_transaction("GetGroupsByLoginID");
   GroupData groupData = loginProxy.GetGroupsByLoginID(loginID);
   methodLR.GetGroupAuth(groupData,CI);
   lr.end_transaction("GetGroupsByLoginID",lr.PASS);

   lr.start_transaction("AddToCurrentEmployee");
   if (AuthenticationManager.CheckAuthentication(CI,EnumAuthority.AuthLoginSystem))
   {
    methodLR.AddToCurrentEmployee(ci,CI);
    lr.end_transaction("AddToCurrentEmployee",lr.PASS);
    DataRow BizDR = new SystemParameterValueProxy().GetSystemParameterValueByParentCode(SystemParametersCode.CANCREATEPUDONGORDERWITHBIZ,Bools.TRUE).Rows[0];
    ifCanCreatePuDongOrderWithBiz = BizDR[SystemParameterValueData.OTHER1].ToString();
   }
   else
   {
    lr.end_transaction("AddToCurrentEmployee",lr.FAIL);
   }
  
   lr.end_transaction("init",lr.PASS);
  }
  catch(Exception ex)
  {
   string error = ex.Message;
  }
   return lr.PASS;

  }

  // ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  public int Actions()
  {
   
   #region 查询客户
   //条件为空查询
   try
   {
    lr.start_transaction("GetCustomerCountByCondition");
    object[] param = {methodLR.GetQueryCustomerConditions()};

    Object ōbj = System.Activator.CreateInstance(typeof(Proxy.CustomerProxy));
    MethodInfo method = obj.GetType().GetMethod("GetCustomerCountByCondition");
    DataTable dt = (DataTable)method.Invoke(obj,param);
    int count = Convert.ToInt32(dt.Rows[0][0]);

    if(count>0)
     lr.end_transaction("GetCustomerCountByCondition",lr.PASS);
    else
     lr.end_transaction("GetCustomerCountByCondition",lr.FAIL);
   }
   catch(Exception ex)
   {
    string error = ex.Message;
   }

   //按客户编号查询
   try
   {
    lr.start_transaction("GetCustomerCountByCode");
    object[] param1 = {methodLR.GetQueryCustomerByCodeConditions()};

    Object obj1 = System.Activator.CreateInstance(typeof(Proxy.CustomerProxy));
    MethodInfo method1 = obj1.GetType().GetMethod("GetCustomerCountByCondition");
    DataTable dt1 = (DataTable)method1.Invoke(obj1,param1);
    int count1 = Convert.ToInt32(dt1.Rows[0][0]);

    if(count1>0)
     lr.end_transaction("GetCustomerCountByCode",lr.PASS);
    else
     lr.end_transaction("GetCustomerCountByCode",lr.FAIL);
   }
   catch(Exception ex)
   {
    string error = ex.Message;
   }

   //按客户名称查询
   try
   {
    lr.start_transaction("GetCustomerCountByCustomerName");
    object[] param2 = {methodLR.GetQueryCustomerByCustomerName()};

    Object obj2 = System.Activator.CreateInstance(typeof(Proxy.CustomerProxy));
    MethodInfo method2 = obj2.GetType().GetMethod("GetCustomerCountByCondition");
    DataTable dt2 = (DataTable)method2.Invoke(obj2,param2);
    int count2 = Convert.ToInt32(dt2.Rows[0][0]);

    if(count2>0)
     lr.end_transaction("GetCustomerCountByCustomerName",lr.PASS);
    else
     lr.end_transaction("GetCustomerCountByCustomerName",lr.FAIL);
   }
   catch(Exception ex)
   {
    string error = ex.Message;
   }

   //按客户类型查询
   try
   {
    lr.start_transaction("GetCustomerCountByCustomerTypeId");
    object[] param3 = {methodLR.GetQueryCustomerByCustomerTypeId()};

    Object obj3 = System.Activator.CreateInstance(typeof(Proxy.CustomerProxy));
    MethodInfo method3 = obj3.GetType().GetMethod("GetCustomerCountByCondition");
    DataTable dt3 = (DataTable)method3.Invoke(obj3,param3);
    int count3 = Convert.ToInt32(dt3.Rows[0][0]);

    if(count3>0)
     lr.end_transaction("GetCustomerCountByCustomerTypeId",lr.PASS);
    else
     lr.end_transaction("GetCustomerCountByCustomerTypeId",lr.FAIL);
   }
   catch(Exception ex)
   {
    string error = ex.Message;
   }

   //按销售员查询
   try
   {
    lr.start_transaction("GetCustomerCountBySalesManId");
    object[] param4 = {methodLR.GetQueryCustomerBySalesManId()};

    Object obj4 = System.Activator.CreateInstance(typeof(Proxy.CustomerProxy));
    MethodInfo method4 = obj4.GetType().GetMethod("GetCustomerCountByCondition");
    DataTable dt4 = (DataTable)method4.Invoke(obj4,param4);
    int count4 = Convert.ToInt32(dt4.Rows[0][0]);

    if(count4>0)
     lr.end_transaction("GetCustomerCountBySalesManId",lr.PASS);
    else
     lr.end_transaction("GetCustomerCountBySalesManId",lr.FAIL);
   }
   catch(Exception ex)
   {
    string error = ex.Message;
   }

   //按话务员查询
   try
   {
    lr.start_transaction("GetCustomerCountByTelephonistId");
    object[] param5 = {methodLR.GetQueryCustomerByTelephonistId()};

    Object obj5 = System.Activator.CreateInstance(typeof(Proxy.CustomerProxy));
    MethodInfo method5 = obj5.GetType().GetMethod("GetCustomerCountByCondition");
    DataTable dt5 = (DataTable)method5.Invoke(obj5,param5);
    int count5 = Convert.ToInt32(dt5.Rows[0][0]);

    if(count5>0)
     lr.end_transaction("GetCustomerCountByTelephonistId",lr.PASS);
    else
     lr.end_transaction("GetCustomerCountByTelephonistId",lr.FAIL);
   }
   catch(Exception ex)
   {
    string error = ex.Message;
   }

   //按客户电话查询
   try
   {
    lr.start_transaction("GetQueryCustomerByTelephone");
    object[] param6 = {methodLR.GetQueryCustomerByTelephone()};

    Object obj6 = System.Activator.CreateInstance(typeof(Proxy.CustomerProxy));
    MethodInfo method6 = obj6.GetType().GetMethod("GetCustomerCountByCondition");
    DataTable dt6 = (DataTable)method6.Invoke(obj6,param6);
    int count6 = Convert.ToInt32(dt6.Rows[0][0]);

    if(count6>0)
     lr.end_transaction("GetQueryCustomerByTelephone",lr.PASS);
    else
     lr.end_transaction("GetQueryCustomerByTelephone",lr.FAIL);
   }
   catch(Exception ex)
   {
    string error = ex.Message;
   }

   //按客户地址查询
   try
   {
    lr.start_transaction("GetQueryCustomerByAddress");
    object[] param7 = {methodLR.GetQueryCustomerByAddress()};

    Object obj7 = System.Activator.CreateInstance(typeof(Proxy.CustomerProxy));
    MethodInfo method7 = obj7.GetType().GetMethod("GetCustomerCountByCondition");
    DataTable dt7 = (DataTable)method7.Invoke(obj7,param7);
    int count7 = Convert.ToInt32(dt7.Rows[0][0]);

    if(count7>0)
     lr.end_transaction("GetQueryCustomerByAddress",lr.PASS);
    else
     lr.end_transaction("GetQueryCustomerByAddress",lr.FAIL);
   }
   catch(Exception ex)
   {
    string error = ex.Message;
   }

   //综合查询
   try
   {
    lr.start_transaction("GetQueryCustomerByAll");
    object[] param8 = {methodLR.GetQueryCustomerByAll()};

    Object obj8 = System.Activator.CreateInstance(typeof(Proxy.CustomerProxy));
    MethodInfo method8 = obj8.GetType().GetMethod("GetCustomerCountByCondition");
    DataTable dt8 = (DataTable)method8.Invoke(obj8,param8);
    int count8 = Convert.ToInt32(dt8.Rows[0][0]);

    if(count8>0)
     lr.end_transaction("GetQueryCustomerByAll",lr.PASS);
    else
     lr.end_transaction("GetQueryCustomerByAll",lr.FAIL);
   }
   catch(Exception ex)
   {
    string error = ex.Message;
   }

   #endregion      
 
   return lr.PASS;
  }

  // ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  public int Terminate()
  {
   // TO DO: Add virtual user's termination routines

   return lr.PASS;
  }

 }
}

Method代码如下:

using System;
using Common;
using Proxy;
using DAT;
using ShangXin;
using ShangXin.Data;
using ShangXinInterface;
using System.Collections;
using System.Data;

namespace LRQueryCustomer
{
 ///


 /// Method 的摘要说明。
 ///

 public class Method
 { 
  Proxy.LoginProxy loginProxy = new LoginProxy();

  public Method()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }
  public void SetAuth(AuthData auth,CertificationInfo ci)
  {
   for(int i=0;i   {
    ci.AddAuthority((EnumAuthority)(Enum.Parse(typeof(EnumAuthority),auth.Rows[i]["PKID"].ToString())));
   }
  }

  
  public void GetGroupAuth(GroupData groupData,CertificationInfo ci)
  {
   try
   {
    //判断组记录是否为空
    if (groupData.Rows.Count > 0)
    {
     for(int i=0; i     {
      //根据组,获取对应的权限信息,并加载到该用户的权限列表中
      int groupID = SXConvert.ToInt32(groupData.Rows[i][GroupData.PKID]);
      AuthData Groupad = loginProxy.GetGroupAuthByGroupId(groupID);
     
      //加载权限
      if (Groupad.Rows.Count > 0)
      {
       SetAuth(Groupad,ci);
       ci.AddGroup(groupID);
      }

      int parentGroupID = loginProxy.GetParentGroupByGroupID(groupID);

      if (parentGroupID > 0)
      {
       GroupData subGroupData = loginProxy.GetGroupByPKID(parentGroupID);

       //循环加载
       GetGroupAuth(subGroupData,ci);
      }
     }
    }
   }
   catch(Exception exp)
   {
    throw new Exception(exp.Message);
   }
  }
   public void AddToCurrentEmployee(CertificationInfo ci,CertificationInfo CI)
   {
    //先清空当前用户的权限列表
    ci.ClearAuthority();

    //增加基本属性与权限列表
    ci.LoginName = CI.LoginName;
    ci.Password = CI.Password;
    ci.EmployeeId = CI.EmployeeId;
    ci.EmployeeName = CI.EmployeeName;
    ci.RecordCount = CI.RecordCount;

    for(int i=0;i    {
     ci.AddAuthority((EnumAuthority)CI.Authority[i]);
    }

    for(int i=0;i    {
     ci.AddGroup((int)CI.Group[i]);
    }
   }

  #region 查询客户
  //条件为空查询
  public Hashtable GetQueryCustomerConditions()
  {
   Hashtable conditions = new Hashtable();
   int parentId = -1;//上一级公司
   int customerTypeId = -1;//客户类型
   string code = "";//客户编码
   int salesManId = -1;//销售员
   int employeeId = 64;//
   string customerName = "";//客户名称
   int telePhinstId = -1;//话务员   
   string telephone="";//客户电话
   string address="";//客户地址
   
   conditions.Add("PARENTID",parentId);
   conditions.Add("CUSTOMERTYPEID",customerTypeId);
   conditions.Add("CODE",code);
   conditions.Add("SALESMANID",salesManId);
   conditions.Add("EMPLOYEEID",employeeId);
   conditions.Add("CUSTOMERNAME",customerName);
   conditions.Add("TELEPHINSTID",telePhinstId);
   conditions.Add("TELEPHONE",telephone);
   conditions.Add("ADDRESS",address);

   return conditions;

  }

  //按客户编号查询
  public Hashtable GetQueryCustomerByCodeConditions()
  {
   Hashtable conditions = new Hashtable();
   int parentId = -1;//上一级公司
   int customerTypeId = -1;//客户类型
   string code = "31450";//客户编码
   int salesManId = -1;//销售员
   int employeeId = 64;//
   string customerName = "";//客户名称
   int telePhinstId = -1;//话务员   
   string telephone="";//客户电话
   string address="";//客户地址
   
   conditions.Add("PARENTID",parentId);
   conditions.Add("CUSTOMERTYPEID",customerTypeId);
   conditions.Add("CODE",code);
   conditions.Add("SALESMANID",salesManId);
   conditions.Add("EMPLOYEEID",employeeId);
   conditions.Add("CUSTOMERNAME",customerName);
   conditions.Add("TELEPHINSTID",telePhinstId);
   conditions.Add("TELEPHONE",telephone);
   conditions.Add("ADDRESS",address);

   return conditions;

  }

  //按客户名称查询
  public Hashtable GetQueryCustomerByCustomerName()
  {
   Hashtable conditions = new Hashtable();
   int parentId = -1;//上一级公司
   int customerTypeId = -1;//客户类型
   string code = "";//客户编码
   int salesManId = -1;//销售员
   int employeeId = 64;//
   string customerName = "一本万利公司第31450分公司";//客户名称
   int telePhinstId = -1;//话务员   
   string telephone="";//客户电话
   string address="";//客户地址
   
   conditions.Add("PARENTID",parentId);
   conditions.Add("CUSTOMERTYPEID",customerTypeId);
   conditions.Add("CODE",code);
   conditions.Add("SALESMANID",salesManId);
   conditions.Add("EMPLOYEEID",employeeId);
   conditions.Add("CUSTOMERNAME",customerName);
   conditions.Add("TELEPHINSTID",telePhinstId);
   conditions.Add("TELEPHONE",telephone);
   conditions.Add("ADDRESS",address);

   return conditions;

  }

  //按客户类型查询
  public Hashtable GetQueryCustomerByCustomerTypeId()
  {
   Hashtable conditions = new Hashtable();
   int parentId = -1;//上一级公司
   int customerTypeId = 2;//客户类型
   string code = "";//客户编码
   int salesManId = -1;//销售员
   int employeeId = 64;//
   string customerName = "";//客户名称
   string telePhinstId ="" ;//话务员   
   int telephone=-1;//客户电话
   string address="";//客户地址
   
   conditions.Add("PARENTID",parentId);
   conditions.Add("CUSTOMERTYPEID",customerTypeId);
   conditions.Add("CODE",code);
   conditions.Add("SALESMANID",salesManId);
   conditions.Add("EMPLOYEEID",employeeId);
   conditions.Add("CUSTOMERNAME",customerName);
   conditions.Add("TELEPHINSTID",telePhinstId);
   conditions.Add("TELEPHONE",telephone);
   conditions.Add("ADDRESS",address);
   
   return conditions;

  }

  //按销售员查询
  public Hashtable GetQueryCustomerBySalesManId()
  {
   Hashtable conditions = new Hashtable();
   int parentId = -1;//上一级公司
   int customerTypeId = -1;//客户类型
   string code = "";//客户编码
   int salesManId = 314;//销售员
   int employeeId = 529;//
   string customerName = "";//客户名称
   int telePhinstId = -1;//话务员   
   string telephone="";//客户电话
   string address="";//客户地址
   
   conditions.Add("PARENTID",parentId);
   conditions.Add("CUSTOMERTYPEID",customerTypeId);
   conditions.Add("CODE",code);
   conditions.Add("SALESMANID",salesManId);
   conditions.Add("EMPLOYEEID",employeeId);
   conditions.Add("CUSTOMERNAME",customerName);
   conditions.Add("TELEPHINSTID",telePhinstId);
   conditions.Add("TELEPHONE",telephone);
   conditions.Add("ADDRESS",address);

   return conditions;

  }

  //按话务员查询
  public Hashtable GetQueryCustomerByTelephonistId()
  {
   Hashtable conditions = new Hashtable();
   int parentId = -1;//上一级公司
   int customerTypeId = -1;//客户类型
   string code = "";//客户编码
   int salesManId = -1;//销售员
   int employeeId = 64;//
   string customerName = "";//客户名称
   int telePhinstId = 23;//话务员   
   string telephone="";//客户电话
   string address="";//客户地址
   
   conditions.Add("PARENTID",parentId);
   conditions.Add("CUSTOMERTYPEID",customerTypeId);
   conditions.Add("CODE",code);
   conditions.Add("SALESMANID",salesManId);
   conditions.Add("EMPLOYEEID",employeeId);
   conditions.Add("CUSTOMERNAME",customerName);
   conditions.Add("TELEPHINSTID",telePhinstId);
   conditions.Add("TELEPHONE",telephone);
   conditions.Add("ADDRESS",address);

   return conditions;

  }

  //按客户电话
  public Hashtable GetQueryCustomerByTelephone()
  {
   Hashtable conditions = new Hashtable();
   int parentId = -1;//上一级公司
   int customerTypeId = -1;//客户类型
   string code = "";//客户编码
   int salesManId = -1;//销售员
   int employeeId = 64;//
   string customerName = "";//客户名称
   int telePhinstId = 23;//话务员   
   string telephone="88888888";//客户电话
   string address="";//客户地址
   
   conditions.Add("PARENTID",parentId);
   conditions.Add("CUSTOMERTYPEID",customerTypeId);
   conditions.Add("CODE",code);
   conditions.Add("SALESMANID",salesManId);
   conditions.Add("EMPLOYEEID",employeeId);
   conditions.Add("CUSTOMERNAME",customerName);
   conditions.Add("TELEPHINSTID",telePhinstId);
   conditions.Add("TELEPHONE",telephone);
   conditions.Add("ADDRESS",address);

   return conditions;

  }

  //按客户地址
  public Hashtable GetQueryCustomerByAddress()
  {
   Hashtable conditions = new Hashtable();
   int parentId = -1;//上一级公司
   int customerTypeId = -1;//客户类型
   string code = "";//客户编码
   int salesManId = -1;//销售员
   int employeeId = 64;//
   string customerName = "";//客户名称
   int telePhinstId = 23;//话务员   
   string telephone="";//客户电话
   string address="天堂区幸福大道第31450号";//客户地址
   
   conditions.Add("PARENTID",parentId);
   conditions.Add("CUSTOMERTYPEID",customerTypeId);
   conditions.Add("CODE",code);
   conditions.Add("SALESMANID",salesManId);
   conditions.Add("EMPLOYEEID",employeeId);
   conditions.Add("CUSTOMERNAME",customerName);
   conditions.Add("TELEPHINSTID",telePhinstId);
   conditions.Add("TELEPHONE",telephone);
   conditions.Add("ADDRESS",address);

   return conditions;

  }
  //综合查询
  public Hashtable GetQueryCustomerByAll()
  {
   Hashtable conditions = new Hashtable();
   int parentId = -1;//上一级公司
   int customerTypeId = -1;//客户类型
   string code = "005305";//客户编码
   int salesManId =-1 ;//销售员
   int employeeId = 64;//
   string customerName = "一本万利公司第120分公司";//客户名称
   int telePhinstId =-1;//话务员   
   string telephone="88888888";//客户电话
   string address="天堂区幸福大道第120号";//客户地址
   
   conditions.Add("PARENTID",parentId);
   conditions.Add("CUSTOMERTYPEID",customerTypeId);
   conditions.Add("CODE",code);
   conditions.Add("SALESMANID",salesManId);
   conditions.Add("EMPLOYEEID",employeeId);
   conditions.Add("CUSTOMERNAME",customerName);
   conditions.Add("TELEPHINSTID",telePhinstId);
   conditions.Add("TELEPHONE",telephone);
   conditions.Add("ADDRESS",address);

   return conditions;

  }
  #endregion
 }
}


TAG: LoadRunner 基类 性能

 

评分:0

我来说两句

日历

« 2024-04-24  
 123456
78910111213
14151617181920
21222324252627
282930    

我的存档

数据统计

  • 访问量: 4544
  • 日志数: 5
  • 建立时间: 2006-12-07
  • 更新时间: 2006-12-19

RSS订阅

Open Toolbar