Exemple #1
0
        public void TestGtPathOperator()
        {
            var c = StateMachineBuilder.ChoiceState()
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.StringGreaterThanPath("$.varstr", "$.a")))
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.NumericGreaterThanPath("$.varint", "$.a")))
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.TimestampGreaterThanPath("$.vardate", "$.a")))
                    .Build();

            var choices = c.Choices.ToArray();

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

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

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

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