public void ThrowArgumentWhenInsertingElementWithDuplicatedName() { Action act = () => { var processModel = ProcessModel.Create() .AddActivity("act1", LambdaActivity.Create(() => { })) .AddActivity("act1", LambdaActivity.Create(() => { })); }; act.Should().Throw <ArgumentException>(); }
public void CreateWithSingleActivity() { var passed = false; var model = ProcessModel.CreateWithSingleActivity( LambdaActivity.Create(() => passed = true) ); var instance = ProcessInstance.Create(model); var context = new ExecutionContext(null, model, instance, instance.Token, null); instance.HandleEvent(context, new object()); passed.Should().BeTrue(); }
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(); }
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); }
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); }
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); }
// TODO: Ensure that COMPENSATION has no incoming or outcoming sequence flow public ProcessModel AttachAsCompensationActivity(string compensation, string to) { var that = this; if (that.GetElementByName("__compensation_start__") == null) { that = that .AddParallelGateway("__compensation_start__") .AddParallelGateway("__compensation_end__") .AddEventThrower("__process_failure__") .AddSequenceFlow("__compensation_end__", "__process_failure__") ; } var preifname = $"__compensation_pre_if_{to}__"; var ifname = $"__compensation_if_{to}_was_completed__"; var endifname = $"__compensation_endif_{to}_was_completed__"; return(new ProcessModel(Id, that.Version + 1, that.Elements, that.Associations.Add(new Association( compensation, to, AssociationType.Compensation ))) .AddActivity(preifname, LambdaActivity.Create((act, ctx) => { var shouldRun = ctx.Instance.WasActivityCompleted(to); act.GetDataOutputByName("default").Update(ctx, ctx.Token.ExecutionPoint, shouldRun); })) .AddExclusiveGateway(ifname) .AddExclusiveGateway(endifname) .AddSequenceFlow("__compensation_start__", preifname, ifname) .AddConditionalSequenceFlow(ifname, compensation, true) .AddSequenceFlow(compensation, endifname) .AddConditionalSequenceFlow(ifname, endifname, false) .AddSequenceFlow(endifname, "__compensation_end__")); }
public void ThrowArgumentNullExceptionWhenNoLambdaIsSpecified() { Action act = () => { LambdaActivity.Create((Action <ExecutionContext>)null); }; act.Should().Throw <ArgumentNullException>(); }
public ProcessModel AddActivity(string name, Action activity) => AddActivity(name, LambdaActivity.Create(activity));