Exemplo n.º 1
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");
        }
Exemplo n.º 2
0
        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 })));
        }
Exemplo n.º 3
0
        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");
        }
Exemplo n.º 4
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" })));
        }