Esempio n. 1
0
        public void TestLtePathOperator()
        {
            var c = StateMachineBuilder.ChoiceState()
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.StringLessThanEqualsPath("$.varstr", "$.b")))
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.NumericLessThanEqualsPath("$.varint", "$.b")))
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.TimestampLessThanEqualsPath("$.vardate", "$.b")))
                    .Build();

            var choices = c.Choices.ToArray();

            Assert.False(choices[0].Condition.Match(JObject.FromObject(new { varstr = "vvalue", b = "value" })));
            Assert.True(choices[0].Condition.Match(JObject.FromObject(new { varstr = "notValue", b = "value" })));
            Assert.True(choices[0].Condition.Match(JObject.FromObject(new { varstr = "value", b = "value" }))); //Equal

            Assert.False(choices[1].Condition.Match(JObject.FromObject(new { varint = 34, b = 33 })));
            Assert.True(choices[1].Condition.Match(JObject.FromObject(new { varint = 30, b = 33 })));
            Assert.True(choices[1].Condition.Match(JObject.FromObject(new { varint = 33, b = 33 }))); //Equal

            var d = new DateTime(2018, 10, 22, 22, 33, 20);

            Assert.False(choices[2].Condition.Match(JObject.FromObject(new { vardate = d.AddHours(1), b = d })));
            Assert.True(choices[2].Condition.Match(JObject.FromObject(new { vardate = d.AddHours(-1), b = d })));
            Assert.True(choices[2].Condition.Match(JObject.FromObject(new { vardate = d, b = d }))); //Equal
        }