Esempio n. 1
0
        public void BeRunningAfterHandlingValidStartEvent()
        {
            var model = ProcessModel.Create()
                        .AddEventCatcher(
                "start",
                CatchAnyEventCatcher.Create()
                )
                        .AddEventCatcher(
                "middle",
                CatchAnyEventCatcher.Create()
                )
                        .AddEventThrower(
                "end",
                SilentEventThrower.Instance
                )
                        .AddSequenceFlow("start", "middle", "end");

            var instance = ProcessInstance.Create(Guid.Parse(model.Id));
            var context  = new ExecutionContext(null, model, instance, instance.Token, null);

            instance.HandleEvent(
                context, new object()
                );
            instance.IsRunning.Should().BeTrue();
            instance.Token.ExecutionPoint.Should().Be("middle");
        }
        public void StartMiddleEnd()
        {
            var models = new InMemoryProcessModelsStore();

            models.Store(ProcessModel.Create()
                         .AddEventCatcher("start", TypedEventCatcher <Start> .Create())
                         .AddEventCatcher("middle", CatchAnyEventCatcher.Create())
                         .AddEventThrower("end", SilentEventThrower.Instance)
                         .AddSequenceFlow("start", "middle", "end"));

            var instances = new InMemoryProcessInstancesStore();

            var manager = new ProcessManager(models, instances);

            var result = manager.HandleEvent(new Start()).First();

            manager.GetExecutionPoint(
                result.ProcessInstanceId,
                result.AffectedTokens.First()
                ).Should().Be("middle");

            result = manager.HandleEvent(result.ProcessInstanceId, result.AffectedTokens.First(), new object());
            manager.InstancesStore.GetById(result.ProcessInstanceId)
            .IsDone.Should().Be(true);
        }
Esempio n. 3
0
        public void FinishWhenMeetingTheEnd()
        {
            var model = ProcessModel.Create()
                        .AddEventCatcher(
                "start",
                CatchAnyEventCatcher.Create()
                )
                        .AddEventCatcher(
                "middle",
                CatchAnyEventCatcher.Create()
                )
                        .AddEventThrower(
                "end",
                SilentEventThrower.Instance
                )
                        .AddSequenceFlow("start", "middle")
                        .AddSequenceFlow("middle", "end");

            var instance = ProcessInstance.Create(model.Id);

            var context = new ExecutionContext(null, model, instance, instance.Token, null);

            // start
            instance.HandleEvent(
                context, new object()
                ).Should().BeEquivalentTo(instance.Token);

            // middle
            instance.HandleEvent(
                context, new object()
                ).Should().BeEmpty();

            instance.IsRunning.Should().BeFalse();
            instance.IsDone.Should().BeTrue();
        }
Esempio n. 4
0
        public void SaveStartEventNameAtTheFirstHistoryEntry()
        {
            var model = ProcessModel.Create()
                        .AddEventCatcher(
                "start",
                CatchAnyEventCatcher.Create()
                )
                        .AddEventCatcher(
                "middle",
                CatchAnyEventCatcher.Create()
                )
                        .AddEventThrower(
                "end",
                SilentEventThrower.Instance
                )
                        .AddSequenceFlow("start", "middle")
                        .AddSequenceFlow("middle", "end");

            var instance = ProcessInstance.Create(Guid.Parse(model.Id));

            var context = new ExecutionContext(null, model, instance, instance.Token, null);

            instance.HandleEvent(
                context, new object()
                );

            instance.History.First().ExecutionPoint.Should().Be("start");
        }
Esempio n. 5
0
        public void ReturnTwoTokensWhenStartEventHaveTwoOutcomingConnections()
        {
            var model = ProcessModel.Create()
                        .AddEventCatcher(
                "start",
                CatchAnyEventCatcher.Create()
                )
                        .AddEventCatcher(
                "middle1",
                CatchAnyEventCatcher.Create()
                )
                        .AddEventCatcher(
                "middle2",
                CatchAnyEventCatcher.Create()
                )
                        .AddEventThrower(
                "end",
                SilentEventThrower.Instance
                )
                        .AddSequenceFlow("start", "middle1")
                        .AddSequenceFlow("start", "middle2")
                        .AddSequenceFlow("middle1", "end")
                        .AddSequenceFlow("middle2", "end");

            var instance = ProcessInstance.Create(model.Id);
            var context  = new ExecutionContext(null, model, instance, instance.Token, null);
            var tokens   = instance.HandleEvent(context, new object());

            tokens.Count().Should().Be(2);

            tokens.Select(token => token.ExecutionPoint)
            .Should().BeEquivalentTo("middle1", "middle2");
        }
Esempio n. 6
0
        public void HaveDefaultOutput()
        {
            var catcher =
                (CatchAnyEventCatcher)CatchAnyEventCatcher.Create();

            catcher.GetDataOutputByName("default")
            .Should().NotBeNull();
        }
Esempio n. 7
0
        public void TokenShouldNotBeActiveWhenProcessIsDone()
        {
            var model = ProcessModel.Create()
                        .AddEventCatcher("start", CatchAnyEventCatcher.Create())
                        .AddEventThrower("end", SilentEventThrower.Instance)
                        .AddSequenceFlow("start", "end");

            var instance = ProcessInstance.Create(model.Id);
            var context  = new ExecutionContext(null, model, instance, instance.Token, null);

            instance.HandleEvent(context, new object());

            instance.Token.WasReleased.Should().BeTrue();
            instance.Token.IsActive.Should().BeFalse();
        }
Esempio n. 8
0
        public void BasicSetup()
        {
            var passed = false;
            var model  = ProcessModel.Create()
                         .AddEventCatcher("start", CatchAnyEventCatcher.Create())
                         .AddActivity("activity", LambdaActivity.Create(() => passed = true))
                         .AddEventThrower("end", SilentEventThrower.Instance)
                         .AddSequenceFlow("start", "activity", "end");

            var instance = ProcessInstance.Create(model.Id);

            var context = new ExecutionContext(null, model, instance, instance.Token, null);

            instance.HandleEvent(context, new object());
            passed.Should().BeTrue();
        }
Esempio n. 9
0
        public void EnumerateStartEventCatchers()
        {
            var processModel = ProcessModel.Create()
                               .AddEventCatcher(
                "start",
                CatchAnyEventCatcher.Create()
                )
                               .AddEventThrower(
                "end",
                SilentEventThrower.Instance
                )
                               .AddSequenceFlow("start", "end");

            var catchers = processModel.GetStartEventCatchers();

            Assert.Single(catchers);
        }
Esempio n. 10
0
        public void ReturnElementByName()
        {
            var obj = NamedProcessElement <IEventThrower> .Create("middle", SilentEventThrower.Instance);

            var processModel = ProcessModel.Create()
                               .AddEventCatcher(
                "start",
                CatchAnyEventCatcher.Create()
                )
                               .AddEventThrower(obj)
                               .AddEventThrower(
                "end",
                SilentEventThrower.Instance
                )
                               .AddSequenceFlow("start", "middle")
                               .AddSequenceFlow("middle", "end");

            processModel.GetElementByName("middle").Should().Be(obj);
        }
Esempio n. 11
0
        public void RefuseEventsWhenItIsDone()
        {
            var count = 0;
            var model = ProcessModel.Create()
                        .AddEventCatcher("start", CatchAnyEventCatcher.Create())
                        .AddActivity("a1", LambdaActivity.Create(() => count++))
                        .AddActivity("a2", LambdaActivity.Create(() => count++))
                        .AddActivity("a3", LambdaActivity.Create(() => count++))
                        .AddEventThrower("end", SilentEventThrower.Instance)
                        .AddSequenceFlow("start", "a1", "a2", "a3", "end");

            var instance = ProcessInstance.Create(model.Id);

            var context = new ExecutionContext(null, model, instance, instance.Token, null);

            instance.HandleEvent(context, new object());
            instance.HandleEvent(context, new object());

            count.Should().Be(3);
        }
Esempio n. 12
0
        public void ExecuteActivitiesBetweenEvents()
        {
            var count = 0;
            var model = ProcessModel.Create()
                        .AddEventCatcher("start", CatchAnyEventCatcher.Create())
                        .AddActivity("a1", LambdaActivity.Create(() => count++))
                        .AddActivity("a2", LambdaActivity.Create(() => count++))
                        .AddActivity("a3", LambdaActivity.Create(() => count++))
                        .AddEventThrower("end", SilentEventThrower.Instance)
                        .AddSequenceFlow("start", "a1", "a2", "a3", "end");

            var instance = ProcessInstance.Create(model.Id);
            var context  = new ExecutionContext(null, model, instance, instance.Token, null);

            instance.HandleEvent(context, new object());

            instance.IsDone.Should().BeTrue();
            instance.IsRunning.Should().BeFalse();
            instance.History.Count().Should().Be(8);
            count.Should().Be(3);
        }
Esempio n. 13
0
        public void CreateInstancesOnlyWhenApplicable()
        {
            var model = ProcessModel.Create()
                        .AddEventCatcher("start", TypedEventCatcher <Start> .Create())
                        .AddEventCatcher("middle", CatchAnyEventCatcher.Create())
                        .AddEventThrower("end", SilentEventThrower.Instance)
                        .AddSequenceFlow("start", "middle", "end");

            var models = new InMemoryProcessModelsStore();

            models.Store(model);

            var instances = new InMemoryProcessInstancesStore();

            var manager = new ProcessManager(models, instances);

            manager.HandleEvent(new object());
            manager.InstancesStore.GetRunningInstancesCount().Should().Be(0);

            manager.HandleEvent(new Start());
            manager.InstancesStore.GetRunningInstancesCount().Should().Be(1);
        }
Esempio n. 14
0
        public void UsingDataReceivedInStartEventInTheFollowingAction()
        {
            var    input  = "Hello World";
            string output = null;

            var start = CatchAnyEventCatcher.Create();

            start.SetEventDataOutput("o");

            var activity = LambdaActivity.Create((la, ctx) =>
            {
                var i  = la.GetDataInputByName("i");
                output = (string)i.GetCurrentValue(ctx, "middle");
            });

            activity.Inputs.Add("i");

            var model = ProcessModel.Create()
                        .AddEventCatcher("start", start)
                        .AddActivity("middle", activity)
                        .AddEventThrower("end", SilentEventThrower.Instance)
                        .AddSequenceFlow("start", "middle", "end")
                        .AddDataAssociation("startToMiddle",
                                            DataAssociation.Create("start", "o", "middle", "i"));

            var models = new InMemoryProcessModelsStore();

            models.Store(model);

            var instances = new InMemoryProcessInstancesStore();

            var pm = new ProcessManager(models, instances);

            pm.HandleEvent(input);

            output.Should().Be(input);
        }
Esempio n. 15
0
 public ProcessModel AddEventCatcher(string name)
 => AddEventCatcher(name, CatchAnyEventCatcher.Create());