Ejemplo n.º 1
0
        public async Task When_Execute_BoundaryEvent()
        {
            var          humanTaskInstanceId = Guid.NewGuid().ToString();
            const string messageName         = "message";
            var          processInstance     = ProcessInstanceBuilder.New("processFile")
                                               .AddMessage(messageName, "message", "item")
                                               .AddMessage("humanTaskCreated", "humanTaskCreated", "item")
                                               .AddItemDef("item", ItemKinds.Information, false, typeof(PersonParameter).FullName)
                                               .AddStartEvent("1", "evt")
                                               .AddUserTask("2", "userTask", (cb) =>
            {
                cb.SetWsHumanTask("dressAppropriate");
                cb.AddBoundaryEventRef("3");
            })
                                               .AddBoundaryEvent("3", "messageReceived", _ =>
            {
                _.AddMessageEvtDef("id", cb =>
                {
                    cb.SetMessageRef(messageName);
                });
            })
                                               .AddEmptyTask("4", "emptyTask")
                                               .AddSequenceFlow("seq1", "sequence", "1", "2")
                                               .AddSequenceFlow("seq2", "sequence", "2", "3")
                                               .AddSequenceFlow("seq3", "sequence", "3", "4")
                                               .Build();
            var jobServer = FakeCaseJobServer.New();

            jobServer.HttpMessageHandler.Protected()
            .As <IHttpMessageHandler>()
            .Setup(x => x.SendAsync(It.IsAny <HttpRequestMessage>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new HttpResponseMessage
            {
                Content = new StringContent("{ 'id' : '" + humanTaskInstanceId + "', 'defId': 'defId' }")
            });

            await jobServer.RegisterProcessInstance(processInstance, CancellationToken.None);

            await jobServer.EnqueueProcessInstance(processInstance.AggregateId, true, CancellationToken.None);

            await jobServer.EnqueueMessage(processInstance.AggregateId, messageName, new PersonParameter { }, CancellationToken.None);

            var casePlanInstance = await jobServer.Get(processInstance.AggregateId, CancellationToken.None);

            var ei = casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "2");
            await jobServer.EnqueueStateTransition(casePlanInstance.AggregateId, ei.EltId, "COMPLETED", new JObject(), CancellationToken.None);

            casePlanInstance = await jobServer.Get(processInstance.AggregateId, CancellationToken.None);

            var executionPath = casePlanInstance.ExecutionPathLst.First();

            Assert.True(casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "1").State == FlowNodeStates.Complete);
            Assert.True(casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "2").State == FlowNodeStates.Complete);
            Assert.True(casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "4").State == FlowNodeStates.Complete);
            Assert.Equal(1, executionPath.Pointers.First(p => p.FlowNodeId == "1").Outgoing.Count());
            Assert.Equal(1, executionPath.Pointers.First(p => p.FlowNodeId == "2").Incoming.Count());
            Assert.Equal(1, executionPath.Pointers.First(p => p.FlowNodeId == "2").Outgoing.Count());
            Assert.Equal(2, executionPath.Pointers.First(p => p.FlowNodeId == "3").Incoming.Count());
            Assert.Equal(2, executionPath.Pointers.First(p => p.FlowNodeId == "4").Incoming.Count());
        }
        public async Task When_Execute_FileItem()
        {
            var instance = CasePlanInstanceBuilder.New("1", "firstCase")
                           .AddFileItem("2", "directory", (_) =>
            {
                _.DefinitionType = CMMNConstants.ContentManagementTypes.FAKE_CMIS_DIRECTORY;
            })
                           .AddEmptyTask("3", "emptytask", (_) =>
            {
                _.AddEntryCriteria("entry", (__) =>
                {
                    __.AddFileItemOnPart("2", CMMNTransitions.AddChild);
                });
            })
                           .Build();
            var jobServer = FakeCaseJobServer.New();
            await jobServer.RegisterCasePlanInstance(instance, CancellationToken.None);

            await jobServer.EnqueueCasePlanInstance("1", CancellationToken.None);

            await jobServer.PublishExternalEvt("addchild", "1", CaseEltInstance.BuildId("1", "2"), new Dictionary <string, string> {
                { "fileId", "file" }
            }, CancellationToken.None);

            var casePlanInstance = await jobServer.Get("1", CancellationToken.None);

            var firstFileItem  = casePlanInstance.FileItems.ElementAt(0);
            var firstEmptyTask = casePlanInstance.StageContent.Children.ElementAt(0);

            Assert.Equal(CaseStates.Completed, casePlanInstance.State);
            Assert.Equal(CaseFileItemStates.Available, firstFileItem.FileState);
            Assert.Equal(TaskStageStates.Completed, firstEmptyTask.TakeStageState);
        }
        public async Task When_Execute_ServiceTask_With_CSHARPCallback()
        {
            const string messageName     = "message";
            var          processInstance = ProcessInstanceBuilder.New("processFile")
                                           .AddMessage(messageName, "message", string.Empty)
                                           .AddStartEvent("1", "evt", _ =>
            {
                _.AddMessageEvtDef("id", cb =>
                {
                    cb.SetMessageRef(messageName);
                });
            })
                                           .AddServiceTask("2", "name", _ =>
            {
                _.SetCallback(typeof(GetWeatherInformationDelegate).FullName);
            })
                                           .AddSequenceFlow("seq1", "sequence", "1", "2")
                                           .Build();
            var jobServer = FakeCaseJobServer.New();

            try
            {
                await jobServer.RegisterProcessInstance(processInstance, CancellationToken.None);

                jobServer.Start();
                await jobServer.EnqueueProcessInstance(processInstance.AggregateId, true, CancellationToken.None);

                var casePlanInstance = await jobServer.MonitorProcessInstance(processInstance.AggregateId, (c) =>
                {
                    if (c == null)
                    {
                        return(false);
                    }

                    return(c.ElementInstances.Any());
                }, CancellationToken.None);

                await jobServer.EnqueueMessage(processInstance.AggregateId, messageName, null, CancellationToken.None);

                casePlanInstance = await jobServer.MonitorProcessInstance(processInstance.AggregateId, (c) =>
                {
                    if (c == null)
                    {
                        return(false);
                    }

                    return(c.ElementInstances.Count() == 2);
                }, CancellationToken.None);

                var startEventInstance  = casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "1");
                var serviceTaskInstance = casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "2");
                Assert.Equal(FlowNodeStates.Active, startEventInstance.State);
                Assert.Equal(ActivityStates.COMPLETED, serviceTaskInstance.ActivityState);
                Assert.Equal(FlowNodeStates.Complete, serviceTaskInstance.State);
            }
            finally
            {
                jobServer.Stop();
            }
        }
        public async Task When_Execute_ConditionalSequenceFlow()
        {
            const string messageName     = "message";
            var          processInstance = ProcessInstanceBuilder.New("processFile")
                                           .AddMessage(messageName, "message", "item")
                                           .AddItemDef("item", ItemKinds.Information, false, typeof(PersonParameter).FullName)
                                           .AddStartEvent("1", "evt", _ =>
            {
                _.AddMessageEvtDef("id", cb =>
                {
                    cb.SetMessageRef(messageName);
                });
            })
                                           .AddEmptyTask("2", "name")
                                           .AddEmptyTask("3", "name")
                                           .AddSequenceFlow("seq1", "sequence", "1", "2", "context.GetIncomingMessage(\"Firstname\") == \"user\"")
                                           .AddSequenceFlow("seq2", "sequence", "1", "3", "context.GetIncomingMessage(\"Firstname\") == \"baduser\"")
                                           .Build();
            var jobServer = FakeCaseJobServer.New();

            try
            {
                await jobServer.RegisterProcessInstance(processInstance, CancellationToken.None);

                jobServer.Start();
                await jobServer.EnqueueProcessInstance(processInstance.AggregateId, true, CancellationToken.None);

                var casePlanInstance = await jobServer.MonitorProcessInstance(processInstance.AggregateId, (c) =>
                {
                    if (c == null)
                    {
                        return(false);
                    }

                    return(c.ElementInstances.Any());
                }, CancellationToken.None);

                await jobServer.EnqueueMessage(processInstance.AggregateId, messageName, new PersonParameter { Firstname = "user" }, CancellationToken.None);

                casePlanInstance = await jobServer.MonitorProcessInstance(processInstance.AggregateId, (c) =>
                {
                    if (c == null)
                    {
                        return(false);
                    }

                    return(c.ElementInstances.Count() == 2);
                }, CancellationToken.None);

                var startEventInstance     = casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "1");
                var firstEmptyTaskInstance = casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "2");
                Assert.Equal(FlowNodeStates.Active, startEventInstance.State);
                Assert.Equal(ActivityStates.COMPLETED, firstEmptyTaskInstance.ActivityState);
                Assert.Equal(FlowNodeStates.Complete, firstEmptyTaskInstance.State);
            }
            finally
            {
                jobServer.Stop();
            }
        }
Ejemplo n.º 5
0
        public async Task When_Terminate_CasePlanInstance()
        {
            var instance = CasePlanInstanceBuilder.New("1", "firstCase")
                           .AddHumanTask("2", "humanTask", null, (_) => { })
                           .Build();
            var jobServer = FakeCaseJobServer.New();

            try
            {
                await jobServer.RegisterCasePlanInstance(instance, CancellationToken.None);

                jobServer.Start();
                await jobServer.EnqueueCasePlanInstance("1", CancellationToken.None);

                await jobServer.PublishExternalEvt("terminate", "1", null, new Dictionary <string, string>(), CancellationToken.None);

                var casePlanInstance = await jobServer.MonitorCasePlanInstance("1", (c) =>
                {
                    if (c == null)
                    {
                        return(false);
                    }

                    return(c.State == CaseStates.Terminated);
                }, CancellationToken.None);

                var firstHumanTask = casePlanInstance.StageContent.Children.First() as HumanTaskElementInstance;
                Assert.Equal(CaseStates.Terminated, casePlanInstance.State);
                Assert.Equal(TaskStageStates.Terminated, firstHumanTask.State);
            }
            finally
            {
                jobServer.Stop();
            }
        }
Ejemplo n.º 6
0
        public async Task When_Execute_Task_With_RepetitionRule()
        {
            var instance = CasePlanInstanceBuilder.New("1", "firstCase")
                           .AddEmptyTask("2", "firstTask", (_) =>
            {
                _.SetRepetitionRule("name", new CMMNExpression("csharp", "context.GetVariableAndIncrement(\"counter\") < 2"));
            })
                           .Build();
            var jobServer = FakeCaseJobServer.New();

            try
            {
                await jobServer.RegisterCasePlanInstance(instance, CancellationToken.None);

                jobServer.Start();
                await jobServer.EnqueueCasePlanInstance("1", CancellationToken.None);

                var casePlanInstance = await jobServer.MonitorCasePlanInstance("1", (c) =>
                {
                    if (c == null)
                    {
                        return(false);
                    }

                    return(c.StageContent.Children.Count() == 2);
                }, CancellationToken.None);

                Assert.Equal(2, casePlanInstance.StageContent.Children.Count());
            }
            finally
            {
                jobServer.Stop();
            }
        }
        public async Task When_Execute_Stage()
        {
            var instance = CasePlanInstanceBuilder.New("1", "firstCase")
                           .AddStage("2", "firstStage", (_) =>
            {
                _.AddStage("3", "secondStage", (__) =>
                {
                    __.AddEmptyTask("4", "emtpytask");
                });
            })
                           .AddStage("5", "thirdStage", (_) =>
            {
                _.AddEmptyTask("6", "emtpytask");
            })
                           .Build();
            var jobServer = FakeCaseJobServer.New();
            await jobServer.RegisterCasePlanInstance(instance, CancellationToken.None);

            await jobServer.EnqueueCasePlanInstance("1", CancellationToken.None);

            var casePlanInstance = await jobServer.Get("1", CancellationToken.None);

            var firstStage  = casePlanInstance.StageContent.Children.ElementAt(0);
            var secondStage = casePlanInstance.StageContent.Children.ElementAt(1);

            Assert.Equal(CaseStates.Completed, casePlanInstance.State);
            Assert.Equal(TaskStageStates.Completed, firstStage.TakeStageState);
            Assert.Equal(TaskStageStates.Completed, secondStage.TakeStageState);
        }
        public async Task When_Execute_Human_Task()
        {
            var humanTaskInstanceId = Guid.NewGuid().ToString();
            var instance            = CasePlanInstanceBuilder.New("1", "firstCase")
                                      .AddHumanTask("2", "humanTask", null, (_) =>
            {
            })
                                      .Build();
            var jobServer = FakeCaseJobServer.New();

            jobServer.HttpMessageHandler.Protected()
            .As <IHttpMessageHandler>()
            .Setup(x => x.SendAsync(It.IsAny <HttpRequestMessage>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new HttpResponseMessage
            {
                Content = new StringContent("{ 'id' : '{" + humanTaskInstanceId + "}' }")
            });
            await jobServer.RegisterCasePlanInstance(instance, CancellationToken.None);

            await jobServer.EnqueueCasePlanInstance("1", CancellationToken.None);

            await jobServer.PublishExternalEvt("complete", "1", CaseEltInstance.BuildId("1", "2", 0), new Dictionary <string, string> {
                { "firstname", "firstname" }
            }, CancellationToken.None);

            var casePlanInstance = await jobServer.Get("1", CancellationToken.None);

            var firstHumanTask = casePlanInstance.StageContent.Children.ElementAt(0);

            Assert.Equal(CaseStates.Completed, casePlanInstance.State);
            Assert.Equal(TaskStageStates.Completed, firstHumanTask.TakeStageState);
        }
        public async Task When_Execute_Empty_Tasks()
        {
            var instance = CasePlanInstanceBuilder.New("1", "firstCase")
                           .AddEmptyTask("2", "firstTask", (_) =>
            {
            })
                           .AddEmptyTask("3", "secondTask", (_) =>
            {
            })
                           .AddEmptyTask("4", "thirdTask", (_) =>
            {
                _.AddEntryCriteria("entry", (__) =>
                {
                    __.AddPlanItemOnPart("2", CMMNTransitions.Complete);
                    __.AddPlanItemOnPart("3", CMMNTransitions.Complete);
                });
            })
                           .Build();
            var jobServer = FakeCaseJobServer.New();
            await jobServer.RegisterCasePlanInstance(instance, CancellationToken.None);

            await jobServer.EnqueueCasePlanInstance("1", CancellationToken.None);

            var casePlanInstance = await jobServer.Get("1", CancellationToken.None);

            var firstEmptyTask  = casePlanInstance.StageContent.Children.ElementAt(0);
            var secondEmptyTask = casePlanInstance.StageContent.Children.ElementAt(1);
            var thirdEmptyTask  = casePlanInstance.StageContent.Children.ElementAt(2);

            Assert.Equal(CaseStates.Completed, casePlanInstance.State);
            Assert.Equal(TaskStageStates.Completed, firstEmptyTask.TakeStageState);
            Assert.Equal(TaskStageStates.Completed, secondEmptyTask.TakeStageState);
            Assert.Equal(TaskStageStates.Completed, thirdEmptyTask.TakeStageState);
        }
Ejemplo n.º 10
0
        public async Task When_Execute_HumanTaskWithBoundaryEvent()
        {
            var          humanTaskInstanceId = Guid.NewGuid().ToString();
            const string messageName         = "humanTaskCreated";
            var          processInstance     = ProcessInstanceBuilder.New("processFile")
                                               .AddMessage(messageName, "humanTaskCreated", "item")
                                               .AddItemDef("item", ItemKinds.Information, false, typeof(HumanTaskParameter).FullName)
                                               .AddStartEvent("1", "evt")
                                               .AddUserTask("2", "userTask", (cb) =>
            {
                cb.SetWsHumanTask("dressAppropriate");
                cb.AddBoundaryEventRef("3");
            })
                                               .AddBoundaryEvent("3", "humanTaskCreated", _ =>
            {
                _.AddMessageEvtDef("id", cb =>
                {
                    cb.SetMessageRef(messageName);
                });
            })
                                               .AddEmptyTask("4", "firstEmptyTask")
                                               .AddEmptyTask("5", "secondEmptyTask")
                                               .AddSequenceFlow("seq1", "sequence", "1", "2")
                                               .AddSequenceFlow("seq2", "sequence", "2", "3")
                                               .AddSequenceFlow("seq3", "sequence", "3", "4")
                                               .AddSequenceFlow("seq4", "sequence", "2", "5")
                                               .Build();
            var jobServer = FakeCaseJobServer.New();

            jobServer.Start();
            jobServer.HttpMessageHandler.Protected()
            .As <IHttpMessageHandler>()
            .Setup(x => x.SendAsync(It.IsAny <HttpRequestMessage>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new HttpResponseMessage
            {
                Content = new StringContent("{ 'id' : '" + humanTaskInstanceId + "', 'defId': 'defId' }")
            });
            await jobServer.RegisterProcessInstance(processInstance, CancellationToken.None);

            await jobServer.EnqueueProcessInstance(processInstance.AggregateId, true, CancellationToken.None);

            var result = await jobServer.MonitoringProcessInstance(processInstance.AggregateId, (p) =>
            {
                var elt = p.ElementInstances.FirstOrDefault(_ => _.FlowNodeId == "4");
                return(elt != null && elt.State == FlowNodeStates.Complete);
            }, CancellationToken.None);

            var ei = result.ElementInstances.First(_ => _.FlowNodeId == "2");
            await jobServer.EnqueueStateTransition(result.AggregateId, ei.EltId, "COMPLETED", new JObject(), CancellationToken.None);

            result = await jobServer.Get(processInstance.AggregateId, CancellationToken.None);

            Assert.True(result.ElementInstances.First(_ => _.FlowNodeId == "1").State == FlowNodeStates.Complete);
            Assert.True(result.ElementInstances.First(_ => _.FlowNodeId == "2").State == FlowNodeStates.Complete);
            Assert.True(result.ElementInstances.First(_ => _.FlowNodeId == "4").State == FlowNodeStates.Complete);
            jobServer.Stop();
        }
Ejemplo n.º 11
0
        public async Task When_Execute_Timer()
        {
            var instance = CasePlanInstanceBuilder.New("1", "firstCase")
                           .AddTimerEventListener("2", "timer", (_) =>
            {
                _.TimerExpression = new CMMNExpression("csharp", "R2/P0Y0M0DT0H0M4S");
            })
                           .AddEmptyTask("3", "emptytask", (_) =>
            {
                _.SetRepetitionRule("name", new CMMNExpression("csharp", "context.GetVariableAndIncrement(\"counter\") < 1"));
                _.AddEntryCriteria("entry", (__) =>
                {
                    __.AddPlanItemOnPart("2", CMMNTransitions.Occur);
                });
            })
                           .Build();
            var jobServer = FakeCaseJobServer.New();

            try
            {
                await jobServer.RegisterCasePlanInstance(instance, CancellationToken.None);

                jobServer.Start();
                await jobServer.EnqueueCasePlanInstance("1", CancellationToken.None);

                var casePlanInstance = await jobServer.MonitorCasePlanInstance("1", (c) =>
                {
                    if (c == null)
                    {
                        return(false);
                    }

                    if (c.StageContent.Children.Count() == 4)
                    {
                        var firstTimer  = c.StageContent.Children.ElementAt(0) as TimerEventListener;
                        var secondTimer = c.StageContent.Children.ElementAt(2) as TimerEventListener;
                        return(firstTimer.State == MilestoneEventStates.Completed && secondTimer.State == MilestoneEventStates.Completed);
                    }

                    return(false);
                }, CancellationToken.None);

                var firstTimerEventListener  = casePlanInstance.StageContent.Children.ElementAt(0) as TimerEventListener;
                var firstEmptyTask           = casePlanInstance.StageContent.Children.ElementAt(1) as EmptyTaskElementInstance;
                var secondTimerEventListener = casePlanInstance.StageContent.Children.ElementAt(2) as TimerEventListener;
                var secondEmptyTask          = casePlanInstance.StageContent.Children.ElementAt(3) as EmptyTaskElementInstance;
                Assert.Equal(MilestoneEventStates.Completed, firstTimerEventListener.State);
                Assert.Equal(TaskStageStates.Completed, firstEmptyTask.State);
                Assert.Equal(MilestoneEventStates.Completed, secondTimerEventListener.State);
                Assert.Equal(TaskStageStates.Completed, secondEmptyTask.State);
            }
            finally
            {
                jobServer.Stop();
            }
        }
Ejemplo n.º 12
0
        public async Task When_Execute_ParallelGateway()
        {
            const string messageName     = "message";
            var          processInstance = ProcessInstanceBuilder.New("processFile")
                                           .AddMessage(messageName, "message", "item")
                                           .AddItemDef("item", ItemKinds.Information, false, typeof(PersonParameter).FullName)
                                           .AddStartEvent("1", "evt", _ =>
            {
                _.AddMessageEvtDef("id", cb =>
                {
                    cb.SetMessageRef(messageName);
                });
            })
                                           .AddParallelGateway("2", "gateway", GatewayDirections.DIVERGING)
                                           .AddEmptyTask("3", "name")
                                           .AddEmptyTask("4", "name")
                                           .AddParallelGateway("5", "gateway", GatewayDirections.CONVERGING)
                                           .AddEmptyTask("6", "name")
                                           .AddSequenceFlow("seq1", "sequence", "1", "2")
                                           .AddSequenceFlow("seq2", "sequence", "2", "3")
                                           .AddSequenceFlow("seq3", "sequence", "2", "4")
                                           .AddSequenceFlow("seq4", "sequence", "3", "5")
                                           .AddSequenceFlow("seq5", "sequence", "4", "5")
                                           .AddSequenceFlow("seq6", "sequence", "5", "6")
                                           .Build();
            var jobServer = FakeCaseJobServer.New();
            await jobServer.RegisterProcessInstance(processInstance, CancellationToken.None);

            await jobServer.EnqueueProcessInstance(processInstance.AggregateId, true, CancellationToken.None);

            var casePlanInstance = await jobServer.Get(processInstance.AggregateId, CancellationToken.None);

            await jobServer.EnqueueMessage(processInstance.AggregateId, messageName, new PersonParameter { Firstname = "user" }, CancellationToken.None);

            casePlanInstance = await jobServer.Get(processInstance.AggregateId, CancellationToken.None);

            var startEventInstance               = casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "1");
            var firstParallelGateway             = casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "2");
            var firstEmptyTaskInstance           = casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "3");
            var secondEmptyTaskInstance          = casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "4");
            var secondParallelGateway            = casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "5");
            var thirdEmptyTaskInstance           = casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "6");
            var secondParallelGatewayExecPointer = casePlanInstance.ExecutionPathLst.First().Pointers.First(_ => _.FlowNodeId == "5");
            var thirdEmptyTaskExecPointer        = casePlanInstance.ExecutionPathLst.First().Pointers.First(_ => _.FlowNodeId == "6");

            Assert.Equal(FlowNodeStates.Active, startEventInstance.State);
            Assert.Equal(FlowNodeStates.Complete, firstParallelGateway.State);
            Assert.Equal(FlowNodeStates.Complete, firstEmptyTaskInstance.State);
            Assert.Equal(FlowNodeStates.Complete, secondEmptyTaskInstance.State);
            Assert.Equal(FlowNodeStates.Complete, secondParallelGateway.State);
            Assert.Equal(FlowNodeStates.Complete, thirdEmptyTaskInstance.State);
            Assert.Equal(2, secondParallelGatewayExecPointer.Incoming.Count());
            Assert.Equal(2, thirdEmptyTaskExecPointer.Incoming.Count());
        }
Ejemplo n.º 13
0
        public async Task When_Execute_Task_With_ManualActivationRule()
        {
            var instance = CasePlanInstanceBuilder.New("1", "firstCase")
                           .AddEmptyTask("2", "firstTask", (_) =>
            {
                _.SetManualActivationRule("name", new CMMNExpression("csharp", "true"));
            })
                           .AddEmptyTask("3", "secondTask", (_) =>
            {
            })
                           .AddEmptyTask("4", "thirdTask", (_) =>
            {
                _.AddEntryCriteria("entry", (__) =>
                {
                    __.AddPlanItemOnPart("2", CMMNTransitions.Complete);
                    __.AddPlanItemOnPart("3", CMMNTransitions.Complete);
                });
            })
                           .Build();
            var jobServer = FakeCaseJobServer.New();

            try
            {
                await jobServer.RegisterCasePlanInstance(instance, CancellationToken.None);

                jobServer.Start();
                await jobServer.EnqueueCasePlanInstance("1", CancellationToken.None);

                await jobServer.PublishExternalEvt("manualstart", "1", EmptyTaskElementInstance.BuildId("1", "2", 0), new Dictionary <string, string>(), CancellationToken.None);

                var casePlanInstance = await jobServer.MonitorCasePlanInstance("1", (c) =>
                {
                    if (c == null)
                    {
                        return(false);
                    }

                    return(c.State == CaseStates.Completed);
                }, CancellationToken.None);

                var firstEmptyTask  = casePlanInstance.StageContent.Children.ElementAt(0) as EmptyTaskElementInstance;
                var secondEmptyTask = casePlanInstance.StageContent.Children.ElementAt(0) as EmptyTaskElementInstance;
                var thirdEmptyTask  = casePlanInstance.StageContent.Children.ElementAt(0) as EmptyTaskElementInstance;
                Assert.Equal(CaseStates.Completed, casePlanInstance.State);
                Assert.Equal(TaskStageStates.Completed, firstEmptyTask.State);
                Assert.Equal(TaskStageStates.Completed, secondEmptyTask.State);
                Assert.Equal(TaskStageStates.Completed, thirdEmptyTask.State);
            }
            finally
            {
                jobServer.Stop();
            }
        }
Ejemplo n.º 14
0
        public async Task When_Execute_Empty_Tasks()
        {
            var instance = CasePlanInstanceBuilder.New("1", "firstCase")
                           .AddEmptyTask("2", "firstTask", (_) =>
            {
            })
                           .AddEmptyTask("3", "secondTask", (_) =>
            {
            })
                           .AddEmptyTask("4", "thirdTask", (_) =>
            {
                _.AddEntryCriteria("entry", (__) =>
                {
                    __.AddPlanItemOnPart("2", CMMNTransitions.Complete);
                    __.AddPlanItemOnPart("3", CMMNTransitions.Complete);
                });
            })
                           .Build();
            var jobServer = FakeCaseJobServer.New();

            try
            {
                await jobServer.RegisterCasePlanInstance(instance, CancellationToken.None);

                jobServer.Start();
                await jobServer.EnqueueCasePlanInstance("1", CancellationToken.None);

                var casePlanInstance = await jobServer.MonitorCasePlanInstance("1", (c) =>
                {
                    if (c == null)
                    {
                        return(false);
                    }
                    return(c.State == CaseStates.Completed);
                }, CancellationToken.None);

                var firstEmptyTask  = casePlanInstance.StageContent.Children.ElementAt(0) as EmptyTaskElementInstance;
                var secondEmptyTask = casePlanInstance.StageContent.Children.ElementAt(1) as EmptyTaskElementInstance;
                var thirdEmptyTask  = casePlanInstance.StageContent.Children.ElementAt(2) as EmptyTaskElementInstance;
                Assert.Equal(CaseStates.Completed, casePlanInstance.State);
                Assert.Equal(TaskStageStates.Completed, firstEmptyTask.State);
                Assert.Equal(TaskStageStates.Completed, secondEmptyTask.State);
                Assert.Equal(TaskStageStates.Completed, thirdEmptyTask.State);
            }
            finally
            {
                jobServer.Stop();
            }
        }
Ejemplo n.º 15
0
        public async Task When_Execute_FileItem()
        {
            var instance = CasePlanInstanceBuilder.New("1", "firstCase")
                           .AddFileItem("2", "directory", (_) =>
            {
                _.DefinitionType = CMMNConstants.ContentManagementTypes.FAKE_CMIS_DIRECTORY;
            })
                           .AddEmptyTask("3", "emptytask", (_) =>
            {
                _.AddEntryCriteria("entry", (__) =>
                {
                    __.AddFileItemOnPart("2", CMMNTransitions.AddChild);
                });
            })
                           .Build();
            var jobServer = FakeCaseJobServer.New();

            try
            {
                await jobServer.RegisterCasePlanInstance(instance, CancellationToken.None);

                jobServer.Start();
                await jobServer.EnqueueCasePlanInstance("1", CancellationToken.None);

                await jobServer.PublishExternalEvt("addchild", "1", CaseFileItemInstance.BuildId("1", "2"), CancellationToken.None);

                var casePlanInstance = await jobServer.MonitorCasePlanInstance("1", (c) =>
                {
                    if (c == null)
                    {
                        return(false);
                    }

                    return(c.State == CaseStates.Completed);
                }, CancellationToken.None);

                var firstFileItem  = casePlanInstance.FileItems.ElementAt(0) as CaseFileItemInstance;
                var firstEmptyTask = casePlanInstance.StageContent.Children.ElementAt(0) as EmptyTaskElementInstance;
                Assert.Equal(CaseStates.Completed, casePlanInstance.State);
                Assert.Equal(CaseFileItemStates.Available, firstFileItem.State);
                Assert.Equal(TaskStageStates.Completed, firstEmptyTask.State);
            }
            finally
            {
                jobServer.Stop();
            }
        }
Ejemplo n.º 16
0
        public async Task When_Execute_Stage()
        {
            var instance = CasePlanInstanceBuilder.New("1", "firstCase")
                           .AddStage("2", "firstStage", (_) =>
            {
                _.AddStage("3", "secondStage", (__) =>
                {
                    __.AddEmptyTask("4", "emtpytask");
                });
            })
                           .AddStage("5", "thirdStage", (_) =>
            {
                _.AddEmptyTask("6", "emtpytask");
            })
                           .Build();
            var jobServer = FakeCaseJobServer.New();

            try
            {
                await jobServer.RegisterCasePlanInstance(instance, CancellationToken.None);

                jobServer.Start();
                await jobServer.EnqueueCasePlanInstance("1", CancellationToken.None);

                var casePlanInstance = await jobServer.MonitorCasePlanInstance("1", (c) =>
                {
                    if (c == null)
                    {
                        return(false);
                    }

                    return(c.State == CaseStates.Completed);
                }, CancellationToken.None);

                var firstStage  = casePlanInstance.StageContent.Children.ElementAt(0) as StageElementInstance;
                var secondStage = casePlanInstance.StageContent.Children.ElementAt(1) as StageElementInstance;
                Assert.Equal(CaseStates.Completed, casePlanInstance.State);
                Assert.Equal(TaskStageStates.Completed, firstStage.State);
                Assert.Equal(TaskStageStates.Completed, secondStage.State);
            }
            finally
            {
                jobServer.Stop();
            }
        }
Ejemplo n.º 17
0
        public async Task When_Terminate_CasePlanElementInstance()
        {
            var humanTaskInstanceId = Guid.NewGuid().ToString();
            var instance            = CasePlanInstanceBuilder.New("1", "firstCase")
                                      .AddHumanTask("2", "humanTask", null, (_) => { })
                                      .Build();
            var jobServer = FakeCaseJobServer.New();

            try
            {
                jobServer.HttpMessageHandler.Protected()
                .As <IHttpMessageHandler>()
                .Setup(x => x.SendAsync(It.IsAny <HttpRequestMessage>(), It.IsAny <CancellationToken>()))
                .ReturnsAsync(new HttpResponseMessage
                {
                    Content = new StringContent("{ 'id' : '{" + humanTaskInstanceId + "}' }")
                });
                await jobServer.RegisterCasePlanInstance(instance, CancellationToken.None);

                jobServer.Start();
                await jobServer.EnqueueCasePlanInstance("1", CancellationToken.None);

                await jobServer.PublishExternalEvt("terminate", "1", HumanTaskElementInstance.BuildId("1", "2", 0), new Dictionary <string, string>(), CancellationToken.None);

                var casePlanInstance = await jobServer.MonitorCasePlanInstance("1", (c) =>
                {
                    if (c == null || !c.StageContent.Children.Any())
                    {
                        return(false);
                    }

                    var ht = c.StageContent.Children.First() as HumanTaskElementInstance;
                    return(ht.State == TaskStageStates.Terminated);
                }, CancellationToken.None);

                var firstHumanTask = casePlanInstance.StageContent.Children.First() as HumanTaskElementInstance;
                Assert.Equal(CaseStates.Completed, casePlanInstance.State);
                Assert.Equal(TaskStageStates.Terminated, firstHumanTask.State);
            }
            finally
            {
                jobServer.Stop();
            }
        }
        public async Task When_Terminate_CasePlanInstance()
        {
            var instance = CasePlanInstanceBuilder.New("1", "firstCase")
                           .AddHumanTask("2", "humanTask", null, (_) => { })
                           .Build();
            var jobServer = FakeCaseJobServer.New();
            await jobServer.RegisterCasePlanInstance(instance, CancellationToken.None);

            await jobServer.EnqueueCasePlanInstance("1", CancellationToken.None);

            await jobServer.PublishExternalEvt("terminate", "1", null, new Dictionary <string, string>(), CancellationToken.None);

            var casePlanInstance = await jobServer.Get("1", CancellationToken.None);

            var firstHumanTask = casePlanInstance.StageContent.Children.First();

            Assert.Equal(CaseStates.Terminated, casePlanInstance.State);
            Assert.Equal(TaskStageStates.Terminated, firstHumanTask.TakeStageState);
        }
Ejemplo n.º 19
0
        public async Task When_Execute_UserTask()
        {
            var humanTaskInstanceId = Guid.NewGuid().ToString();
            var processInstance     = ProcessInstanceBuilder.New("processFile")
                                      .AddStartEvent("1", "evt")
                                      .AddServiceTask("2", "serviceTask", (cb) =>
            {
                cb.SetDelegate("GetWeatherInformationDelegate");
            })
                                      .AddUserTask("3", "userTask", (cb) =>
            {
                cb.SetWsHumanTask("dressAppropriate", new Dictionary <string, string>
                {
                    { "degree", "context.GetIncomingMessage(\"weatherInformation\", \"degree\")" },
                    { "city", "context.GetIncomingMessage(\"weatherInformation\", \"city\")" }
                });
            })
                                      .AddSequenceFlow("seq1", "sequence", "1", "2")
                                      .AddSequenceFlow("seq2", "sequence", "2", "3")
                                      .Build();
            var jobServer = FakeCaseJobServer.New();

            jobServer.HttpMessageHandler.Protected()
            .As <IHttpMessageHandler>()
            .Setup(x => x.SendAsync(It.IsAny <HttpRequestMessage>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new HttpResponseMessage
            {
                Content = new StringContent("{ 'id' : '" + humanTaskInstanceId + "', 'defId': 'defId' }")
            });
            await jobServer.RegisterProcessInstance(processInstance, CancellationToken.None);

            await jobServer.EnqueueProcessInstance(processInstance.AggregateId, true, CancellationToken.None);

            var casePlanInstance = await jobServer.Get(processInstance.AggregateId, CancellationToken.None);

            var ei = casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "3");
            await jobServer.EnqueueStateTransition(casePlanInstance.AggregateId, ei.EltId, "COMPLETED", new JObject(), CancellationToken.None);

            casePlanInstance = await jobServer.Get(processInstance.AggregateId, CancellationToken.None);

            Assert.True(casePlanInstance.ElementInstances.All(_ => _.State == FlowNodeStates.Complete));
        }
Ejemplo n.º 20
0
        public async Task When_Execute_InclusiveGateway()
        {
            const string messageName     = "message";
            var          processInstance = ProcessInstanceBuilder.New("1")
                                           .AddMessage(messageName, "message", "item")
                                           .AddItemDef("item", ItemKinds.Information, false, typeof(PersonParameter).FullName)
                                           .AddStartEvent("1", "evt", _ =>
            {
                _.AddMessageEvtDef("id", cb =>
                {
                    cb.SetMessageRef(messageName);
                });
            })
                                           .AddInclusiveGateway("2", "gateway", GatewayDirections.DIVERGING, "5")
                                           .AddEmptyTask("3", "name")
                                           .AddEmptyTask("4", "name")
                                           .AddEmptyTask("5", "name")
                                           .AddSequenceFlow("seq1", "sequence", "1", "2")
                                           .AddSequenceFlow("seq2", "sequence", "2", "3", "context.GetIncomingMessage(\"Firstname\") == \"user1\"")
                                           .AddSequenceFlow("seq3", "sequence", "2", "4", "context.GetIncomingMessage(\"Firstname\") == \"user2\"")
                                           .AddSequenceFlow("seq4", "sequence", "2", "5")
                                           .Build();
            var jobServer = FakeCaseJobServer.New();
            await jobServer.RegisterProcessInstance(processInstance, CancellationToken.None);

            await jobServer.EnqueueProcessInstance(processInstance.AggregateId, true, CancellationToken.None);

            var casePlanInstance = await jobServer.Get(processInstance.AggregateId, CancellationToken.None);

            await jobServer.EnqueueMessage(processInstance.AggregateId, messageName, new PersonParameter { }, CancellationToken.None);

            casePlanInstance = await jobServer.Get(processInstance.AggregateId, CancellationToken.None);

            var startEventInstance       = casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "1");
            var inclusiveGatewayInstance = casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "2");
            var firstEmptyTaskInstance   = casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "5");

            Assert.Equal(FlowNodeStates.Active, startEventInstance.State);
            Assert.Equal(FlowNodeStates.Complete, inclusiveGatewayInstance.State);
            Assert.Equal(FlowNodeStates.Complete, firstEmptyTaskInstance.State);
        }
Ejemplo n.º 21
0
        public async Task When_Execute_StartEvent_With_MessageEventDefinition()
        {
            const string messageName     = "message";
            var          processInstance = ProcessInstanceBuilder.New("processFile")
                                           .AddMessage(messageName, "message", string.Empty)
                                           .AddStartEvent("1", "evt", _ =>
            {
                _.AddMessageEvtDef("id", cb =>
                {
                    cb.SetMessageRef("message");
                });
            })
                                           .AddEmptyTask("2", "name", _ =>
            {
                _.SetStartQuantity(2);
            })
                                           .AddSequenceFlow("seq1", "sequence", "1", "2")
                                           .Build();
            var jobServer = FakeCaseJobServer.New();
            await jobServer.RegisterProcessInstance(processInstance, CancellationToken.None);

            await jobServer.EnqueueProcessInstance(processInstance.AggregateId, true, CancellationToken.None);

            var casePlanInstance = await jobServer.Get(processInstance.AggregateId, CancellationToken.None);

            await jobServer.EnqueueMessage(processInstance.AggregateId, messageName, null, CancellationToken.None);

            await jobServer.EnqueueMessage(processInstance.AggregateId, messageName, null, CancellationToken.None);

            casePlanInstance = await jobServer.Get(processInstance.AggregateId, CancellationToken.None);

            var startEventInstance = casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "1");
            var emptyTaskInstance  = casePlanInstance.ElementInstances.First(_ => _.FlowNodeId == "2");

            Assert.Equal(FlowNodeStates.Active, startEventInstance.State);
            Assert.Equal(ActivityStates.COMPLETED, emptyTaskInstance.ActivityState);
            Assert.Equal(FlowNodeStates.Complete, emptyTaskInstance.State);
            Assert.Equal(1, casePlanInstance.ExecutionPathLst.Count());
            Assert.Equal(1, casePlanInstance.ExecutionPathLst.First().ActivePointers.Count());
            Assert.Equal(4, casePlanInstance.ExecutionPathLst.First().Pointers.Count());
        }
        public async Task When_Execute_Sequence_Of_Empty_Tasks()
        {
            var processInstance = ProcessInstanceBuilder.New("processFile")
                                  .AddStartEvent("1", "evt")
                                  .AddEmptyTask("2", "name")
                                  .AddEmptyTask("3", "name")
                                  .AddEmptyTask("4", "name")
                                  .AddSequenceFlow("seq1", "sequence", "1", "2")
                                  .AddSequenceFlow("seq2", "sequence", "1", "3")
                                  .AddSequenceFlow("seq3", "sequence", "2", "4")
                                  .AddSequenceFlow("seq3", "sequence", "3", "4")
                                  .Build();
            var jobServer = FakeCaseJobServer.New();

            try
            {
                await jobServer.RegisterProcessInstance(processInstance, CancellationToken.None);

                jobServer.Start();
                await jobServer.EnqueueProcessInstance(processInstance.AggregateId, true, CancellationToken.None);

                await jobServer.EnqueueProcessInstance(processInstance.AggregateId, true, CancellationToken.None);

                var casePlanInstance = await jobServer.MonitorProcessInstance(processInstance.AggregateId, (c) =>
                {
                    if (c == null)
                    {
                        return(false);
                    }

                    return(c.ElementInstances.Count() == 10);
                }, CancellationToken.None);

                Assert.Equal(10, casePlanInstance.ElementInstances.Count());
            }
            finally
            {
                jobServer.Stop();
            }
        }
        public async Task When_Execute_IfPart()
        {
            var instance = CasePlanInstanceBuilder.New("1", "firstCase")
                           .AddEmptyTask("2", "emptyTask", (_) => { })
                           .AddEmptyTask("3", "secondTask", (_) =>
            {
                _.AddEntryCriteria("entry", __ =>
                {
                    __.SetIfPart("context.GetStrVariable(\"action\") == \"secondTask\"");
                    __.AddPlanItemOnPart("2", CMMNTransitions.Complete);
                });
            })
                           .AddEmptyTask("4", "thirdTask", (_) =>
            {
                _.AddEntryCriteria("entry", __ =>
                {
                    __.SetIfPart("context.GetStrVariable(\"action\") == \"thirdTask\"");
                    __.AddPlanItemOnPart("2", CMMNTransitions.Complete);
                });
            })
                           .Build();

            instance.ExecutionContext.SetStrVariable("action", "thirdTask");
            var jobServer = FakeCaseJobServer.New();
            await jobServer.RegisterCasePlanInstance(instance, CancellationToken.None);

            await jobServer.EnqueueCasePlanInstance("1", CancellationToken.None);

            var casePlanInstance = await jobServer.Get("1", CancellationToken.None);

            var firstEmptyTask  = casePlanInstance.StageContent.Children.ElementAt(0);
            var secondEmptyTask = casePlanInstance.StageContent.Children.ElementAt(1);
            var thirdEmptyTask  = casePlanInstance.StageContent.Children.ElementAt(2);

            Assert.Equal(TaskStageStates.Completed, firstEmptyTask.TakeStageState);
            Assert.Equal(TaskStageStates.Completed, thirdEmptyTask.TakeStageState);
            Assert.Null(secondEmptyTask.TakeStageState);
        }
Ejemplo n.º 24
0
        public async Task When_Execute_Sequence_Of_Empty_Tasks()
        {
            var processInstance = ProcessInstanceBuilder.New("processFile")
                                  .AddStartEvent("1", "evt")
                                  .AddEmptyTask("2", "name")
                                  .AddEmptyTask("3", "name")
                                  .AddEmptyTask("4", "name")
                                  .AddSequenceFlow("seq1", "sequence", "1", "2")
                                  .AddSequenceFlow("seq2", "sequence", "1", "3")
                                  .AddSequenceFlow("seq3", "sequence", "2", "4")
                                  .AddSequenceFlow("seq3", "sequence", "3", "4")
                                  .Build();
            var jobServer = FakeCaseJobServer.New();
            await jobServer.RegisterProcessInstance(processInstance, CancellationToken.None);

            await jobServer.EnqueueProcessInstance(processInstance.AggregateId, true, CancellationToken.None);

            await jobServer.EnqueueProcessInstance(processInstance.AggregateId, true, CancellationToken.None);

            var casePlanInstance = await jobServer.Get(processInstance.AggregateId, CancellationToken.None);

            Assert.Equal(10, casePlanInstance.ElementInstances.Count());
        }
Ejemplo n.º 25
0
        public async Task When_Execute_IfPart()
        {
            var instance = CasePlanInstanceBuilder.New("1", "firstCase")
                           .AddEmptyTask("2", "emptyTask", (_) => { })
                           .AddEmptyTask("3", "secondTask", (_) =>
            {
                _.AddEntryCriteria("entry", __ =>
                {
                    __.SetIfPart("context.GetStrVariable(\"action\") == \"secondTask\"");
                    __.AddPlanItemOnPart("2", CMMNTransitions.Complete);
                });
            })
                           .AddEmptyTask("4", "thirdTask", (_) =>
            {
                _.AddEntryCriteria("entry", __ =>
                {
                    __.SetIfPart("context.GetStrVariable(\"action\") == \"thirdTask\"");
                    __.AddPlanItemOnPart("2", CMMNTransitions.Complete);
                });
            })
                           .Build();

            instance.ExecutionContext.SetStrVariable("action", "thirdTask");
            var jobServer = FakeCaseJobServer.New();

            try
            {
                await jobServer.RegisterCasePlanInstance(instance, CancellationToken.None);

                jobServer.Start();
                await jobServer.EnqueueCasePlanInstance("1", CancellationToken.None);

                var casePlanInstance = await jobServer.MonitorCasePlanInstance("1", (c) =>
                {
                    if (c == null)
                    {
                        return(false);
                    }

                    if (c.StageContent.Children.Count() == 3)
                    {
                        var th = c.StageContent.Children.ElementAt(2) as EmptyTaskElementInstance;
                        if (th.State == TaskStageStates.Completed)
                        {
                            return(true);
                        }
                    }

                    return(false);
                }, CancellationToken.None);

                var firstEmptyTask  = casePlanInstance.StageContent.Children.ElementAt(0) as EmptyTaskElementInstance;
                var secondEmptyTask = casePlanInstance.StageContent.Children.ElementAt(1) as EmptyTaskElementInstance;
                var thirdEmptyTask  = casePlanInstance.StageContent.Children.ElementAt(2) as EmptyTaskElementInstance;
                Assert.Equal(TaskStageStates.Completed, firstEmptyTask.State);
                Assert.Equal(TaskStageStates.Completed, thirdEmptyTask.State);
                Assert.Null(secondEmptyTask.State);
            }
            finally
            {
                jobServer.Stop();
            }
        }