Exemple #1
0
        public void TestEqOperatorWithJTokens()
        {
            var c = StateMachineBuilder.ChoiceState()
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.StringEquals(null, "value")))
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.NumericEquals(null, 33)))
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.TimestampEquals(null, new DateTime(2018, 10, 22, 22, 33, 11))))
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.BooleanEquals(null, true)))
                    .Build();

            var choices = c.Choices.ToArray();

            Assert.True(choices[0].Condition.Match(new JValue("value")));
            Assert.False(choices[0].Condition.Match(new JValue("not-value")));

            Assert.True(choices[1].Condition.Match(new JValue(33)));
            Assert.False(choices[1].Condition.Match(new JValue(34)));

            Assert.True(choices[2].Condition.Match(new JValue(new DateTime(2018, 10, 22, 22, 33, 11))));
            Assert.False(choices[2].Condition.Match(new JValue(new DateTime(2018, 10, 22, 22, 33, 12))));

            Assert.True(choices[3].Condition.Match(new JValue(true)));
            Assert.False(choices[3].Condition.Match(new JValue(false)));
        }
Exemple #2
0
        public void TestIsBoolean()
        {
            var c = StateMachineBuilder.ChoiceState()
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.IsBoolean("$.isBoolean", true)))
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.IsBoolean("$.isBoolean", false))
                            )
                    .Build();

            var choices = c.Choices.ToArray();

            Assert.False(choices[0].Condition.Match(JObject.FromObject(new { isBoolean = "str" })));
            Assert.False(choices[0].Condition.Match(JObject.FromObject(new { isBoolean = DateTime.Now })));
            Assert.False(choices[0].Condition.Match(JObject.FromObject(new { isBoolean = 33 })));
            Assert.False(choices[0].Condition.Match(JObject.FromObject(new { isBoolean = 33.23 })));
            Assert.True(choices[0].Condition.Match(JObject.FromObject(new { isBoolean = true })));

            Assert.True(choices[1].Condition.Match(JObject.FromObject(new { isBoolean = "str" })));
            Assert.True(choices[1].Condition.Match(JObject.FromObject(new { isBoolean = DateTime.Now })));
            Assert.True(choices[1].Condition.Match(JObject.FromObject(new { isBoolean = 33 })));
            Assert.True(choices[1].Condition.Match(JObject.FromObject(new { isBoolean = 33.23 })));
            Assert.False(choices[1].Condition.Match(JObject.FromObject(new { isBoolean = true })));
        }
Exemple #3
0
 public void ParallelState_ChoiceStateWithTerminalPath_IsValid()
 {
     AssertHasPathToTerminal(
         StateMachineBuilder.StateMachine()
         .StartAt("Parallel")
         .State("Parallel", StateMachineBuilder.ParallelState()
                .Transition(StateMachineBuilder.End())
                .Branch(StateMachineBuilder.SubStateMachine()
                        .StartAt("Initial")
                        .State("Initial", StateMachineBuilder.PassState()
                               .Transition(StateMachineBuilder
                                           .Next("Choice")))
                        .State("Choice", StateMachineBuilder.ChoiceState()
                               .DefaultStateName("Default")
                               .Choice(StateMachineBuilder.Choice()
                                       .Transition(StateMachineBuilder
                                                   .Next("Initial"))
                                       .Condition(StateMachineBuilder
                                                  .StringEquals("$.foo",
                                                                "bar")))
                               .Choice(StateMachineBuilder.Choice()
                                       .Transition(StateMachineBuilder
                                                   .Next("Default"))
                                       .Condition(StateMachineBuilder
                                                  .StringEquals("$.foo",
                                                                "bar"))))
                        .State("Default",
                               StateMachineBuilder
                               .PassState().Transition(StateMachineBuilder.End())))));
 }
Exemple #4
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 #5
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 })));
        }
Exemple #6
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
        }
Exemple #7
0
        public void TestMatchOperatorWithJObject()
        {
            var c = StateMachineBuilder.ChoiceState()
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.Match("$.varstr", "val*")))
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.Match("$.varstr", "val*ue")))
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.Match("$.varstr", "val\\*ue")))
                    .Build();

            var choices = c.Choices.ToArray();

            Assert.True(choices[0].Condition.Match(JObject.FromObject(new { varstr = "value" })));
            Assert.False(choices[0].Condition.Match(JObject.FromObject(new { varstr = "test" })));

            Assert.True(choices[1].Condition.Match(JObject.FromObject(new { varstr = "value" })));
            Assert.True(choices[1].Condition.Match(JObject.FromObject(new { varstr = "valDFDFDFue" })));

            Assert.True(choices[2].Condition.Match(JObject.FromObject(new { varstr = "val*ue" })));
            Assert.False(choices[2].Condition.Match(JObject.FromObject(new { varstr = "value" })));
        }
Exemple #8
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
        }
Exemple #9
0
        public void TestNotOperator()
        {
            var c = StateMachineBuilder.ChoiceState()
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.Not(StateMachineBuilder.StringEquals("$.varstr", "value"))))
                    .Build();

            var choices = c.Choices.ToArray();

            Assert.False(choices[0].Condition.Match(JObject.FromObject(new { varstr = "value" }))); //Equal
        }
Exemple #10
0
 public void MissingExpectedValue_StringEqualsCondition_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         StateMachineBuilder.StateMachine()
                                         .StartAt("Initial")
                                         .State("Initial", StateMachineBuilder.ChoiceState()
                                                .Choice(StateMachineBuilder.Choice()
                                                        .Condition(StateMachineBuilder.StringEquals("$.Foo", null))
                                                        .Transition(StateMachineBuilder.Next("Terminal")))
                                                .DefaultStateName("Terminal"))
                                         .State("Terminal", StateMachineBuilder.SucceedState())
                                         .Build());
 }
Exemple #11
0
 public void NoConditionSetForNot_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         StateMachineBuilder.StateMachine()
                                         .StartAt("Initial")
                                         .State("Initial", StateMachineBuilder.ChoiceState()
                                                .Choice(StateMachineBuilder.Choice()
                                                        .Condition(NotCondition.GetBuilder())
                                                        .Transition(StateMachineBuilder.Next("Terminal")))
                                                .DefaultStateName("Terminal"))
                                         .State("Terminal", StateMachineBuilder.SucceedState())
                                         .Build());
 }
Exemple #12
0
 public void ChoiceStateWithInvalidChoiceTransition_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         StateMachineBuilder.StateMachine()
                                         .StartAt("Initial")
                                         .State("Initial", StateMachineBuilder.ChoiceState()
                                                .Choice(StateMachineBuilder.Choice()
                                                        .Condition(StateMachineBuilder.StringEquals("$.Foo", "bar"))
                                                        .Transition(StateMachineBuilder.Next("NoSuchState")))
                                                .DefaultStateName("Terminal"))
                                         .State("Terminal", StateMachineBuilder.SucceedState())
                                         .Build());
 }
Exemple #13
0
        public void ChoiceStateWithNotCondition()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.ChoiceState()
                                      .DefaultStateName("DefaultState")
                                      .Choice(StateMachineBuilder.Choice().Transition(StateMachineBuilder.Next("NextState"))
                                              .Condition(StateMachineBuilder.Not(
                                                             StateMachineBuilder.StringGreaterThanEquals("$.var", "value")))))
                               .State("NextState", StateMachineBuilder.SucceedState())
                               .State("DefaultState", StateMachineBuilder.SucceedState())
                               .Build();

            AssertStateMachine(stateMachine, "ChoiceStateWithNotCondition.json");
        }
Exemple #14
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 #15
0
        public void ChoiceStateWithAndCondition()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.ChoiceState()
                                      .DefaultStateName("DefaultState")
                                      .Choice(StateMachineBuilder.Choice().Transition(StateMachineBuilder.Next("NextState"))
                                              .Condition(
                                                  StateMachineBuilder.And(StateMachineBuilder.StringEquals("$.var", "value"),
                                                                          StateMachineBuilder.NumericEquals("$.other-var", 10)
                                                                          ))))
                               .State("NextState", StateMachineBuilder.SucceedState())
                               .State("DefaultState", StateMachineBuilder.SucceedState())
                               .Build();

            AssertStateMachine(stateMachine, "ChoiceStateWithAndCondition.json");
        }
Exemple #16
0
        public void SimpleChoiceState()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.ChoiceState()
                                      .Comment("My choice state")
                                      .DefaultStateName("DefaultState")
                                      .InputPath("$.input")
                                      .OutputPath("$.output")
                                      .Choice(StateMachineBuilder.Choice().Transition(StateMachineBuilder.Next("NextState"))
                                              .Condition(StateMachineBuilder.StringEquals("$.var", "value"))))
                               .State("NextState", StateMachineBuilder.SucceedState())
                               .State("DefaultState", StateMachineBuilder.SucceedState())
                               .Build();

            AssertStateMachine(stateMachine, "SimpleChoiceState.json");
        }
Exemple #17
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 })));
        }
Exemple #18
0
        public void ChoiceStateWithMultipleChoices()
        {
            var stateMachine = StateMachineBuilder.StateMachine()
                               .StartAt("InitialState")
                               .State("InitialState", StateMachineBuilder.ChoiceState()
                                      .DefaultStateName("DefaultState")
                                      .Choices(
                                          StateMachineBuilder.Choice().Transition(StateMachineBuilder.Next("NextState"))
                                          .Condition(StateMachineBuilder.StringEquals("$.var", "value")),
                                          StateMachineBuilder.Choice().Transition(StateMachineBuilder.Next("OtherNextState"))
                                          .Condition(StateMachineBuilder.NumericGreaterThan("$.number", 10))))
                               .State("NextState", StateMachineBuilder.SucceedState())
                               .State("OtherNextState", StateMachineBuilder.SucceedState())
                               .State("DefaultState", StateMachineBuilder.SucceedState())
                               .Build();

            AssertStateMachine(stateMachine, "ChoiceStateWithMultipleChoices.json");
        }
Exemple #19
0
        public void TestIsNull()
        {
            var c = StateMachineBuilder.ChoiceState()
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.IsNull("$.isNull", true)))
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.IsNull("$.isNotNull", false))
                            )
                    .Build();

            var choices = c.Choices.ToArray();

            Assert.True(choices[0].Condition.Match(JObject.Parse("{\"isNull\":null}")));
            Assert.False(choices[0].Condition.Match(JObject.Parse("{\"isNull\":33}")));

            Assert.True(choices[1].Condition.Match(JObject.Parse("{\"isNotNull\":22}")));
            Assert.False(choices[1].Condition.Match(JObject.Parse("{\"isNotNull\":null}")));
        }
Exemple #20
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");
        }
Exemple #21
0
 public void ChoiceStateWithPathOut_IsValid()
 {
     AssertNoCycle(
         StateMachineBuilder.StateMachine()
         .StartAt("Initial")
         .State("Initial", StateMachineBuilder.PassState()
                .Transition(StateMachineBuilder.Next("ChoiceOne")))
         .State("ChoiceOne", StateMachineBuilder.ChoiceState()
                .DefaultStateName("DefaultOne")
                .Choice(StateMachineBuilder.Choice()
                        .Transition(StateMachineBuilder.Next("ChoiceTwo"))
                        .Condition(StateMachineBuilder.StringEquals("$.foo", "bar"))))
         .State("DefaultOne", StateMachineBuilder.SucceedState())
         .State("ChoiceTwo", StateMachineBuilder.ChoiceState()
                .DefaultStateName("DefaultTwo")
                .Choice(StateMachineBuilder.Choice()
                        .Transition(StateMachineBuilder.Next("ChoiceOne"))
                        .Condition(StateMachineBuilder.StringEquals("$.foo", "bar"))))
         .State("DefaultTwo",
                StateMachineBuilder.PassState().Transition(StateMachineBuilder.Next("ChoiceTwo"))));
 }
Exemple #22
0
 public void ChoiceStateWithClosedCycle_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         AssertCycle(StateMachineBuilder.StateMachine()
                                                     .StartAt("Initial")
                                                     .State("Initial", StateMachineBuilder.PassState()
                                                            .Transition(StateMachineBuilder.Next("Choice")))
                                                     .State("Choice", StateMachineBuilder.ChoiceState()
                                                            .DefaultStateName("Terminal")
                                                            .Choice(StateMachineBuilder.Choice()
                                                                    .Transition(StateMachineBuilder.Next("Terminal"))
                                                                    .Condition(StateMachineBuilder.StringEquals("$.foo", "bar")))
                                                            .Choice(StateMachineBuilder.Choice()
                                                                    .Transition(StateMachineBuilder.Next("NonTerminal"))
                                                                    .Condition(StateMachineBuilder.StringEquals("$.foo", "bar"))))
                                                     .State("Terminal", StateMachineBuilder.PassState().Transition(StateMachineBuilder.End()))
                                                     .State("NonTerminal",
                                                            StateMachineBuilder.PassState().Transition(StateMachineBuilder.Next("Cyclic")))
                                                     .State("Cyclic",
                                                            StateMachineBuilder.PassState().Transition(StateMachineBuilder.Next("NonTerminal")))));
 }
Exemple #23
0
 public void ParallelState_WithChoiceThatHasNoTerminalPath_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         AssertDoesNotHaveTerminalPath(
                                             StateMachineBuilder.StateMachine()
                                             .StartAt("Parallel")
                                             .State("Parallel", StateMachineBuilder.ParallelState()
                                                    .Transition(StateMachineBuilder.End())
                                                    .Branch(StateMachineBuilder.SubStateMachine()
                                                            .StartAt("Initial")
                                                            .State("Initial",
                                                                   StateMachineBuilder
                                                                   .PassState()
                                                                   .Transition(StateMachineBuilder
                                                                               .Next("Choice")))
                                                            .State("Choice",
                                                                   StateMachineBuilder
                                                                   .ChoiceState()
                                                                   .DefaultStateName("Default")
                                                                   .Choice(StateMachineBuilder
                                                                           .Choice()
                                                                           .Transition(StateMachineBuilder
                                                                                       .Next("Initial"))
                                                                           .Condition(StateMachineBuilder
                                                                                      .StringEquals("$.foo",
                                                                                                    "bar")))
                                                                   .Choice(StateMachineBuilder
                                                                           .Choice()
                                                                           .Transition(StateMachineBuilder
                                                                                       .Next("Default"))
                                                                           .Condition(StateMachineBuilder
                                                                                      .StringEquals("$.foo",
                                                                                                    "bar"))))
                                                            .State("Default",
                                                                   StateMachineBuilder
                                                                   .PassState()
                                                                   .Transition(StateMachineBuilder
                                                                               .Next("Choice")))))));
 }
Exemple #24
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 #25
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");
        }
Exemple #26
0
        public void TestEqOperatorWithJObject()
        {
            var c = StateMachineBuilder.ChoiceState()
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.StringEquals("$.varstr", "value")))
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.NumericEquals("$.varint", 33)))
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.TimestampEquals("$.vardate",
                                                                           new DateTime(2018, 10, 22, 22, 33, 11))))
                    .Choice(StateMachineBuilder.Choice()
                            .Transition(StateMachineBuilder.Next("NextState"))
                            .Condition(StateMachineBuilder.BooleanEquals("$.varbool", true)))
                    .Build();

            var choices = c.Choices.ToArray();

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

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

            Assert.True(choices[2].Condition
                        .Match(JObject.FromObject(new { vardate = new DateTime(2018, 10, 22, 22, 33, 11) })));
            Assert.False(choices[2].Condition
                         .Match(JObject.FromObject(new { vardate = new DateTime(2018, 10, 22, 22, 33, 12) })));

            Assert.True(choices[3].Condition.Match(JObject.FromObject(new { varbool = true })));
            Assert.False(choices[3].Condition.Match(JObject.FromObject(new { varbool = false })));
            Assert.False(choices[3].Condition.Match(JToken.Parse("true")));
            Assert.False(choices[3].Condition.Match(JToken.Parse("false")));
        }
Exemple #27
0
 public void ChoiceStateWithOnlyCycles_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         AssertDoesNotHaveTerminalPath(StateMachineBuilder.StateMachine()
                                                                       .StartAt("Initial")
                                                                       .State("Initial", StateMachineBuilder.PassState()
                                                                              .Transition(StateMachineBuilder.Next("Choice")))
                                                                       .State("Choice", StateMachineBuilder.ChoiceState()
                                                                              .DefaultStateName("Default")
                                                                              .Choice(StateMachineBuilder.Choice()
                                                                                      .Transition(StateMachineBuilder
                                                                                                  .Next("Initial"))
                                                                                      .Condition(StateMachineBuilder
                                                                                                 .StringEquals("$.foo",
                                                                                                               "bar")))
                                                                              .Choice(StateMachineBuilder.Choice()
                                                                                      .Transition(StateMachineBuilder
                                                                                                  .Next("Default"))
                                                                                      .Condition(StateMachineBuilder
                                                                                                 .StringEquals("$.foo",
                                                                                                               "bar"))))
                                                                       .State("Default",
                                                                              StateMachineBuilder.PassState().Transition(StateMachineBuilder.Next("Choice")))));
 }