Exemple #1
0
        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
        }
Exemple #2
0
        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");
        }
Exemple #3
0
        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" })));
        }
Exemple #4
0
        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");
        }