private void FrmMain_Load(object sender, EventArgs e) { this.toolStripStatusLabel1.Text = "流程引擎单元测试"; this.textBox1.Text = ""; // let admin login. BP.WF.Dev2Interface.Port_Login("admin"); #region 执行补充的sql, 让外键的字段长度都设置成100. DBAccess.RunSQL("UPDATE Sys_MapAttr SET maxlen=100 WHERE LGType=2 AND MaxLen<100"); DBAccess.RunSQL("UPDATE Sys_MapAttr SET maxlen=100 WHERE KeyOfEn='FK_Dept'"); Nodes nds = new Nodes(); nds.RetrieveAll(); foreach (Node nd in nds) { nd.HisWork.CheckPhysicsTable(); } //装载部门数据. string sqlscript = ""; sqlscript = SystemConfig.PathOfData + "\\Install\\SQLScript\\Port_Inc_CH.sql"; BP.DA.DBAccess.RunSQLScript(sqlscript); BP.SystemConfig.DoClearCash_del(); BP.WF.Dev2Interface.Port_Login("admin"); #endregion 执行补充的sql, 让外键的字段长度都设置成100. BP.WF.GenerWorkerList gwl = new GenerWorkerList(); gwl.CheckPhysicsTable(); BP.WF.GenerWorkFlow wf = new GenerWorkFlow(); wf.CheckPhysicsTable(); }
/// <summary> /// 步骤1 让zhanghaicheng 发起流程. /// </summary> public void Step1() { //给发起人赋值. starterEmp = new Port.Emp(userNo); //让 userNo 登录. BP.WF.Dev2Interface.Port_Login(userNo); //创建空白工作, 发起开始节点. workID = BP.WF.Dev2Interface.Node_CreateBlankWork(fk_flow, null, null, WebUser.No, null, 0, null); #region 检查创建工作是否符合预期. //检查开始节点写入的数据是否正确? sql = "SELECT * FROM ND2301 WHERE OID=" + workID; dt = DBAccess.RunSQLReturnTable(sql); if (dt.Rows.Count != 1) { throw new Exception("@发起流程出错误,不应该找不到开始节点的数据."); } foreach (DataColumn dc in dt.Columns) { string val = dt.Rows[0][dc.ColumnName].ToString(); switch (dc.ColumnName) { case WorkAttr.CDT: if (val.Contains(DataType.CurrentData) == false) { throw new Exception("CDT,日期错误.现在的日期是:" + val); } break; case WorkAttr.RDT: if (val.Contains(DataType.CurrentData) == false) { throw new Exception("RDT,日期错误.现在的日期是:" + val); } break; case WorkAttr.Emps: if (val.Contains(WebUser.No) == false) { throw new Exception("应当包含当前人员,现在是:" + val); } break; case WorkAttr.FID: if (val != "0") { throw new Exception("应当 = 0,现在是:" + val); } break; case WorkAttr.MD5: //if (Glo.ism //if (val !="0") // throw new Exception("应当 = 0,现在是:"+val); break; case WorkAttr.MyNum: if (val != "1") { throw new Exception("应当 = 1,现在是:" + val); } break; case WorkAttr.Rec: if (val != WebUser.No) { throw new Exception("应当 Rec= " + WebUser.No + ",现在是:" + val); } break; //case WorkAttr.Sender: // if (val != WebUser.No) // throw new Exception("应当 Sender= " + WebUser.No + ",现在是:" + val); // break; default: break; } } //检查流程表的数据. sql = "SELECT * FROM " + fl.PTable + " WHERE OID=" + workID; dt = DBAccess.RunSQLReturnTable(sql); if (dt.Rows.Count != 1) { throw new Exception("@流程报表数据被删除了."); } foreach (DataColumn dc in dt.Columns) { string val = dt.Rows[0][dc.ColumnName].ToString(); switch (dc.ColumnName) { case GERptAttr.FID: if (val != "0") { throw new Exception("@应当是0"); } break; case GERptAttr.FK_Dept: if (val != WebUser.FK_Dept) { throw new Exception("@应当是" + WebUser.FK_Dept + ", 现在是:" + val); } break; case GERptAttr.FK_NY: if (val != DataType.CurrentYearMonth) { throw new Exception("@应当是" + DataType.CurrentYearMonth + ", 现在是:" + val); } break; case GERptAttr.FlowDaySpan: if (val != "0") { throw new Exception("@应当是 0 , 现在是:" + val); } break; case GERptAttr.FlowEmps: if (val.Contains(WebUser.No) == false) { throw new Exception("@应当是包含当前人员, 现在是:" + val); } break; case GERptAttr.FlowEnder: if (val != WebUser.No) { throw new Exception("@应当是 当前人员, 现在是:" + val); } break; case GERptAttr.FlowEnderRDT: if (val.Contains(DataType.CurrentData) == false) { throw new Exception("@应当是 当前日期, 现在是:" + val); } break; case GERptAttr.FlowEndNode: if (val != "2301") { throw new Exception("@应当是 2301, 现在是:" + val); } break; case GERptAttr.FlowStarter: if (val != WebUser.No) { throw new Exception("@应当是 WebUser.No, 现在是:" + val); } break; case GERptAttr.FlowStartRDT: if (string.IsNullOrEmpty(val)) { throw new Exception("@应当不能为空,现在是:" + val); } break; case GERptAttr.Title: if (string.IsNullOrEmpty(val)) { throw new Exception("@不能为空title" + val); } break; case GERptAttr.WFState: WFState sta = (WFState)int.Parse(val); if (sta != WFState.Blank) { throw new Exception("@应当是 WFState.Blank 现在是" + sta.ToString()); } break; default: break; } } #endregion 检查创建工作是否符合预期 //定义一个参数. Hashtable ht = new System.Collections.Hashtable(); ht.Add("GoTo", 1); ht.Add("MyPara", "TestPara"); //执行发送. objs = BP.WF.Dev2Interface.Node_SendWork(fk_flow, workID, ht); #region 第1步: 检查发送对象. //从获取的发送对象里获取到下一个工作者. zhangyifan(张一帆)、zhoushengyu(周升雨). if (objs.VarAcceptersID != "zhoupeng") { throw new Exception("@下一步的接受人不正确, 应当是: zhoupeng.现在是:" + objs.VarAcceptersID); } if (objs.VarToNodeID != 2302) { throw new Exception("@应该是 2302 节点. 现在是:" + objs.VarToNodeID); } if (objs.VarWorkID != workID) { throw new Exception("@主线程的workid不应该变化:" + objs.VarWorkID); } if (objs.VarCurrNodeID != 2301) { throw new Exception("@当前节点的编号不能变化:" + objs.VarCurrNodeID); } if (objs.VarTreadWorkIDs != null) { throw new Exception("@不应当获得子线程WorkID."); } #endregion 第1步: 检查发送对象. #region 第2步: 检查流程引擎表. //检查创建这个空白是否有数据完整? sql = "SELECT * FROM WF_EmpWorks WHERE WorkID=" + workID + " AND FK_Emp='" + objs.VarAcceptersID + "'"; dt = DBAccess.RunSQLReturnTable(sql); if (dt.Rows.Count == 0) { throw new Exception("@不应该找不到当前人员的待办."); } gwf = new GenerWorkFlow(workID); if (gwf.Starter != WebUser.No || gwf.StarterName != WebUser.Name) { throw new Exception("没有写入发起人的信息."); } if (gwf.FK_Dept != starterEmp.FK_Dept) { throw new Exception("@发起人的部门有变化,应当是" + starterEmp.FK_Dept + ",现在是:" + gwf.FK_Dept); } if (gwf.Starter != starterEmp.No) { throw new Exception("@发起人的 No 有变化,应当是" + starterEmp.No + ",现在是:" + gwf.Starter); } //判断当前点. if (gwf.FK_Node != 2302) { throw new Exception("@当前点应该是 2302 现在是:" + gwf.FK_Node); } //判断当前点. if (gwf.FID != 0) { throw new Exception("@当前点应该是 FID=0 现在是:" + gwf.FID); } //判断PWorkID,没有谁调用它,应当是 0. if (gwf.PWorkID != 0) { throw new Exception("@没有谁调用它, 当前点应该是 PWorkID=0 现在是:" + gwf.PWorkID); } //判断 WFState . if (gwf.WFState != WFState.Runing) { throw new Exception("@应当是 WFState=Runing 现在是:" + gwf.WFState.ToString()); } //检查开始节点 发送人的WF_GenerWorkerList的. gwl = new GenerWorkerList(); gwl.CheckPhysicsTable(); gwl.FK_Emp = Web.WebUser.No; gwl.FK_Node = 2301; gwl.WorkID = workID; gwl.Retrieve(); // 没有分合流应当是 0 . if (gwl.FID != 0) { throw new Exception("@没有分合流应当是 0."); } if (gwl.IsEnable == false) { throw new Exception("@应该是启用的状态 "); } if (gwl.IsPass == false) { throw new Exception("@应该是通过的状态 "); } if (gwl.Sender.Contains(WebUser.No) == false) { throw new Exception("@应该是 包含当前状态 . "); } if (gwl.Paras != "@MyPara=TestPara@GoTo=1") { throw new Exception("@参数应当是:@MyPara=TestPara@GoTo=1 .现在是:" + gwl.Paras); } //检查接受人的 WF_GenerWorkerList 的. gwl = new GenerWorkerList(); gwl.FK_Emp = objs.VarAcceptersID; gwl.FK_Node = 2302; gwl.WorkID = workID; gwl.Retrieve(); // 没有分合流应当是 0 . if (gwl.FID != 0) { throw new Exception("@没有分合流应当是 0."); } if (gwl.IsEnable == false) { throw new Exception("@应该是启用的状态 "); } if (gwl.IsPass == true) { throw new Exception("@应该是未通过的状态 "); } if (gwl.Sender.Contains(WebUser.No) == false) { throw new Exception("@应该是 当前人发送的,现在是: " + gwl.Sender); } #endregion 第2步: 检查流程引擎表. #region 第3步: 检查节点数据表. sql = "SELECT * FROM ND2301 WHERE OID=" + workID; dt = DBAccess.RunSQLReturnTable(sql); if (dt.Rows.Count != 1) { throw new Exception("@发起流程出错误,不应该找不到开始节点的数据."); } foreach (DataColumn dc in dt.Columns) { string val = dt.Rows[0][dc.ColumnName].ToString(); switch (dc.ColumnName) { case WorkAttr.CDT: if (val.Contains(DataType.CurrentData) == false) { throw new Exception("CDT,日期错误."); } break; case WorkAttr.RDT: if (val.Contains(DataType.CurrentData) == false) { throw new Exception("RDT,日期错误."); } break; case WorkAttr.Emps: if (val.Contains(WebUser.No) == false) { throw new Exception("应当包含当前人员,现在是:" + val); } break; case WorkAttr.FID: if (val != "0") { throw new Exception("应当 = 0,现在是:" + val); } break; case WorkAttr.MD5: //if (Glo.ism //if (val !="0") // throw new Exception("应当 = 0,现在是:"+val); break; case WorkAttr.MyNum: if (val != "1") { throw new Exception("应当 = 1,现在是:" + val); } break; case WorkAttr.Rec: if (val != WebUser.No) { throw new Exception("应当 Rec= " + WebUser.No + ",现在是:" + val); } break; //case WorkAttr.Sender: // if (val != WebUser.No) // throw new Exception("应当 Sender= " + WebUser.No + ",现在是:" + val); // break; default: break; } } //检查节点2的数据. sql = "SELECT * FROM ND2302 WHERE OID=" + workID; dt = DBAccess.RunSQLReturnTable(sql); if (dt.Rows.Count != 1) { throw new Exception("@发起流程出错误,不应该找不到 ND2302 的数据."); } foreach (DataColumn dc in dt.Columns) { string val = dt.Rows[0][dc.ColumnName].ToString(); switch (dc.ColumnName) { case WorkAttr.CDT: if (val.Contains(DataType.CurrentData) == false) { throw new Exception("CDT,日期错误."); } break; case WorkAttr.RDT: if (val.Contains(DataType.CurrentData) == false) { throw new Exception("RDT,日期错误."); } break; case WorkAttr.Emps: if (val.Contains("zhoupeng") == false) { throw new Exception("第二步骤的处理人员,应当zhoupeng ,现在是:" + val); } break; case WorkAttr.FID: if (val != "0") { throw new Exception("应当 = 0,现在是:" + val); } break; case WorkAttr.MD5: //if (Glo.ism //if (val !="0") // throw new Exception("应当 = 0,现在是:"+val); break; case WorkAttr.MyNum: if (val != "1") { throw new Exception("应当 = 1,现在是:" + val); } break; case WorkAttr.Rec: if (val != "zhoupeng") { throw new Exception("应当 Rec= zhoupeng,现在是:" + val); } break; default: break; } } //检查流程表的数据. sql = "SELECT * FROM " + fl.PTable + " WHERE OID=" + workID; dt = DBAccess.RunSQLReturnTable(sql); if (dt.Rows.Count != 1) { throw new Exception("@流程报表数据被删除了."); } foreach (DataColumn dc in dt.Columns) { string val = dt.Rows[0][dc.ColumnName].ToString(); switch (dc.ColumnName) { case GERptAttr.FID: if (val != "0") { throw new Exception("@应当是0"); } break; case GERptAttr.FK_Dept: if (val != WebUser.FK_Dept) { throw new Exception("@应当是" + WebUser.FK_Dept + ", 现在是:" + val); } break; case GERptAttr.FK_NY: if (val != DataType.CurrentYearMonth) { throw new Exception("@应当是" + DataType.CurrentYearMonth + ", 现在是:" + val); } break; case GERptAttr.FlowDaySpan: if (val != "0") { throw new Exception("@应当是 0 , 现在是:" + val); } break; case GERptAttr.FlowEmps: if (val.Contains(WebUser.No) == false) { throw new Exception("@应当是包含当前人员, 现在是:" + val); } break; case GERptAttr.FlowEnder: if (val != WebUser.No) { throw new Exception("@应当是 当前人员, 现在是:" + val); } break; case GERptAttr.FlowEnderRDT: if (val.Contains(DataType.CurrentData) == false) { throw new Exception("@应当是 当前日期, 现在是:" + val); } break; case GERptAttr.FlowEndNode: if (val != "2302") { throw new Exception("@应当是 2302, 现在是:" + val); } break; case GERptAttr.FlowStarter: if (val != WebUser.No) { throw new Exception("@应当是 WebUser.No, 现在是:" + val); } break; case GERptAttr.FlowStartRDT: if (string.IsNullOrEmpty(val)) { throw new Exception("@应当不能为空,现在是:" + val); } break; case GERptAttr.Title: if (string.IsNullOrEmpty(val)) { throw new Exception("@不能为空title" + val); } break; case GERptAttr.WFState: WFState sta = (WFState)int.Parse(val); if (sta != WFState.Runing) { throw new Exception("@应当是 WFState.Runing 现在是" + sta.ToString()); } break; default: break; } } #endregion 第3步: 检查节点数据表. }