Esempio n. 1
0
        public void TestEqualPathOperator()
        {
            var c = StateMachineBuilder.ChoiceState()
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.StringEqualsPath("$.a", "$.b")))
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.NumericEqualsPath("$.a", "$.b")))
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.TimestampEqualsPath("$.a", "$.b")))
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.BooleanEqualsPath("$.a", "$.b")))
                    .Build();

            var choices = c.Choices.ToArray();

            Assert.True(choices[0].Condition.Match(JObject.FromObject(new { a = "value", b = "value" })));
            Assert.False(choices[0].Condition.Match(JObject.FromObject(new { a = "value", b = "not-value" })));

            Assert.True(choices[1].Condition.Match(JObject.FromObject(new { a = 33, b = 33 })));
            Assert.False(choices[1].Condition.Match(JObject.FromObject(new { a = 33, b = 22 })));

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

            Assert.True(choices[2].Condition.Match(JObject.FromObject(new { a = d, b = d })));
            Assert.False(choices[2].Condition.Match(JObject.FromObject(new { a = d, b = DateTime.Now })));

            Assert.True(choices[3].Condition.Match(JObject.FromObject(new { a = true, b = true })));
            Assert.True(choices[3].Condition.Match(JObject.FromObject(new { a = false, b = false })));
            Assert.False(choices[3].Condition.Match(JObject.FromObject(new { a = false, b = true })));
        }