public void ChoiceStateWithoutDefaultState() { var stateMachine = StateMachineBuilder.StateMachine() .StartAt("InitialState") .State("InitialState", StateMachineBuilder.ChoiceState() .Choice(StateMachineBuilder.Choice().Transition(StateMachineBuilder.Next("NextState")) .Condition( StateMachineBuilder.Or(StateMachineBuilder.StringGreaterThan("$.var", "value"), StateMachineBuilder.NumericLessThanEquals("$.other-var", 10) )))) .State("NextState", StateMachineBuilder.SucceedState()) .State("DefaultState", StateMachineBuilder.SucceedState()) .Build(); AssertStateMachine(stateMachine, "ChoiceStateWithoutDefault.json"); }
public void TestOrOperator() { var c = StateMachineBuilder.ChoiceState() .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.Or(StateMachineBuilder.StringEquals("$.varstr", "value"), StateMachineBuilder.BooleanEquals("$.varbool", false))) ) .Build(); var choices = c.Choices.ToArray(); Assert.True(choices[0].Condition.Match(JObject.FromObject(new { varstr = "value", varbool = false }))); Assert.True(choices[0].Condition.Match(JObject.FromObject(new { varstr = "valuee", varbool = false }))); Assert.True(choices[0].Condition.Match(JObject.FromObject(new { varstr = "value", varbool = true }))); Assert.False(choices[0].Condition.Match(JObject.FromObject(new { varstr = "valuee", varbool = true }))); }
public void ChoiceStateWithComplexCondition() { var stateMachine = StateMachineBuilder.StateMachine() .StartAt("InitialState") .State("InitialState", StateMachineBuilder.ChoiceState() .DefaultStateName("DefaultState") .Choice(StateMachineBuilder.Choice().Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.And( StateMachineBuilder.StringGreaterThanEquals("$.var", "value"), StateMachineBuilder.StringLessThanEquals("$.other-var", "foo"), StateMachineBuilder.Or( StateMachineBuilder.NumericLessThan("$.numeric", 9000.1), StateMachineBuilder.Not(StateMachineBuilder.NumericGreaterThanEquals("$.numeric", 42)) ) )))) .State("NextState", StateMachineBuilder.SucceedState()) .State("DefaultState", StateMachineBuilder.SucceedState()) .Build(); AssertStateMachine(stateMachine, "ChoiceStateWithComplexCondition.json"); }
public void TestBadFormat() { var dt = new DateTime(2018, 10, 22, 22, 33, 11); var c = StateMachineBuilder.ChoiceState() .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.Or(StateMachineBuilder.NumericEquals("$.varint", 33), StateMachineBuilder.NumericGreaterThan("$.varint", 33), StateMachineBuilder.NumericGreaterThanEquals("$.varint", 33), StateMachineBuilder.NumericLessThan("$.varint", 33), StateMachineBuilder.NumericLessThanEquals("$.varint", 33)))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.Or(StateMachineBuilder.TimestampEquals("$.vardate", dt), StateMachineBuilder.TimestampGreaterThan("$.vardate", dt), StateMachineBuilder.TimestampGreaterThanEquals("$.vardate", dt), StateMachineBuilder.TimestampLessThan("$.vardate", dt), StateMachineBuilder.TimestampLessThanEquals("$.vardate", dt)))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.BooleanEquals("$.varbool", true))) .Build(); var choices = c.Choices.ToArray(); //Unknown prop Assert.False(choices[0].Condition.Match(JObject.FromObject(new { other = "value" }))); Assert.False(choices[1].Condition.Match(JObject.FromObject(new { other = "value" }))); Assert.False(choices[2].Condition.Match(JObject.FromObject(new { other = "value" }))); //Assert.False(choices[0].Condition.Match(JObject.FromObject(new { varstr = "1000" }))); //string instead of correct type Assert.False(choices[0].Condition.Match(JObject.FromObject(new { varint = "hello" }))); Assert.False(choices[1].Condition.Match(JObject.FromObject(new { vardate = "hello" }))); Assert.False(choices[2].Condition.Match(JObject.FromObject(new { varbool = "hello" }))); //Invalid date Assert.False(choices[1].Condition.Match(JObject.FromObject(new { varbool = "2016-14-14T01:59:00Z" }))); }