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 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 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"); }
public void TestEqOperatorWithJObject() { var c = StateMachineBuilder.ChoiceState() .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.StringEquals("$.varstr", "value"))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.NumericEquals("$.varint", 33))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.TimestampEquals("$.vardate", new DateTime(2018, 10, 22, 22, 33, 11)))) .Choice(StateMachineBuilder.Choice() .Transition(StateMachineBuilder.Next("NextState")) .Condition(StateMachineBuilder.BooleanEquals("$.varbool", true))) .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 = "notValue" }))); Assert.True(choices[1].Condition.Match(JObject.FromObject(new { varint = 33 }))); Assert.False(choices[1].Condition.Match(JObject.FromObject(new { varint = 34 }))); Assert.True(choices[2].Condition .Match(JObject.FromObject(new { vardate = new DateTime(2018, 10, 22, 22, 33, 11) }))); Assert.False(choices[2].Condition .Match(JObject.FromObject(new { vardate = new DateTime(2018, 10, 22, 22, 33, 12) }))); Assert.True(choices[3].Condition.Match(JObject.FromObject(new { varbool = true }))); Assert.False(choices[3].Condition.Match(JObject.FromObject(new { varbool = false }))); Assert.False(choices[3].Condition.Match(JToken.Parse("true"))); Assert.False(choices[3].Condition.Match(JToken.Parse("false"))); }