public async Task TransitionPrecedenceTest() { var sm = new StateMachineBuilder <TrigType, States>() .CreateTestState(States.S1) .Transition(TrigType.T1, States.S2) .End() .InterruptTestState(TrigType.T1, States.INTER1) .CreateTestState(States.S2) .Loop(TrigType.T2) .Transition(TrigType.T3, States.S1) .End() .Build(States.S1); sm.Next(TrigType.T1); sm.Next(TrigType.T1); sm.Next(TrigType.T3); await sm.NextAsync(TrigType.T1); TestStateMachineContext <TrigType, States> .GetStateTimesCalled(States.INTER1).ShouldBe(1); TestStateMachineContext <TrigType, States> .Result.ShouldBe("_T1-S2_T1-INTER1_T3-S1_T1-S2"); }
public async Task IgnoringState() { var sm = new StateMachineBuilder <TrigType, States>() .CreateTestState(States.S1, true) .Transition(TrigType.T1, States.S2) .Ignoring() .End() .CreateTestState(States.S2, true) .Ignoring() .End() .InterruptTestState(TrigType.T2, States.INTER1) .Build(States.S1); sm.Next(TrigType.T3); await sm.NextAsync(TrigType.T3); TestStateMachineContext <TrigType, States> .Result.ShouldBe(""); sm.Next(TrigType.T1); TestStateMachineContext <TrigType, States> .Result.ShouldBe("_ET1-ES1_T1-S2"); sm.Next(TrigType.T2); TestStateMachineContext <TrigType, States> .Result.ShouldBe("_ET1-ES1_T1-S2_ET2-ES2_T2-INTER1"); }
public void Transitions_test() { var sm = new StateMachineBuilder <TrigType, States>() .CreateTestState(States.S1, true) .AllTransition(States.S2) .End() .CreateTestState(States.S2) .Loop(TrigType.T2) .Transition(TrigType.T1, States.S1) .End() .Build(States.S1); sm.Next(TrigType.T1); sm.Next(TrigType.T1); sm.Next(TrigType.T1); TestStateMachineContext <TrigType, States> .GetStateTimesCalled(States.S1).ShouldBe(1); TestStateMachineContext <TrigType, States> .GetStateExitTimesCalled(States.S1).ShouldBe(2); TestStateMachineContext <TrigType, States> .GetStateTimesCalled(States.S2).ShouldBe(2); TestStateMachineContext <TrigType, States> .Result.ShouldBe("_ET1-ES1_T1-S2_T1-S1_ET1-ES1_T1-S2"); sm.CurrentState.Name.ShouldBe(States.S2); }
public async Task InterruptState() { int i1Called = 0; int i2Called = 0; var sm = new StateMachineBuilder <TrigType, States>() .CreateTestState(States.S1) .End() .AsyncInterruptState(TrigType.T2, _ => { i2Called++; return(Task.CompletedTask); }, States.INTER2) .InterruptState(TrigType.T1, _ => i1Called++, States.INTER1) .Build(States.S1); sm.Next(TrigType.T1); sm.Next(TrigType.T2); await sm.NextAsync(TrigType.T1); await sm.NextAsync(TrigType.T2); i1Called.ShouldBe(2); i2Called.ShouldBe(2); TestStateMachineContext <TrigType, States> .GetStateTimesCalled(States.S1).ShouldBe(0); }
public async Task ResetInterruptState() { var sm = new StateMachineBuilder <TrigType, States>() .CreateTestState(States.S1) .Transition(TrigType.T2, States.S2) .End() .CreateTestState(States.S2) .Loop(TrigType.T2) .End() .ResetInterruptState(TrigType.T1, t => {}, States.RESETINTER1, States.S1) .AsyncResetInterruptState(TrigType.T3, _ => Task.CompletedTask, States.RESETINTER2, States.S2) .Build(States.S1); sm.Next(TrigType.T2); sm.Next(TrigType.T1); sm.CurrentState.Name.ShouldBe(States.S1); await sm.NextAsync(TrigType.T3); sm.CurrentState.Name.ShouldBe(States.S2); sm.Next(TrigType.T2); TestStateMachineContext <TrigType, States> .GetStateTimesCalled(States.S1).ShouldBe(0); TestStateMachineContext <TrigType, States> .GetStateTimesCalled(States.S2).ShouldBe(2); TestStateMachineContext <TrigType, States> .Result.ShouldBe("_T2-S2_T2-S2"); sm.CurrentState.Name.ShouldBe(States.S2); }
public void Next_called_on_context_enters_next_state_after_current_finished() { bool s1Called = false; bool s2Called = false; bool s3Called = false; bool s4Called = false; var sm = new StateMachineBuilder <TrigType, States>() .CreateState(States.S0) .Transition(TrigType.T1, States.S1) .End() .CreateState(States.S1) .Enter(args => { args.Context.Next(TrigType.T1); s1Called = true; }) .Transition(TrigType.T1, States.S2) .End() .CreateState(States.S2) .Enter(args => { args.Context.NextAsync(TrigType.T2); s2Called = true; }) .Transition(TrigType.T2, States.S3) .End() .CreateState(States.S3) .EnterAsync(args => { s3Called = true; return(Task.CompletedTask); }) .Transition(TrigType.T2, States.S4) .End() .CreateState(States.S4) .Enter(args => s4Called = true) .End() .Build(States.S0); var current = sm.Next(TrigType.T1); current.Name.ShouldBe(States.S3); s1Called.ShouldBeTrue(); s2Called.ShouldBeTrue(); s3Called.ShouldBeTrue(); s4Called.ShouldBeFalse(); //context clear test current = sm.Next(TrigType.T2); current.Name.ShouldBe(States.S4); s4Called.ShouldBeTrue(); }
static void Main(string[] args) { var t1 = 0; var sm = new StateMachineBuilder <Trig, State>() .CreateState(State.S1) .Ignoring() .Transition(Trig.T1, State.S2) .End() .CreateState(State.S2) .Transition(Trig.T1, State.S3) .End() .CreateState(State.S3) .Transition(Trig.T2, State.S1) .End() .Build(State.S1, "example"); var vis = new StateMachineVis <Trig, State>(sm, name: "graphVizTest"); vis.Start("StateMachineLibVis.exe", clientArgs: "-c graphVizTest"); var logging = new StateMachineLogging <Trig, State>(sm); var cts = new CancellationTokenSource(); Task.Run(async() => { while (!cts.IsCancellationRequested) { if (t1 < 2) { sm.Next(Trig.T1); t1++; } else { t1 = 0; sm.Next(Trig.T2); } await Task.Delay(750, cts.Token); } }); Console.ReadKey(); vis.Stop(); cts.Cancel(); }
public void Loop_does_not_call_exit() { var sm = new StateMachineBuilder <TrigType, States>() .CreateTestState(States.S0) .Loop(TrigType.T1) .End() .Build(States.S0); sm.Next(TrigType.T1); sm.Next(TrigType.T1); sm.Next(TrigType.T1); TestStateMachineContext <TrigType, States> .Result.ShouldBe("_T1-S0_T1-S0_T1-S0"); }
public void TestLtePathOperator() { var c = StateMachineBuilder.ChoiceState() .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.StringLessThanEqualsPath("$.varstr", "$.b"))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.NumericLessThanEqualsPath("$.varint", "$.b"))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.TimestampLessThanEqualsPath("$.vardate", "$.b"))) .Build(); var choices = c.Choices.ToArray(); Assert.False(choices[0].Condition.Match(JObject.FromObject(new { varstr = "vvalue", b = "value" }))); Assert.True(choices[0].Condition.Match(JObject.FromObject(new { varstr = "notValue", b = "value" }))); Assert.True(choices[0].Condition.Match(JObject.FromObject(new { varstr = "value", b = "value" }))); //Equal Assert.False(choices[1].Condition.Match(JObject.FromObject(new { varint = 34, b = 33 }))); Assert.True(choices[1].Condition.Match(JObject.FromObject(new { varint = 30, b = 33 }))); Assert.True(choices[1].Condition.Match(JObject.FromObject(new { varint = 33, b = 33 }))); //Equal var d = new DateTime(2018, 10, 22, 22, 33, 20); Assert.False(choices[2].Condition.Match(JObject.FromObject(new { vardate = d.AddHours(1), b = d }))); Assert.True(choices[2].Condition.Match(JObject.FromObject(new { vardate = d.AddHours(-1), b = d }))); Assert.True(choices[2].Condition.Match(JObject.FromObject(new { vardate = d, b = d }))); //Equal }
public void TestLteOperator() { var c = StateMachineBuilder.ChoiceState() .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.StringLessThanEquals("$.varstr", "value"))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.NumericLessThanEquals("$.varint", 33))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.TimestampLessThanEquals("$.vardate", new DateTime(2018, 10, 22, 22, 33, 11)))) .Build(); var choices = c.Choices.ToArray(); Assert.False(choices[0].Condition.Match(JObject.FromObject(new { varstr = "vvalue" }))); Assert.True(choices[0].Condition.Match(JObject.FromObject(new { varstr = "notValue" }))); Assert.True(choices[0].Condition.Match(JObject.FromObject(new { varstr = "value" }))); //Equal Assert.False(choices[1].Condition.Match(JObject.FromObject(new { varint = 34 }))); Assert.True(choices[1].Condition.Match(JObject.FromObject(new { varint = 30 }))); Assert.True(choices[1].Condition.Match(JObject.FromObject(new { varint = 33 }))); //Equal Assert.False(choices[2].Condition .Match(JObject.FromObject(new { vardate = new DateTime(2018, 10, 22, 22, 33, 20) }))); Assert.True(choices[2].Condition .Match(JObject.FromObject(new { vardate = new DateTime(2018, 10, 22, 22, 33, 10) }))); Assert.True(choices[2].Condition .Match(JObject.FromObject(new { vardate = new DateTime(2018, 10, 22, 22, 33, 11) }))); //Equal }
public void TestGtPathOperator() { var c = StateMachineBuilder.ChoiceState() .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.StringGreaterThanPath("$.varstr", "$.a"))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.NumericGreaterThanPath("$.varint", "$.a"))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.TimestampGreaterThanPath("$.vardate", "$.a"))) .Build(); var choices = c.Choices.ToArray(); Assert.True(choices[0].Condition.Match(JObject.FromObject(new { varstr = "vvalue", a = "value" }))); Assert.False(choices[0].Condition.Match(JObject.FromObject(new { varstr = "notValue", a = "value" }))); Assert.False(choices[0].Condition .Match(JObject.FromObject(new { varstr = "value", a = "value" }))); //NotEqual Assert.True(choices[1].Condition.Match(JObject.FromObject(new { varint = 34, a = 33 }))); Assert.False(choices[1].Condition.Match(JObject.FromObject(new { varint = 30, a = 33 }))); Assert.False(choices[1].Condition.Match(JObject.FromObject(new { varint = 33, a = 33 }))); //NotEqual var d = new DateTime(2018, 10, 22, 22, 33, 11); Assert.True(choices[2].Condition.Match(JObject.FromObject(new { vardate = d.AddDays(1), a = d }))); Assert.False(choices[2].Condition.Match(JObject.FromObject(new { vardate = d.AddDays(-1), a = d }))); Assert.False(choices[2].Condition.Match(JObject.FromObject(new { vardate = d, a = d }))); //NotEqual }
public void TestEqualPathOperator() { var c = StateMachineBuilder.ChoiceState() .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.StringEqualsPath("$.a", "$.b"))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.NumericEqualsPath("$.a", "$.b"))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.TimestampEqualsPath("$.a", "$.b"))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.BooleanEqualsPath("$.a", "$.b"))) .Build(); var choices = c.Choices.ToArray(); Assert.True(choices[0].Condition.Match(JObject.FromObject(new { a = "value", b = "value" }))); Assert.False(choices[0].Condition.Match(JObject.FromObject(new { a = "value", b = "not-value" }))); Assert.True(choices[1].Condition.Match(JObject.FromObject(new { a = 33, b = 33 }))); Assert.False(choices[1].Condition.Match(JObject.FromObject(new { a = 33, b = 22 }))); var d = new DateTime(2018, 10, 22, 22, 33, 11); Assert.True(choices[2].Condition.Match(JObject.FromObject(new { a = d, b = d }))); Assert.False(choices[2].Condition.Match(JObject.FromObject(new { a = d, b = DateTime.Now }))); Assert.True(choices[3].Condition.Match(JObject.FromObject(new { a = true, b = true }))); Assert.True(choices[3].Condition.Match(JObject.FromObject(new { a = false, b = false }))); Assert.False(choices[3].Condition.Match(JObject.FromObject(new { a = false, b = true }))); }
public void ParallelStateWithCatchers() { var stateMachine = StateMachineBuilder.StateMachine() .StartAt("InitialState") .State("InitialState", StateMachineBuilder.ParallelState() .Transition(StateMachineBuilder.End()) .Branches( StateMachineBuilder.SubStateMachine() .Comment("Branch one") .StartAt("BranchOneInitial") .State("BranchOneInitial", StateMachineBuilder.SucceedState()), StateMachineBuilder.SubStateMachine() .Comment("Branch two") .StartAt("BranchTwoInitial") .State("BranchTwoInitial", StateMachineBuilder.SucceedState()) ) .Catchers(StateMachineBuilder.Catcher() .ErrorEquals("Foo", "Bar") .Transition(StateMachineBuilder.Next("RecoveryState")) .ResultPath("$.result"), StateMachineBuilder.Catcher() .CatchAll() .Transition(StateMachineBuilder.Next("OtherRecoveryState")) .ResultPath("$.result") )) .State("RecoveryState", StateMachineBuilder.SucceedState()) .State("OtherRecoveryState", StateMachineBuilder.SucceedState()) .Build(); AssertStateMachine(stateMachine, "ParallelStateWithCatchers.json"); }
public void ParallelState_ChoiceStateWithTerminalPath_IsValid() { AssertHasPathToTerminal( StateMachineBuilder.StateMachine() .StartAt("Parallel") .State("Parallel", StateMachineBuilder.ParallelState() .Transition(StateMachineBuilder.End()) .Branch(StateMachineBuilder.SubStateMachine() .StartAt("Initial") .State("Initial", StateMachineBuilder.PassState() .Transition(StateMachineBuilder .Next("Choice"))) .State("Choice", StateMachineBuilder.ChoiceState() .DefaultStateName("Default") .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder .Next("Initial")) .Condition(StateMachineBuilder .StringEquals("$.foo", "bar"))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder .Next("Default")) .Condition(StateMachineBuilder .StringEquals("$.foo", "bar")))) .State("Default", StateMachineBuilder .PassState().Transition(StateMachineBuilder.End()))))); }
public void TestEqOperatorWithJTokens() { var c = StateMachineBuilder.ChoiceState() .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.StringEquals(null, "value"))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.NumericEquals(null, 33))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.TimestampEquals(null, new DateTime(2018, 10, 22, 22, 33, 11)))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.BooleanEquals(null, true))) .Build(); var choices = c.Choices.ToArray(); Assert.True(choices[0].Condition.Match(new JValue("value"))); Assert.False(choices[0].Condition.Match(new JValue("not-value"))); Assert.True(choices[1].Condition.Match(new JValue(33))); Assert.False(choices[1].Condition.Match(new JValue(34))); Assert.True(choices[2].Condition.Match(new JValue(new DateTime(2018, 10, 22, 22, 33, 11)))); Assert.False(choices[2].Condition.Match(new JValue(new DateTime(2018, 10, 22, 22, 33, 12)))); Assert.True(choices[3].Condition.Match(new JValue(true))); Assert.False(choices[3].Condition.Match(new JValue(false))); }
public void SimpleParallelState() { var stateMachine = StateMachineBuilder.StateMachine() .StartAt("InitialState") .State("InitialState", StateMachineBuilder.ParallelState() .Comment("My parallel state") .InputPath("$.input") .OutputPath("$.output") .ResultPath("$.result") .Parameters(JObject.FromObject(new { value = "param" })) .ResultSelector(JObject.FromObject(new { value = "param" })) .Transition(StateMachineBuilder.Next("NextState")) .Branches( StateMachineBuilder.SubStateMachine() .Comment("Branch one") .StartAt("BranchOneInitial") .State("BranchOneInitial", StateMachineBuilder.SucceedState()), StateMachineBuilder.SubStateMachine() .Comment("Branch two") .StartAt("BranchTwoInitial") .State("BranchTwoInitial", StateMachineBuilder.SucceedState()) )) .State("NextState", StateMachineBuilder.SucceedState()) .Build(); AssertStateMachine(stateMachine, "SimpleParallelState.json"); }
public void TestMatchOperatorWithJObject() { var c = StateMachineBuilder.ChoiceState() .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.Match("$.varstr", "val*"))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.Match("$.varstr", "val*ue"))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.Match("$.varstr", "val\\*ue"))) .Build(); var choices = c.Choices.ToArray(); Assert.True(choices[0].Condition.Match(JObject.FromObject(new { varstr = "value" }))); Assert.False(choices[0].Condition.Match(JObject.FromObject(new { varstr = "test" }))); Assert.True(choices[1].Condition.Match(JObject.FromObject(new { varstr = "value" }))); Assert.True(choices[1].Condition.Match(JObject.FromObject(new { varstr = "valDFDFDFue" }))); Assert.True(choices[2].Condition.Match(JObject.FromObject(new { varstr = "val*ue" }))); Assert.False(choices[2].Condition.Match(JObject.FromObject(new { varstr = "value" }))); }
public void TestIsBoolean() { var c = StateMachineBuilder.ChoiceState() .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.IsBoolean("$.isBoolean", true))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.IsBoolean("$.isBoolean", false)) ) .Build(); var choices = c.Choices.ToArray(); Assert.False(choices[0].Condition.Match(JObject.FromObject(new { isBoolean = "str" }))); Assert.False(choices[0].Condition.Match(JObject.FromObject(new { isBoolean = DateTime.Now }))); Assert.False(choices[0].Condition.Match(JObject.FromObject(new { isBoolean = 33 }))); Assert.False(choices[0].Condition.Match(JObject.FromObject(new { isBoolean = 33.23 }))); Assert.True(choices[0].Condition.Match(JObject.FromObject(new { isBoolean = true }))); Assert.True(choices[1].Condition.Match(JObject.FromObject(new { isBoolean = "str" }))); Assert.True(choices[1].Condition.Match(JObject.FromObject(new { isBoolean = DateTime.Now }))); Assert.True(choices[1].Condition.Match(JObject.FromObject(new { isBoolean = 33 }))); Assert.True(choices[1].Condition.Match(JObject.FromObject(new { isBoolean = 33.23 }))); Assert.False(choices[1].Condition.Match(JObject.FromObject(new { isBoolean = true }))); }
public async Task HoldingGlobState() { int i1Called = 0; int i2Called = 0; var sm = new StateMachineBuilder <TrigType, States>() .CreateTestState(States.S1) .End() .AsyncHoldingGlobState(TrigType.T2, _ => { i2Called++; return(Task.CompletedTask); }, States.INTER2, TrigType.RET) .HoldingGlobState(TrigType.T1, _ => i1Called++, States.INTER1, TrigType.RET) .Build(States.S1); sm.Next(TrigType.T1); sm.CurrentState.Name.ShouldBe(States.INTER1); await sm.NextAsync(TrigType.T1); sm.CurrentState.Name.ShouldBe(States.INTER1); sm.Next(TrigType.T2); sm.CurrentState.Name.ShouldBe(States.INTER1); sm.Next(TrigType.RET); sm.CurrentState.Name.ShouldBe(States.S1); await sm.NextAsync(TrigType.T2); sm.CurrentState.Name.ShouldBe(States.INTER2); await sm.NextAsync(TrigType.T1); sm.CurrentState.Name.ShouldBe(States.INTER2); sm.Next(TrigType.T2); sm.CurrentState.Name.ShouldBe(States.INTER2); await sm.NextAsync(TrigType.RET); sm.CurrentState.Name.ShouldBe(States.S1); i1Called.ShouldBe(1); i2Called.ShouldBe(1); TestStateMachineContext <TrigType, States> .GetStateTimesCalled(States.S1).ShouldBe(2); }
public void InvalidTransitionInPassState_IsNotValid() { Assert.Throws <ValidationException>(() => StateMachineBuilder.StateMachine() .StartAt("Initial") .State("Initial", StateMachineBuilder.PassState() .Transition(StateMachineBuilder.Next("NoSuchState"))) .Build()); }
[Fact] // public void ValidTransitionInPassState_IsValid() { StateMachineBuilder.StateMachine() .StartAt("Initial") .State("Initial", StateMachineBuilder.PassState() .Transition(StateMachineBuilder.Next("Terminal"))) .State("Terminal", StateMachineBuilder.SucceedState()) .Build(); }
public void SimpleStateMachine_WithCycle_IsNotValid() { Assert.Throws <ValidationException>(() => AssertCycle(StateMachineBuilder.StateMachine() .StartAt("Initial") .State("Initial", StateMachineBuilder.PassState() .Transition(StateMachineBuilder.Next("Next"))) .State("Next", StateMachineBuilder.PassState() .Transition(StateMachineBuilder.Next("Initial"))))); }
public void TestNotOperator() { var c = StateMachineBuilder.ChoiceState() .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.Not(StateMachineBuilder.StringEquals("$.varstr", "value")))) .Build(); var choices = c.Choices.ToArray(); Assert.False(choices[0].Condition.Match(JObject.FromObject(new { varstr = "value" }))); //Equal }
public void ParallelStateWithInvalidTransition_IsNotValid() { Assert.Throws <ValidationException>(() => StateMachineBuilder.StateMachine() .StartAt("Initial") .State("Initial", StateMachineBuilder.ParallelState() .Branch(StateMachineBuilder.SubStateMachine() .StartAt("InitialBranchState") .State("InitialBranchState", StateMachineBuilder.SucceedState())) .Transition(StateMachineBuilder.Next("NoSuchState"))) .Build()); }
[Fact] // public void CatcherInTaskState_ValidTransition_IsValid() { StateMachineBuilder.StateMachine() .StartAt("Initial") .State("Initial", StateMachineBuilder.TaskState() .Transition(StateMachineBuilder.End()) .Catcher(StateMachineBuilder.Catcher() .Transition(StateMachineBuilder.Next("Terminal")) .CatchAll()) .Resource("arn")) .State("Terminal", StateMachineBuilder.SucceedState()) .Build(); }
public void CatcherInTaskState_InvalidTransition_IsNotValid() { Assert.Throws <ValidationException>(() => StateMachineBuilder.StateMachine() .StartAt("Initial") .State("Initial", StateMachineBuilder.TaskState() .Transition(StateMachineBuilder.End()) .Catcher(StateMachineBuilder.Catcher() .Transition(StateMachineBuilder.Next("NoSuchState")) .CatchAll()) .Resource("arn")) .Build()); }
public void NoConditionSetForNot_IsNotValid() { Assert.Throws <ValidationException>(() => StateMachineBuilder.StateMachine() .StartAt("Initial") .State("Initial", StateMachineBuilder.ChoiceState() .Choice(StateMachineBuilder.Choice() .Condition(NotCondition.GetBuilder()) .Transition(StateMachineBuilder.Next("Terminal"))) .DefaultStateName("Terminal")) .State("Terminal", StateMachineBuilder.SucceedState()) .Build()); }
public void MissingExpectedValue_StringEqualsCondition_IsNotValid() { Assert.Throws <ValidationException>(() => StateMachineBuilder.StateMachine() .StartAt("Initial") .State("Initial", StateMachineBuilder.ChoiceState() .Choice(StateMachineBuilder.Choice() .Condition(StateMachineBuilder.StringEquals("$.Foo", null)) .Transition(StateMachineBuilder.Next("Terminal"))) .DefaultStateName("Terminal")) .State("Terminal", StateMachineBuilder.SucceedState()) .Build()); }
public void ChoiceStateWithInvalidChoiceTransition_IsNotValid() { Assert.Throws <ValidationException>(() => StateMachineBuilder.StateMachine() .StartAt("Initial") .State("Initial", StateMachineBuilder.ChoiceState() .Choice(StateMachineBuilder.Choice() .Condition(StateMachineBuilder.StringEquals("$.Foo", "bar")) .Transition(StateMachineBuilder.Next("NoSuchState"))) .DefaultStateName("Terminal")) .State("Terminal", StateMachineBuilder.SucceedState()) .Build()); }
public void CatcherInTaskState_CatchAllHasOtherErrorCodes_IsNotValid() { Assert.Throws <ValidationException>(() => StateMachineBuilder.StateMachine() .StartAt("Initial") .State("Initial", StateMachineBuilder.TaskState() .Transition(StateMachineBuilder.End()) .Catcher(StateMachineBuilder.Catcher() .Transition(StateMachineBuilder.Next("Terminal")) .ErrorEquals("Foo", "Bar", ErrorCodes.ALL)) .Resource("arn")) .State("Terminal", StateMachineBuilder.SucceedState()) .Build()); }