Exemplo n.º 1
0
        public async Task Given_graph_with_nodes_When_execute_twice_Then_will_travers_nodes_in_right_direction_both_times()
        {
            var root = new LogicNode()
            {
                Name = "root"
            };
            var childA = new LogicNode()
            {
                Name = "nodeA", Parent = root
            };
            var childB = new LogicNode()
            {
                Name = "nodeB", Parent = root
            };

            root.Children.Add(childA);
            root.Children.Add(childB);

            var nodeAA = new LogicNode()
            {
                Name = "nodeAA", Parent = childA
            };

            childA.Children.Add(nodeAA);

            var graph = new LogicGraph()
            {
                Root = root, ExecutionFlow = new OrderedExecutionFlow()
            };

            await graph.Run().ToListAsync();

            var secondRun = await graph.Run().ToListAsync();

            secondRun.Select(v => v.Node.Name).Should().Equal("root", "nodeA", "nodeAA", "nodeB");
        }
Exemplo n.º 2
0
        public async Task Given_graph_with_jint_node_raising_an_error_When_execute_Then_flow_stops()
        {
            var root = new LogicNode()
            {
                Name = "root"
            };
            var childA = new LogicNode()
            {
                Name   = "nodeA", Parent = root,
                Script = new Script("bad script")
            };
            var childB = new LogicNode()
            {
                Name = "nodeB", Parent = root
            };

            root.Children.Add(childA);
            root.Children.Add(childB);

            var nodeAA = new LogicNode()
            {
                Name = "nodeAA", Parent = childA
            };

            childA.Children.Add(nodeAA);

            var graph = new LogicGraph()
            {
                Root = root, ExecutionFlow = new OrderedExecutionFlow(new JintNodeExecutor())
            };

            var trace = new List <NodeVisitResult>();

            await foreach (var visit in graph.Run())
            {
                trace.Add(visit);
            }

            trace.Select(v => v.Node.Name).Should().Equal("root", "nodeA");

            var error = trace.Last().Result.Should().BeOfType <ExecutionError>().Subject;

            error.Message.Should().Contain("Unexpected identifier");
        }
Exemplo n.º 3
0
        public async Task Given_nodes_changing_direction_When_execute_Then_will_follow_it_commands()
        {
            var root = new LogicNode()
            {
                Name = "root"
            };
            var childARedirectParent = new TestLogicNode()
            {
                Name     = "nodeA", Parent = root,
                Behavior = () => new ExecutionSuccessAndRedirect(root)
            };

            var childB = new LogicNode()
            {
                Name = "nodeB", Parent = root
            };

            root.Children.Add(childARedirectParent);
            root.Children.Add(childB);

            var nodeAA = new LogicNode()
            {
                Name = "nodeAA", Parent = childARedirectParent
            };

            childARedirectParent.Children.Add(nodeAA);

            var graph = new LogicGraph()
            {
                Root = root, ExecutionFlow = new OrderedExecutionFlow(new TestNodeExecutor())
            };

            var trace = new List <NodeVisitResult>();


            await foreach (var visit in graph.Run())
            {
                trace.Add(visit);
            }

            trace.Select(v => v.Node.Name).Should().Equal("root", "nodeA", "nodeB");
        }
Exemplo n.º 4
0
        public async Task Given_graph_with_jint_node_stopping_flow_When_execute_Then_will_follow_jint_stop_command()
        {
            var root = new LogicNode()
            {
                Name = "root"
            };
            var childA = new LogicNode()
            {
                Name   = "nodeA", Parent = root,
                Script = new Script("flow.Stop();")
            };
            var childB = new LogicNode()
            {
                Name = "nodeB", Parent = root
            };

            root.Children.Add(childA);
            root.Children.Add(childB);

            var nodeAA = new LogicNode()
            {
                Name = "nodeAA", Parent = childA
            };

            childA.Children.Add(nodeAA);

            var graph = new LogicGraph()
            {
                Root = root, ExecutionFlow = new OrderedExecutionFlow(new JintNodeExecutor())
            };

            var trace = new List <NodeVisitResult>();

            await foreach (var visit in graph.Run())
            {
                trace.Add(visit);
            }

            trace.Select(v => v.Node.Name).Should().Equal("root", "nodeA");
        }
Exemplo n.º 5
0
        public async Task Given_nodes_stopping_flow_When_execute_Then_will_follow_it_commands()
        {
            var root = new LogicNode()
            {
                Name = "root"
            };
            var childAStop = new TestLogicNode()
            {
                Name     = "nodeA", Parent = root,
                Behavior = () => new ExecutionSuccessAndStop()
                {
                    Result = 1
                }
            };

            var childB = new LogicNode()
            {
                Name = "nodeB", Parent = root
            };

            root.Children.Add(childAStop);
            root.Children.Add(childB);

            var graph = new LogicGraph()
            {
                Root = root, ExecutionFlow = new OrderedExecutionFlow(new TestNodeExecutor())
            };

            var trace = new List <NodeVisitResult>();


            await foreach (var visit in graph.Run())
            {
                trace.Add(visit);
            }

            trace.Select(v => v.Node.Name).Should().Equal("root", "nodeA");

            trace.Last().Result.As <ExecutionSuccessAndStop>().Result.Should().Be(1);
        }
Exemplo n.º 6
0
        public async Task Given_graph_with_root_with_missing_services_When_running_Then_error_occurs()
        {
            var root = new LogicNode()
            {
                Name   = "root",
                Script = new Script("bad script",
                                    Language.JavaScriptEs5,
                                    KnownServices.ExecutionFlowService)
            };

            var graph = new LogicGraph()
            {
                Root = root, ExecutionFlow = new OrderedExecutionFlow(new JintNodeExecutor())
            };

            var result = await graph.Run().ToListAsync();

            result.Should().HaveCount(1);
            var error = result.First().Result.Should().BeOfType <ExecutionError>().Subject;

            error.Message.Should().Contain(nameof(MissingServiceException));
        }
Exemplo n.º 7
0
        public async Task Given_graph_with_nodes_When_execute_Then_will_travers_nodes_in_right_direction()
        {
            var root = new LogicNode()
            {
                Name = "root"
            };
            var childA = new LogicNode()
            {
                Name = "nodeA", Parent = root
            };
            var childB = new LogicNode()
            {
                Name = "nodeB", Parent = root
            };

            root.Children.Add(childA);
            root.Children.Add(childB);

            var nodeAA = new LogicNode()
            {
                Name = "nodeAA", Parent = childA
            };

            childA.Children.Add(nodeAA);

            var graph = new LogicGraph()
            {
                Root = root, ExecutionFlow = new OrderedExecutionFlow()
            };

            var trace = new List <NodeVisitResult>();

            await foreach (var visit in graph.Run())
            {
                trace.Add(visit);
            }

            trace.Select(v => v.Node.Name).Should().Equal("root", "nodeA", "nodeAA", "nodeB");
        }
Exemplo n.º 8
0
        public async Task Given_graph_with_jint_node_redirecting_to_not_ordered_child_When_execute_Then_will_follow_jint_redirection()
        {
            var root = new LogicNode()
            {
                Name = "root"
            };
            var childA = new LogicNode()
            {
                Name   = "nodeA", Parent = root,
                Script = new Script("flow.RedirectToChild(1);")
            };
            var childB = new LogicNode()
            {
                Name = "nodeB", Parent = root
            };

            root.Children.Add(childA);
            root.Children.Add(childB);

            var nodeAA = new LogicNode()
            {
                Name = "nodeAA", Parent = childA
            };

            childA.Children.Add(nodeAA);

            var nodeAB = new LogicNode()
            {
                Name = "nodeAB", Parent = childA
            };

            childA.Children.Add(nodeAB);

            //to check that a normal flow without redirection with pick A child before B child as expected
            var nodeBA = new LogicNode()
            {
                Name = "nodeBA", Parent = childB
            };

            childB.Children.Add(nodeBA);

            var nodeBB = new LogicNode()
            {
                Name = "nodeBB", Parent = childB
            };

            childB.Children.Add(nodeBB);

            var graph = new LogicGraph()
            {
                Root = root, ExecutionFlow = new OrderedExecutionFlow(new JintNodeExecutor())
            };

            var trace = new List <NodeVisitResult>();

            await foreach (var visit in graph.Run())
            {
                trace.Add(visit);
            }

            trace.Select(v => v.Node.Name)
            .Should().Equal("root", "nodeA", "nodeAB", "nodeAA", "nodeB", "nodeBA", "nodeBB");
        }
Exemplo n.º 9
0
        public async Task Given_graph_with_nodes_exposing_flow_facade_When_redirect_to_not_ordered_child_via_facade_Then_will_follow_facade_redirection()
        {
            var root = new LogicNode()
            {
                Name = "root"
            };
            var childA = new TestNode()
            {
                Name     = "nodeA", Parent = root,
                Behavior = f => f.RedirectToChild(1) //redirect to nodeAB instead of nodeAA
            };
            var childB = new LogicNode()
            {
                Name = "nodeB", Parent = root
            };

            root.Children.Add(childA);
            root.Children.Add(childB);

            var nodeAA = new LogicNode()
            {
                Name = "nodeAA", Parent = childA
            };

            childA.Children.Add(nodeAA);

            var nodeAB = new LogicNode()
            {
                Name = "nodeAB", Parent = childA
            };

            childA.Children.Add(nodeAB);

            //to check that a normal flow without redirection with pick A child before B child as expected
            var nodeBA = new LogicNode()
            {
                Name = "nodeBA", Parent = childB
            };

            childB.Children.Add(nodeBA);

            var nodeBB = new LogicNode()
            {
                Name = "nodeBB", Parent = childB
            };

            childB.Children.Add(nodeBB);

            var graph = new LogicGraph()
            {
                Root = root, ExecutionFlow = new OrderedExecutionFlow(new TestFacadeNodeExecutor())
            };

            var trace = new List <NodeVisitResult>();

            await foreach (var visit in graph.Run())
            {
                trace.Add(visit);
            }

            trace.Select(v => v.Node.Name)
            .Should().Equal("root", "nodeA", "nodeAB", "nodeAA", "nodeB", "nodeBA", "nodeBB");
        }