public void TestGtOperator() { var c = StateMachineBuilder.ChoiceState() .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.StringGreaterThan("$.varstr", "value"))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.NumericGreaterThan("$.varint", 33))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.TimestampGreaterThan("$.vardate", new DateTime(2018, 10, 22, 22, 33, 11)))) .Build(); var choices = c.Choices.ToArray(); Assert.True(choices[0].Condition.Match(JObject.FromObject(new { varstr = "vvalue" }))); Assert.False(choices[0].Condition.Match(JObject.FromObject(new { varstr = "notValue" }))); Assert.False(choices[0].Condition.Match(JObject.FromObject(new { varstr = "value" }))); //NotEqual Assert.True(choices[1].Condition.Match(JObject.FromObject(new { varint = 34 }))); Assert.False(choices[1].Condition.Match(JObject.FromObject(new { varint = 30 }))); Assert.False(choices[1].Condition.Match(JObject.FromObject(new { varint = 33 }))); //NotEqual Assert.True(choices[2].Condition .Match(JObject.FromObject(new { vardate = new DateTime(2018, 10, 22, 22, 33, 20) }))); Assert.False(choices[2].Condition .Match(JObject.FromObject(new { vardate = new DateTime(2018, 10, 22, 22, 33, 10) }))); Assert.False(choices[2].Condition .Match(JObject.FromObject(new { vardate = new DateTime(2018, 10, 22, 22, 33, 11) }))); //NotEqual }
public void ChoiceStateWithMultipleChoices() { var stateMachine = StateMachineBuilder.StateMachine() .StartAt("InitialState") .State("InitialState", StateMachineBuilder.ChoiceState() .DefaultStateName("DefaultState") .Choices( StateMachineBuilder.Choice().Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.StringEquals("$.var", "value")), StateMachineBuilder.Choice().Transition(StateMachineBuilder.Next("OtherNextState")) .Condition(StateMachineBuilder.NumericGreaterThan("$.number", 10)))) .State("NextState", StateMachineBuilder.SucceedState()) .State("OtherNextState", StateMachineBuilder.SucceedState()) .State("DefaultState", StateMachineBuilder.SucceedState()) .Build(); AssertStateMachine(stateMachine, "ChoiceStateWithMultipleChoices.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" }))); }
public void ChoiceStateWithAllPrimitiveConditions() { var date = DateTime.Parse("2016-03-14T01:59:00.000Z").ToUniversalTime(); var stateMachine = StateMachineBuilder.StateMachine() .StartAt("InitialState") .State("InitialState", StateMachineBuilder.ChoiceState() .DefaultStateName("DefaultState") .Choice(StateMachineBuilder.Choice().Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.And( StateMachineBuilder.StringEquals("$.string", "value"), StateMachineBuilder.StringGreaterThan("$.string", "value"), StateMachineBuilder.StringGreaterThanEquals("$.string", "value"), StateMachineBuilder.StringLessThan("$.string", "value"), StateMachineBuilder.StringLessThanEquals("$.string", "value"), StateMachineBuilder.NumericEquals("$.integral", 42), StateMachineBuilder.NumericGreaterThan("$.integral", 42), StateMachineBuilder.NumericGreaterThanEquals("$.integral", 42), StateMachineBuilder.NumericLessThan("$.integral", 42), StateMachineBuilder.NumericLessThanEquals("$.integral", 42), StateMachineBuilder.NumericEquals("$.double", 9000.1), StateMachineBuilder.NumericGreaterThan("$.double", 9000.1), StateMachineBuilder.NumericGreaterThanEquals("$.double", 9000.1), StateMachineBuilder.NumericLessThan("$.double", 9000.1), StateMachineBuilder.NumericLessThanEquals("$.double", 9000.1), StateMachineBuilder.TimestampEquals("$.timestamp", date), StateMachineBuilder.TimestampGreaterThan("$.timestamp", date), StateMachineBuilder.TimestampGreaterThanEquals("$.timestamp", date), StateMachineBuilder.TimestampLessThan("$.timestamp", date), StateMachineBuilder.TimestampLessThanEquals("$.timestamp", date), StateMachineBuilder.BooleanEquals("$.boolean", true), StateMachineBuilder.BooleanEquals("$.boolean", false) )))) .State("NextState", StateMachineBuilder.SucceedState()) .State("DefaultState", StateMachineBuilder.SucceedState()) .Build(); AssertStateMachine(stateMachine, "ChoiceStateWithAllPrimitiveCondition.json"); }