예제 #1
0
        public void BasicAddActivityExecutorTest()
        {
            IWfProcess process = WfProcessTestCommon.StartupSimpleProcess();

            int originalActCount = process.Activities.Count;

            IWfActivity targetActivity = process.Activities.FindActivityByDescriptorKey("NormalActivity");

            WfActivityDescriptorCreateParams createParams = new WfActivityDescriptorCreateParams();

            WfAddActivityExecutor executor = new WfAddActivityExecutor(process.CurrentActivity, targetActivity, createParams);

            executor.Execute();

            Assert.IsNotNull(executor.AddedActivity.GetMainStreamActivityDescriptor());
            Assert.AreEqual(originalActCount + 1, process.Activities.Count);

            WfMainStreamActivityDescriptorCollection processDespMSA = process.Descriptor.GetMainStreamActivities();
            WfMainStreamActivityDescriptorCollection processMSA     = process.GetMainStreamActivities(true);

            processDespMSA.Output("流程描述中的主线活动");
            processMSA.Output("主线流程中的主线活动");

            Assert.AreEqual(process.Descriptor.Activities.Count, process.MainStream.Activities.Count);
            Assert.AreEqual(processDespMSA.Count, processMSA.Count);
        }
예제 #2
0
        public void AddActivityWithConsignExecutorTest()
        {
            IWfProcess process = WfProcessTestCommon.StartupSimpleProcess();

            int originalActCount = process.Activities.Count;

            IWfActivity targetActivity = process.Activities.FindActivityByDescriptorKey("NormalActivity");

            WfActivityDescriptorCreateParams createParams = new WfActivityDescriptorCreateParams();

            createParams.AllAgreeWhenConsign = true;
            createParams.Users = new OguDataCollection <IUser>();
            createParams.Users.Add((IUser)OguObjectSettings.GetConfig().Objects["approver1"].Object);
            createParams.Users.Add((IUser)OguObjectSettings.GetConfig().Objects["approver2"].Object);

            WfAddActivityExecutor executor = new WfAddActivityExecutor(process.CurrentActivity, targetActivity, createParams);

            executor.Execute();

            Assert.AreEqual(originalActCount + 1, process.Activities.Count);

            WfMainStreamActivityDescriptorCollection processDespMSA = process.Descriptor.GetMainStreamActivities();
            WfMainStreamActivityDescriptorCollection processMSA     = process.GetMainStreamActivities(true);

            processDespMSA.Output("流程描述中的主线活动");
            processMSA.Output("主线流程中的主线活动");

            Assert.AreEqual(1, executor.AddedActivity.Descriptor.BranchProcessTemplates.Count);
            Assert.AreEqual(1, executor.AddedActivity.GetMainStreamActivityDescriptor().BranchProcessTemplates.Count);

            Assert.AreEqual(process.Descriptor.Activities.Count, process.MainStream.Activities.Count);
            Assert.AreEqual(processDespMSA.Count, processMSA.Count);
        }
예제 #3
0
        public void BaseAddApproverExecutorStandardModeWithWithdrawTest()
        {
            IWfProcess process = WfProcessTestCommon.StartupSimpleProcess();

            int originalActCount = process.Activities.Count;

            WfProcessTestCommon.MoveToNextDefaultActivity(process);

            int originalElapsedActCount = process.ElapsedActivities.Count;

            IWfActivity           targetActivity = process.Activities.FindActivityByDescriptorKey("NormalActivity");
            WfAddApproverExecutor executor       = new WfAddApproverExecutor(process.CurrentActivity, targetActivity);

            executor.Assignees.Add((IUser)OguObjectSettings.GetConfig().Objects[OguObject.approver1.ToString()].Object);
            executor.Execute();

            Console.WriteLine("Elapsed activities: {0}", process.ElapsedActivities.Count);

            process = WfRuntime.GetProcessByProcessID(process.ID);
            WfWithdrawExecutor withdrawExecutor = new WfWithdrawExecutor(process.CurrentActivity, process.CurrentActivity);

            withdrawExecutor.Execute();

            Console.WriteLine("Elapsed activities: {0}", process.ElapsedActivities.Count);

            Assert.AreEqual(originalElapsedActCount, process.ElapsedActivities.Count);
            Assert.AreEqual(originalActCount, process.Activities.Count, "撤回后,恢复为加签之前的状态");
            Assert.AreEqual(originalActCount, process.MainStream.Activities.Count, "撤回后,主线流程的活动也没有变化");

            WfMainStreamActivityDescriptorCollection processDespMSA = process.Descriptor.GetMainStreamActivities();
            WfMainStreamActivityDescriptorCollection processMSA     = process.GetMainStreamActivities(true);

            processDespMSA.Output("流程描述中的主线活动");
            processMSA.Output("主线流程中的主线活动");
        }
예제 #4
0
        public void BaseAddApproverExecutorOnlyAddApproverModeTest()
        {
            IWfProcess process = WfProcessTestCommon.StartupSimpleProcess();

            int originalActCount = process.Activities.Count;

            WfProcessTestCommon.MoveToNextDefaultActivity(process);

            IWfActivity           targetActivity = process.Activities.FindActivityByDescriptorKey("NormalActivity");
            WfAddApproverExecutor executor       = new WfAddApproverExecutor(process.CurrentActivity, targetActivity);

            executor.AddApproverMode = WfAddApproverMode.OnlyAddApprover;

            executor.Assignees.Add((IUser)OguObjectSettings.GetConfig().Objects[OguObject.approver1.ToString()].Object);
            executor.Execute();

            Assert.AreEqual(originalActCount + 1, process.Activities.Count);
            Assert.AreEqual(originalActCount + 1, process.MainStream.Activities.Count);

            WfMainStreamActivityDescriptorCollection processDespMSA = process.Descriptor.GetMainStreamActivities();
            WfMainStreamActivityDescriptorCollection processMSA     = process.GetMainStreamActivities(true);

            processDespMSA.Output("流程描述中的主线活动");
            processMSA.Output("主线流程中的主线活动");
        }
예제 #5
0
        public void ConsignExecutorWithMoveToTest()
        {
            IWfProcess process = WfProcessTestCommon.StartupSimpleProcess();

            List <IUser> users = null;

            //添加会签活动且启动了分支流程
            ConsignExecutorWithCondition(process, out users);

            process = WfRuntime.GetProcessByProcessID(process.ID);

            Assert.IsTrue(process.CurrentActivity.BranchProcessGroups.Count > 0);
            Assert.AreEqual(users.Count, process.CurrentActivity.BranchProcessGroups[0].Branches.Count);

            IWfActivity originalActivity = process.CurrentActivity;

            Assert.AreEqual(WfActivityStatus.Pending, process.CurrentActivity.Status);

            foreach (IWfProcess branchProcess in process.CurrentActivity.BranchProcessGroups[0].Branches)
            {
                IWfProcess subProcess = WfRuntime.GetProcessByProcessID(branchProcess.ID);

                MoveToExecutor(subProcess);
            }

            process = WfRuntime.GetProcessByProcessID(process.ID);

            Assert.AreEqual(originalActivity.ID, process.CurrentActivity.ID);
            Assert.AreEqual(WfActivityStatus.Running, process.CurrentActivity.Status);
        }
예제 #6
0
        public void SimpleProcessMoveTest()
        {
            IWfProcess process = WfProcessTestCommon.StartupSimpleProcess();

            WfTransferParams transferParams = new WfTransferParams(process.Descriptor.CompletedActivity);

            process.MoveTo(transferParams);

            Assert.IsTrue(process.InitialActivity.Status == WfActivityStatus.Completed);
            Assert.IsTrue(process.Status == WfProcessStatus.Completed);
            Assert.IsTrue(process.CompletedActivity.Status == WfActivityStatus.Completed);
        }
예제 #7
0
        public void SimpleProcessRuntimeSerializeTest()
        {
            IWfProcess process = WfProcessTestCommon.StartupSimpleProcess();

            if (process.Activities != null)
            {
                foreach (var activity in process.Activities)
                {
                    if (activity.Descriptor != process.Descriptor.InitialActivity)
                    {
                        Assert.IsTrue(activity.Status == WfActivityStatus.NotRunning);
                        WfTransferParams transferPara = new WfTransferParams(activity.Descriptor);
                        process.MoveTo(transferPara);
                    }
                }
            }

            XElementFormatter formatter = new XElementFormatter();

            XElement root = formatter.Serialize(process);

            Console.WriteLine(root.ToString());

            IWfProcess clonedProcess = (IWfProcess)formatter.Deserialize(root);

            Assert.IsTrue(clonedProcess.Status == WfProcessStatus.Completed);

            for (int i = 0; i < clonedProcess.Activities.Count; i++)
            {
                Assert.IsTrue(clonedProcess.Activities[i].Status == WfActivityStatus.Completed);

                if (i < clonedProcess.Activities.Count - 1)
                {
                    Assert.AreEqual(clonedProcess.Activities[i].Descriptor.ToTransitions[0], clonedProcess.Activities[i + 1].Descriptor.FromTransitions[0]);
                }
            }

            Assert.IsNotNull(clonedProcess.Descriptor.Activities[process.Descriptor.InitialActivity.Key], "验证反序列化后集合字典的完整性");

            XElement reRoot = formatter.Serialize(clonedProcess);

            //31000是否允许被撤回默认值不同true false

            Assert.AreEqual(root.ToString(), reRoot.ToString());


            IWfProcess reClonedProcess = (IWfProcess)formatter.Deserialize(reRoot);

            Assert.AreEqual(clonedProcess.ToString(), reClonedProcess.ToString());
        }
예제 #8
0
        public void AddActivityWithTwoOutTransitionsExecutorTest()
        {
            IWfProcess process = WfProcessTestCommon.StartupSimpleProcess();

            int originalActCount = process.Activities.Count;

            IWfActivity targetActivity = process.Activities.FindActivityByDescriptorKey("NormalActivity");

            targetActivity.Descriptor.ToTransitions.FirstOrDefault().Properties.SetValue("Name", "同意");

            //增加一条出线
            IWfTransitionDescriptor tReturn = targetActivity.Descriptor.ToTransitions.AddBackwardTransition(process.InitialActivity.Descriptor);

            tReturn.Properties.SetValue("Name", "不同意");

            WfActivityDescriptorCreateParams createParams = new WfActivityDescriptorCreateParams();

            createParams.AllAgreeWhenConsign = false;
            createParams.Users = new OguDataCollection <IUser>();
            createParams.Users.Add((IUser)OguObjectSettings.GetConfig().Objects["approver1"].Object);

            WfAddActivityExecutor executor = new WfAddActivityExecutor(process.CurrentActivity, targetActivity, createParams);

            executor.Execute();

            process = WfRuntime.GetProcessByProcessID(process.ID);

            IWfActivity addedActivity = process.Activities[executor.AddedActivity.ID];

            targetActivity = process.Activities.FindActivityByDescriptorKey("NormalActivity");

            Assert.AreEqual(originalActCount + 1, process.Activities.Count);
            Assert.AreEqual(1, targetActivity.Descriptor.ToTransitions.Count);
            Assert.IsFalse(targetActivity.Descriptor.ToTransitions[0].IsBackward);

            Assert.AreEqual(2, addedActivity.Descriptor.ToTransitions.Count, "新加的活动应该也有两条出线");
            Assert.AreEqual("同意", addedActivity.Descriptor.ToTransitions[0].Name);
            Assert.AreEqual("不同意", addedActivity.Descriptor.ToTransitions[1].Name);

            WfMainStreamActivityDescriptorCollection processDespMSA = process.Descriptor.GetMainStreamActivities();
            WfMainStreamActivityDescriptorCollection processMSA     = process.GetMainStreamActivities(true);

            processDespMSA.Output("流程描述中的主线活动");
            processMSA.Output("主线流程中的主线活动");

            Assert.AreEqual(process.Descriptor.Activities.Count, process.MainStream.Activities.Count);
            Assert.AreEqual(processDespMSA.Count, processMSA.Count);
        }
예제 #9
0
        public void BasicEditActivityExecutorTest()
        {
            IWfProcess process = WfProcessTestCommon.StartupSimpleProcess();

            IWfActivity targetActivity = process.Activities.FindActivityByDescriptorKey("NormalActivity");

            WfActivityDescriptorCreateParams createParams = new WfActivityDescriptorCreateParams();

            WfVariableDescriptor variable = new WfVariableDescriptor("CodeName", "HelloKitty");

            createParams.Variables = new WfVariableDescriptor[] { variable };

            WfEditActivityExecutor editExecutor = new WfEditActivityExecutor(process.CurrentActivity, targetActivity, createParams);

            editExecutor.Execute();

            Assert.AreEqual("HelloKitty",
                            process.Descriptor.Activities["NormalActivity"].Properties.GetValue("CodeName", string.Empty));
            Assert.AreEqual("HelloKitty",
                            process.MainStream.Activities["NormalActivity"].Properties.GetValue("CodeName", string.Empty));
        }
예제 #10
0
        public void ActivitiesTrackTest()
        {
            IWfProcess process = WfProcessTestCommon.StartupSimpleProcess();

            for (int i = 0; i < process.Activities.Count; i++)
            {
                if (process.Activities[i].Descriptor != process.Descriptor.InitialActivity)
                {
                    WfTransferParams transferPara = new WfTransferParams(process.Activities[i].Descriptor);
                    process.MoveTo(transferPara);
                }
            }

            int k = process.ElapsedActivities.Count;

            string[] keys = new string[] { "Initial", "NormalActivity", "Completed" };

            for (int j = 0; j < process.ElapsedActivities.Count; j++)
            {
                Assert.AreEqual(process.ElapsedActivities[j].Descriptor.Key, process.ElapsedActivities[j].Descriptor.Key, keys[j]);
            }
        }
예제 #11
0
        public void BasicDeleteActivityExecutorTest()
        {
            IWfProcess process = WfProcessTestCommon.StartupSimpleProcess();

            int originalActCount = process.Activities.Count;

            IWfActivity targetActivity = process.Activities.FindActivityByDescriptorKey("NormalActivity");

            WfActivityDescriptorCreateParams createParams = new WfActivityDescriptorCreateParams();

            WfAddActivityExecutor addExecutor = new WfAddActivityExecutor(process.CurrentActivity, targetActivity, createParams);

            addExecutor.Execute();

            IWfActivityDescriptor newActDesp = targetActivity.Descriptor.ToTransitions.FirstOrDefault().ToActivity;

            WfRuntime.ClearCache();

            process = WfRuntime.GetProcessByProcessID(process.ID);

            targetActivity = process.Activities.FindActivityByDescriptorKey(newActDesp.Key);
            WfDeleteActivityExecutor deleteExecutor = new WfDeleteActivityExecutor(process.CurrentActivity, targetActivity);

            deleteExecutor.Execute();

            WfMainStreamActivityDescriptorCollection processDespMSA = process.Descriptor.GetMainStreamActivities();
            WfMainStreamActivityDescriptorCollection processMSA     = process.GetMainStreamActivities(true);

            processDespMSA.Output("流程描述中的主线活动");
            processMSA.Output("主线流程中的主线活动");

            Assert.AreEqual(process.Descriptor.Activities.Count, process.MainStream.Activities.Count);
            Assert.AreEqual(processDespMSA.Count, processMSA.Count);

            Assert.IsNull(process.Activities.FindActivityByDescriptorKey(targetActivity.Descriptor.Key));
            Assert.IsNull(process.MainStream.Activities[targetActivity.MainStreamActivityKey]);
        }
예제 #12
0
        public void RestoreProcessExecutorTest()
        {
            IWfProcess process = WfProcessTestCommon.StartupSimpleProcess();

            MoveToExecutor(process);

            process = WfRuntime.GetProcessByProcessID(process.ID);

            WfExecutorBase executor = new WfCancelProcessExecutor(process.CurrentActivity, process);

            executor.Execute();

            Assert.AreEqual(WfProcessStatus.Aborted, process.Status);

            process = WfRuntime.GetProcessByProcessID(process.ID);

            executor = new WfRestoreProcessExecutor(process.CurrentActivity, process);

            executor.Execute();

            process = WfRuntime.GetProcessByProcessID(process.ID);

            Assert.AreEqual(WfProcessStatus.Running, process.Status);
        }
예제 #13
0
        public void SimpleProcessStartTest()
        {
            IWfProcess process = WfProcessTestCommon.StartupSimpleProcess();

            Assert.AreEqual(WfActivityStatus.Running, process.InitialActivity.Status);
        }