Exemple #1
0
        public async Task Adding_State_To_A_Node_Is_Available_In_Following_Node()
        {
            var pipelineNode = new PipelineNode <TestObjectA>();

            pipelineNode.AddChild(new SimpleTestNodeA1());
            pipelineNode.AddChild(new FuncNode <TestObjectA>
            {
                ExecutedFunc = ctxt =>
                {
                    ctxt.State.Foo = "Bar";
                    return(Task.FromResult(NodeResultStatus.Succeeded));
                }
            });
            pipelineNode.AddChild(new FuncNode <TestObjectA>
            {
                ExecutedFunc = ctxt =>
                               ctxt.State.Foo == "Bar"
                        ? Task.FromResult(NodeResultStatus.Succeeded)
                        : Task.FromResult(NodeResultStatus.Failed)
            });

            var testObject = new TestObjectA();
            var result     = await pipelineNode.ExecuteAsync(testObject);

            result.Status.Should().Be(NodeResultStatus.Succeeded);
        }
Exemple #2
0
        public async void Parent_Pipeline_Cancels_Execution_When_Child_Pipeline_Node_Cancelled()
        {
            var testNode1 = new SimpleTestNodeA1();
            var testNode2 = new SimpleTestNodeA1(true, false, true);
            var testNode3 = new SimpleTestNodeA2();

            var innerPipelineNode = new PipelineNode <TestObjectA>();

            innerPipelineNode.AddChild(testNode1);
            innerPipelineNode.AddChild(testNode2);

            var pipelineNode = new PipelineNode <TestObjectA>();

            pipelineNode.AddChild(innerPipelineNode);
            pipelineNode.AddChild(testNode3);

            var testObject = new TestObjectA();

            NodeResult result = await pipelineNode.ExecuteAsync(testObject);

            result.Status.ShouldEqual(NodeResultStatus.Succeeded);

            innerPipelineNode.Status.ShouldEqual(NodeRunStatus.Completed);
            testNode1.Status.ShouldEqual(NodeRunStatus.Completed);
            testNode2.Status.ShouldEqual(NodeRunStatus.NotRun);
            pipelineNode.Status.ShouldEqual(NodeRunStatus.Completed);
            testNode3.Status.ShouldEqual(NodeRunStatus.NotRun);
        }
Exemple #3
0
        public async Task Pipeline_Overall_Result_Subject_Equals_Last_Changed_Subject()
        {
            var pipelineNode = new PipelineNode <TestObjectA>();

            var node1 = new SimpleTestNodeA1();
            var node2 = new SubjectChangingNode1();
            var node3 = new SimpleTestNodeA2();
            var node4 = new SubjectChangingNode1();

            pipelineNode.AddChild(node1);
            pipelineNode.AddChild(node2);
            pipelineNode.AddChild(node3);
            pipelineNode.AddChild(node4);

            var        testObject = new TestObjectA();
            NodeResult result     = await pipelineNode.ExecuteAsync(testObject);

            pipelineNode.Status.Should().Be(NodeRunStatus.Completed);

            var childResults = result.ChildResults.ToList();

            result.Subject.Should().NotBeSameAs(testObject);
            result.Subject.Should().NotBeSameAs(childResults[1].Subject);
            result.Subject.Should().NotBeSameAs(childResults[2].Subject);
            result.Subject.Should().BeSameAs(childResults[3].Subject);
        }
Exemple #4
0
        public async void Pipeline_Result_Ids_Equal_Node_Ids()
        {
            var pipelineNode = new PipelineNode <TestObjectA> {
                Id = "PipelineNode1", FlowId = "Flow1"
            };

            pipelineNode.AddChild(new SimpleTestNodeA1 {
                FlowId = "Flow1"
            });
            pipelineNode.AddChild(new SimpleTestNodeA2 {
                Id = "Child2", FlowId = "Flow1"
            });

            var        testObject = new TestObjectA();
            NodeResult result     = await pipelineNode.ExecuteAsync(testObject);

            pipelineNode.Status.ShouldEqual(NodeRunStatus.Completed);
            result.FlowId.ShouldEqual("Flow1");
            result.Id.ShouldEqual("PipelineNode1");
            result.ChildResults.First().Id.ShouldEqual("Banzai.Test.SimpleTestNodeA1");
            result.ChildResults.First().FlowId.ShouldEqual("Flow1");

            var secondResult = result.ChildResults.FirstOrDefault(x => x.Id == "Child2");

            secondResult.ShouldNotBeNull();
            secondResult.FlowId.ShouldEqual("Flow1");
        }
Exemple #5
0
        public void Accessing_Nonexistent_State_Returns_Null()
        {
            var testObject = new TestObjectA();
            var context    = new ExecutionContext <TestObjectA>(testObject);

            object result = context.State.NonexistentProperty;

            result.Should().BeNull();
        }
        public async void Successful_Group_Run_Status_Is_Succeeded()
        {
            var groupNode = new GroupNode <TestObjectA>();

            groupNode.AddChild(new SimpleTestNodeA1());
            groupNode.AddChild(new SimpleTestNodeA2());

            var        testObject = new TestObjectA();
            NodeResult result     = await groupNode.ExecuteAsync(testObject);

            groupNode.Status.ShouldEqual(NodeRunStatus.Completed);
        }
Exemple #7
0
        public async Task Successful_Pipeline_Run_Status_Is_Succeeded()
        {
            var pipelineNode = new PipelineNode <TestObjectA>();

            pipelineNode.AddChild(new SimpleTestNodeA1());
            pipelineNode.AddChild(new SimpleTestNodeA2());

            var        testObject = new TestObjectA();
            NodeResult result     = await pipelineNode.ExecuteAsync(testObject);

            pipelineNode.Status.Should().Be(NodeRunStatus.Completed);
        }
Exemple #8
0
        public async void Successful_Node_Run_Status_Is_Completed()
        {
            var testNode = new SimpleTestNodeA1();

            var testObject = new TestObjectA();

            var context = new ExecutionContext <TestObjectA>(testObject);

            var result = await testNode.ExecuteAsync(context);

            testNode.Status.ShouldEqual(NodeRunStatus.Completed);
        }
Exemple #9
0
        public async void Pipeline_Result_Should_Equal_Initial_Subject()
        {
            var pipelineNode = new PipelineNode <TestObjectA>();

            pipelineNode.AddChild(new SimpleTestNodeA1());
            pipelineNode.AddChild(new SimpleTestNodeA2());

            var        testObject = new TestObjectA();
            NodeResult result     = await pipelineNode.ExecuteAsync(testObject);

            pipelineNode.Status.ShouldEqual(NodeRunStatus.Completed);
            result.Subject.ShouldBeSameAs(testObject);
        }
Exemple #10
0
        public async Task Group_Run_With_Fault_Returns_Failed_Status()
        {
            var groupNode = new GroupNode <TestObjectA>();

            groupNode.AddChild(new SimpleTestNodeA1());
            groupNode.AddChild(new FaultingTestNodeA());

            var        testObject = new TestObjectA();
            NodeResult result     = await groupNode.ExecuteAsync(testObject);

            result.Status.Should().Be(NodeResultStatus.Failed);
            groupNode.Status.Should().Be(NodeRunStatus.Completed);
        }
Exemple #11
0
        public async void Pipeline_Run_With_Failure_After_Success_Returns_Failed_Status()
        {
            var pipelineNode = new PipelineNode <TestObjectA>();

            pipelineNode.AddChild(new SimpleTestNodeA1());
            pipelineNode.AddChild(new FailingTestNodeA());

            var        testObject = new TestObjectA();
            NodeResult result     = await pipelineNode.ExecuteAsync(testObject);

            result.Status.ShouldEqual(NodeResultStatus.Failed);
            pipelineNode.Status.ShouldEqual(NodeRunStatus.Completed);
        }
        public async void Failed_Group_Run_Returns_Failed_Status()
        {
            var groupNode = new GroupNode <TestObjectA>();

            groupNode.AddChild(new FailingTestNodeA());
            groupNode.AddChild(new FailingTestNodeA());

            var        testObject = new TestObjectA();
            NodeResult result     = await groupNode.ExecuteAsync(testObject);

            result.Status.ShouldEqual(NodeResultStatus.Failed);
            groupNode.Status.ShouldEqual(NodeRunStatus.Completed);
        }
Exemple #13
0
        public async Task Pipeline_Run_With_Initial_Failure_Returns_Failed_Status()
        {
            var pipelineNode = new PipelineNode <TestObjectA>();

            pipelineNode.AddChild(new FailingTestNodeA());
            pipelineNode.AddChild(new SimpleTestNodeA1());

            var        testObject = new TestObjectA();
            NodeResult result     = await pipelineNode.ExecuteAsync(testObject);

            result.Status.Should().Be(NodeResultStatus.Failed);
            pipelineNode.Status.Should().Be(NodeRunStatus.Completed);
        }
Exemple #14
0
        public async void Pipeline_Child_Result_Count_Equals_Child_Node_Count()
        {
            var pipelineNode = new PipelineNode <TestObjectA>();

            pipelineNode.AddChild(new SimpleTestNodeA1());
            pipelineNode.AddChild(new SimpleTestNodeA2());

            var        testObject = new TestObjectA();
            NodeResult result     = await pipelineNode.ExecuteAsync(testObject);

            pipelineNode.Status.ShouldEqual(NodeRunStatus.Completed);
            result.ChildResults.Count().ShouldEqual(2);
        }
Exemple #15
0
        public async void Failed_Node_Run_Status_Is_Completed_With_Failed_Result()
        {
            var testNode = new FailingTestNodeA();

            var testObject = new TestObjectA();

            var context = new ExecutionContext <TestObjectA>(testObject);

            var result = await testNode.ExecuteAsync(context);

            testNode.Status.ShouldEqual(NodeRunStatus.Completed);
            result.Status.ShouldEqual(NodeResultStatus.Failed);
        }
Exemple #16
0
        public void Errant_Node_Run_With_ThrowOnError_True_Throws()
        {
            var testNode = new FaultingTestNodeA();

            var testObject = new TestObjectA();

            var context = new ExecutionContext <TestObjectA>(testObject)
            {
                GlobalOptions = { ThrowOnError = true }
            };

            Assert.Throws <Exception>(async() => await testNode.ExecuteAsync(context));
        }
Exemple #17
0
        public void Node_Specific_Options_Override_Global_Options()
        {
            var testNode = new SimpleTestNodeA1();

            var testObject = new TestObjectA();

            var context = new ExecutionContext <TestObjectA>(testObject);

            testNode.LocalOptions = new ExecutionOptions {
                ThrowOnError = true
            };

            testNode.GetEffectiveOptions(context.GlobalOptions).ThrowOnError.ShouldEqual(true);
        }
Exemple #18
0
        public async void Errant_Node_Run_Status_Is_Faulted()
        {
            var testNode = new FaultingTestNodeA();

            var testObject = new TestObjectA();

            var context = new ExecutionContext <TestObjectA>(testObject);

            var result = await testNode.ExecuteAsync(context);

            result.Exception.ShouldNotBeNull();

            testNode.Status.ShouldEqual(NodeRunStatus.Faulted);
        }
Exemple #19
0
        public async void Successful_FuncNode_Values_Match_Expected()
        {
            var node = new FuncNode <TestObjectA>();

            node.AddShouldExecute(context => Task.FromResult(context.Subject.TestValueInt == 0));
            node.ExecutedFunc = context => { context.Subject.TestValueString = "Completed"; return(Task.FromResult(NodeResultStatus.Succeeded)); };

            var        testObject = new TestObjectA();
            NodeResult result     = await node.ExecuteAsync(testObject);

            node.Status.ShouldEqual(NodeRunStatus.Completed);
            result.Status.ShouldEqual(NodeResultStatus.Succeeded);
            result.GetSubjectAs <TestObjectA>().TestValueString.ShouldEqual("Completed");
        }
Exemple #20
0
        public async void Node_Is_Not_Run_If_ShouldExecute_False()
        {
            var testNode = new SimpleTestNodeA1(false);

            var testObject = new TestObjectA();

            var context = new ExecutionContext <TestObjectA>(testObject);

            var result = await testNode.ExecuteAsync(context);

            result.Status.ShouldEqual(NodeResultStatus.NotRun);

            context.Subject.TestValueString.ShouldBeNull();
        }
        public async Task Node_With_ShouldExecuteBlock_Should_Run()
        {
            var node = new FuncNode <TestObjectA>();

            node.AddShouldExecuteBlock(new ShouldExecuteBlockA());
            node.ExecutedFunc = context => { context.Subject.TestValueString = "Completed"; return(Task.FromResult(NodeResultStatus.Succeeded)); };

            var        testObject = new TestObjectA();
            NodeResult result     = await node.ExecuteAsync(testObject);

            node.Status.Should().Be(NodeRunStatus.Completed);
            result.Status.Should().Be(NodeResultStatus.Succeeded);
            result.GetSubjectAs <TestObjectA>().TestValueString.Should().Be("Completed");
        }
Exemple #22
0
        public async Task Successful_Pipeline_Result_Matches_Expectations()
        {
            var pipelineNode = new PipelineNode <TestObjectA>();

            pipelineNode.AddChild(new SimpleTestNodeA1());
            pipelineNode.AddChild(new SimpleTestNodeA2());

            var        testObject = new TestObjectA();
            NodeResult result     = await pipelineNode.ExecuteAsync(testObject);

            result.Status.Should().Be(NodeResultStatus.Succeeded);
            testObject.TestValueString.Should().Be("Completed");
            testObject.TestValueInt.Should().Be(100);
        }
Exemple #23
0
        public async Task Node_May_Change_Context_Subject()
        {
            var testNode   = new SubjectChangingNode1();
            var testObject = new TestObjectA();
            var context    = new ExecutionContext <TestObjectA>(testObject);

            var result = await testNode.ExecuteAsync(context);

            result.Status.Should().Be(NodeResultStatus.Succeeded);

            result.Subject.Should().BeSameAs(context.Subject);
            result.Subject.Should().NotBeSameAs(testObject);
            result.GetSubjectAs <TestObjectA>().TestValueString.Should().Be("New Instance");
        }
Exemple #24
0
        public async void FuncNode_With_ShouldExecute_False_Shouldnt_Run()
        {
            var node = new FuncNode <TestObjectA>();

            node.AddShouldExecute(context => Task.FromResult(context.Subject.TestValueInt == 5));
            node.ExecutedFunc = context => { context.Subject.TestValueString = "Completed"; return(Task.FromResult(NodeResultStatus.Succeeded)); };

            var        testObject = new TestObjectA();
            NodeResult result     = await node.ExecuteAsync(testObject);

            node.Status.ShouldEqual(NodeRunStatus.NotRun);
            result.Status.ShouldEqual(NodeResultStatus.NotRun);
            result.GetSubjectAs <TestObjectA>().TestValueString.ShouldBeNull();
        }
        public async void Successful_Group_Result_Matches_Expectations()
        {
            var groupNode = new GroupNode <TestObjectA>();

            groupNode.AddChild(new SimpleTestNodeA1());
            groupNode.AddChild(new SimpleTestNodeA2());

            var        testObject = new TestObjectA();
            NodeResult result     = await groupNode.ExecuteAsync(testObject);

            result.Status.ShouldEqual(NodeResultStatus.Succeeded);
            testObject.TestValueString.ShouldEqual("Completed");
            testObject.TestValueInt.ShouldEqual(100);
        }
Exemple #26
0
        public async void Nested_Pipeline_Results_Contain_All_Child_Results()
        {
            var pipelineNode  = new PipelineNode <TestObjectA>();
            var pipelineNode2 = new PipelineNode <TestObjectA>();

            pipelineNode.AddChild(pipelineNode2);
            pipelineNode2.AddChild(new SimpleTestNodeA2());
            pipelineNode2.AddChild(new SimpleTestNodeA2());

            var        testObject = new TestObjectA();
            NodeResult result     = await pipelineNode.ExecuteAsync(testObject);

            result.ChildResults.Count().ShouldEqual(1);
            result.ChildResults.First().ChildResults.Count().ShouldEqual(2);
        }
Exemple #27
0
        public async Task Pipeline_Run_With_Initial_Failure_Returns_Failed_Status()
        {
            var pipelineNode = new PipelineNode <TestObjectA>();

            pipelineNode.AddChild(new FaultingTestNodeA());
            pipelineNode.AddChild(new SimpleTestNodeA1());

            var        testObject = new TestObjectA();
            NodeResult result     = await pipelineNode.ExecuteAsync(testObject);

            IEnumerable <Exception> exceptions = result.GetFailExceptions();

            exceptions.Should().NotBeNull();
            exceptions.Count().Should().Be(1);
        }
Exemple #28
0
        public async void Global_Options_Are_Reflected_In_Effective_Options()
        {
            var testNode = new SimpleTestNodeA1();

            var testObject = new TestObjectA();

            var context = new ExecutionContext <TestObjectA>(testObject)
            {
                GlobalOptions = { ThrowOnError = true }
            };

            var result = await testNode.ExecuteAsync(context);

            testNode.GetEffectiveOptions(context.GlobalOptions).ThrowOnError.ShouldEqual(true);
        }
Exemple #29
0
        public void Faulted_Node_Throws_If_Throw_On_Error_True()
        {
            var testNode = new FaultingTestNodeA();

            var testObject1 = new TestObjectA();
            var testObject2 = new TestObjectA();

            var testObjectList = new List <TestObjectA> {
                testObject1, testObject2
            };

            Assert.ThrowsAsync <AggregateException>(() => testNode.ExecuteManyAsync(testObjectList, new ExecutionOptions {
                ThrowOnError = true
            }));
        }
        public void Faulted_Sync_Node_Throws_If_Throw_On_Error_True()
        {
            var testNode = new FaultingTestNodeA();

            var testObject1 = new TestObjectA();
            var testObject2 = new TestObjectA();

            var testObjectList = new List <TestObjectA> {
                testObject1, testObject2
            };

            Assert.Throws <Exception>(async() => await testNode.ExecuteManySeriallyAsync(testObjectList, new ExecutionOptions {
                ThrowOnError = true
            }));
        }