Example #1
0
        public void PipelineBuilder_Build_Binds_By_Name()
        {
            MockPipelineBuilder     pb         = new MockPipelineBuilder();
            MockProcessor1          processor1 = new MockProcessor1();
            MockProcessorEchoString processor2 = new MockProcessorEchoString();

            // Rename processor inputs and outputs to bind by name to pipeline arguments and to each other:
            // pipeline[intInput] --> [intInput]p1[echoInput] --> [echoInput]p2[stringOutput] --> [stringOutput]pipeline
            processor1.InArguments[0].Name  = "intInput";
            processor2.InArguments[0].Name  = processor1.OutArguments[0].Name = "echoInput";
            processor2.OutArguments[0].Name = "stringOutput";

            Pipeline pipeline = pb.Build(
                new Processor[] { processor1, processor2 },
                new ProcessorArgument[] { new ProcessorArgument("intInput", typeof(int)) },
                new ProcessorArgument[] { new ProcessorArgument("stringOutput", typeof(string)) }
                );

            Assert.IsNotNull(pipeline, "Build should produce non-null pipeline");

            ProcessorArgument[] boundArgs = pipeline.GetBoundToArguments(pipeline.Processors[0].OutArguments[0]).ToArray();
            Assert.AreEqual(1, boundArgs.Length, "Expected 1 parameter bound to entry processor output");
            Assert.AreSame(processor1.InArguments[0], boundArgs[0], "Expected entry processor output to bind to processor 1 input");

            boundArgs = pipeline.GetBoundToArguments(pipeline.Processors[1].OutArguments[0]).ToArray();
            Assert.AreEqual(1, boundArgs.Length, "Expected 1 parameter bound to first processor output");
            Assert.AreSame(processor2.InArguments[0], boundArgs[0], "Expected first processor output to bind to second processor input");

            boundArgs = pipeline.GetBoundToArguments(pipeline.Processors[2].OutArguments[0]).ToArray();
            Assert.AreEqual(1, boundArgs.Length, "Expected 1 parameter bound to second processor output");
            Assert.AreSame(pipeline.Processors[3].InArguments[0], boundArgs[0], "Expected second processor output to bind to exit processor input");
        }
        public void Pipeline_BindArgumentToPipelineOutput_By_Name()
        {
            MockProcessor1 processor = new MockProcessor1();
            MockPipeline   pipeline  = new MockPipeline(
                new Processor[] { processor },
                Enumerable.Empty <ProcessorArgument>(),
                new ProcessorArgument[] { new ProcessorArgument("PipelineOutput", typeof(string)) });

            BindArgumentsEventArgs eventArgs      = null;
            ProcessorArgument      inArgFromBind  = null;
            ProcessorArgument      outArgFromBind = null;

            pipeline.OnBindArgumentsCalled = (outArg, inArg) =>
            {
                inArgFromBind  = inArg;
                outArgFromBind = outArg;
            };

            pipeline.BoundArguments = (s, a) => { eventArgs = a as BindArgumentsEventArgs; };
            pipeline.BindArgumentToPipelineOutput(processor.OutArguments[0], "PipelineOutput");
            Assert.IsNotNull(eventArgs, "Did not receive OnBoundArguments callback");
            Assert.AreSame(pipeline.Processors[1].OutArguments[0], outArgFromBind, "Did not receive correct outArg in OnBind virtual");
            Assert.AreSame(pipeline.Processors[2].InArguments[0], inArgFromBind, "Did not receive correct inArg in OnBind virtual");
            Assert.IsTrue(pipeline.GetBoundToArguments(pipeline.Processors[1].OutArguments[0]).Contains(pipeline.Processors[2].InArguments[0]),
                          "Failed to find exit processor in argument in bindings for processor 1");
        }
        public void Pipeline_Bind_OnBinding_OnBind_OnBound_Callbacks()
        {
            MockProcessor1          processor1 = new MockProcessor1();
            MockProcessorEchoString processor2 = new MockProcessorEchoString();
            MockPipeline            pipeline   = new MockPipeline(
                new Processor[] { processor1, processor2 },
                Enumerable.Empty <ProcessorArgument>(),
                Enumerable.Empty <ProcessorArgument>());
            BindArgumentsEventArgs bindingEventArgs = null;
            BindArgumentsEventArgs boundEventArgs   = null;
            ProcessorArgument      inArgFromBind    = null;
            ProcessorArgument      outArgFromBind   = null;

            pipeline.OnBindArgumentsCalled = (outArg, inArg) =>
            {
                inArgFromBind  = inArg;
                outArgFromBind = outArg;
            };

            pipeline.BindingArguments = (s, a) => { bindingEventArgs = a as BindArgumentsEventArgs; };
            pipeline.BoundArguments   = (s, a) => { boundEventArgs = a as BindArgumentsEventArgs; };

            pipeline.BindArguments(processor1.OutArguments[0], processor2.InArguments[0]);
            Assert.IsNotNull(bindingEventArgs, "Did not receive BindingArguments callback");
            Assert.AreSame(processor1.OutArguments[0], bindingEventArgs.OutArgument, "Did not receive correct outArg in BindingArgument callback");
            Assert.AreSame(processor2.InArguments[0], bindingEventArgs.InArgument, "Did not receive correct inArg in BindingArgument callback");

            Assert.IsNotNull(boundEventArgs, "Did not receive BoundArguments callback");
            Assert.AreSame(processor1.OutArguments[0], boundEventArgs.OutArgument, "Did not receive correct outArg in BoundArgument callback");
            Assert.AreSame(processor2.InArguments[0], boundEventArgs.InArgument, "Did not receive correct inArg in BoundArgument callback");

            Assert.AreSame(processor1.OutArguments[0], outArgFromBind, "Did not receive correct outArg in OnBind virtual");
            Assert.AreSame(processor2.InArguments[0], inArgFromBind, "Did not receive correct inArg in OnBind virtual");
        }
Example #4
0
        public void PipelineBuilder_Build_Binds_By_Name_And_Executes()
        {
            MockPipelineBuilder     pb         = new MockPipelineBuilder();
            MockProcessor1          processor1 = new MockProcessor1();
            MockProcessorEchoString processor2 = new MockProcessorEchoString();

            // Rename processor inputs and outputs to bind by name to pipeline arguments and to each other:
            // pipeline[intInput] --> [intInput]p1[echoInput] --> [echoInput]p2[stringOutput] --> [stringOutput]pipeline
            processor1.InArguments[0].Name  = "intInput";
            processor2.InArguments[0].Name  = processor1.OutArguments[0].Name = "echoInput";
            processor2.OutArguments[0].Name = "stringOutput";

            Pipeline pipeline = pb.Build(
                new Processor[] { processor1, processor2 },
                new ProcessorArgument[] { new ProcessorArgument("intInput", typeof(int)) },
                new ProcessorArgument[] { new ProcessorArgument("stringOutput", typeof(string)) }
                );

            Assert.IsNotNull(pipeline, "Build should produce non-null pipeline");

            ProcessorResult result = pipeline.Execute(new object[] { 9 });

            Assert.IsNotNull(result, "Null result from execute");
            Assert.AreEqual(ProcessorStatus.Ok, result.Status, "Expected OK result status");
            Assert.IsNotNull(result.Output, "Expected non-null output");
            Assert.AreEqual(1, result.Output.Length, "Expected 1 output value");
            Assert.AreEqual(9.ToString(), result.Output[0], "Wrong output value");
        }
Example #5
0
        public void PipelineBuilder_Build_Removes_Filtered_Processors()
        {
            MockPipelineBuilder pb         = new MockPipelineBuilder();
            MockProcessor1      processor1 = new MockProcessor1();
            ConditionalMockProcessorEchoString processor2 = new ConditionalMockProcessorEchoString()
            {
                WillExecute = true
            };
            ConditionalMockProcessorEchoString processor3 = new ConditionalMockProcessorEchoString()
            {
                WillExecute = false
            };

            // Rename processor inputs and outputs to bind by name to pipeline arguments and to each other:
            // pipeline[intInput] --> [intInput]p1[echoInput] --> [echoInput]p2[stringOutput] --> [stringOutput]pipeline
            // Also temporarily, have this before it gets yanked:
            //    pipeline[intInput] --> [intInput]p1[echoInput] --> [echoInput]p3[stringOutput2]
            processor1.InArguments[0].Name  = "intInput";
            processor3.InArguments[0].Name  = processor2.InArguments[0].Name = processor1.OutArguments[0].Name = "echoInput";
            processor2.OutArguments[0].Name = "stringOutput";
            processor3.OutArguments[0].Name = "stringOutput2";

            Pipeline pipeline = pb.Build(
                new Processor[] { processor1, processor2, processor3 },
                new ProcessorArgument[] { new ProcessorArgument("intInput", typeof(int)) },
                new ProcessorArgument[] { new ProcessorArgument("stringOutput", typeof(string)) }
                );

            Assert.IsNotNull(pipeline, "Build should produce non-null pipeline");
            Assert.AreEqual(4, pipeline.Processors.Count, "Should have filtered to 4 processors");
            Assert.IsFalse(pipeline.Processors.Contains(processor3), "Processor3 should have been filtered out");
        }
        public void Pipeline_BindArgumentToPipelineOutput_By_Bad_Name_Throws()
        {
            MockProcessor1 processor = new MockProcessor1();
            MockPipeline   pipeline  = new MockPipeline(
                new Processor[] { processor },
                Enumerable.Empty <ProcessorArgument>(),
                new ProcessorArgument[] { new ProcessorArgument("PipelineOutput", typeof(string)) });

            ExceptionAssert.Throws(
                typeof(ArgumentException),
                "BindArgumentToPipelineOutput should throw with null name",
                () => pipeline.BindArgumentToPipelineOutput(processor.OutArguments[0], null),
                "pipelineOutputArgumentName"
                );

            ExceptionAssert.Throws(
                typeof(ArgumentException),
                "BindArgumentToPipelineOutput should throw with empty name",
                () => pipeline.BindArgumentToPipelineOutput(processor.OutArguments[0], string.Empty),
                "pipelineOutputArgumentName"
                );

            ExceptionAssert.Throws(
                typeof(ArgumentException),
                "BindArgumentToPipelineOutput should throw with whitespace name",
                () => pipeline.BindArgumentToPipelineOutput(processor.OutArguments[0], "   "),
                "pipelineOutputArgumentName"
                );

            ExceptionAssert.ThrowsInvalidOperation(
                "BindArgumentToPipelineInput should throw with non-existent name",
                () => pipeline.BindArgumentToPipelineOutput(processor.OutArguments[0], "NotAName")
                );
        }
        public void Pipeline_UnbindArgument_Succeeds()
        {
            MockProcessor1          processor1 = new MockProcessor1();
            MockProcessorEchoString processor2 = new MockProcessorEchoString();
            Pipeline pipeline = new Pipeline(
                new Processor[] { processor1, processor2 },
                Enumerable.Empty <ProcessorArgument>(),
                Enumerable.Empty <ProcessorArgument>());

            pipeline.BindArguments(processor1.OutArguments[0], processor2.InArguments[0]);
            Assert.IsTrue(
                pipeline.GetBoundToArguments(processor1.OutArguments[0]).Contains(processor2.InArguments[0]),
                "Expected GetBoundTo(out) to show we bound out to in");
            Assert.IsTrue(
                pipeline.GetBoundToArguments(processor2.InArguments[0]).Contains(processor1.OutArguments[0]),
                "Expected GetBoundTo(in) to show we bound out to in");

            pipeline.UnbindArguments(processor1.OutArguments[0], processor2.InArguments[0]);

            Assert.IsFalse(
                pipeline.GetBoundToArguments(processor1.OutArguments[0]).Contains(processor2.InArguments[0]),
                "Expected GetBoundTo(out) to show we unbound out to in");
            Assert.IsFalse(
                pipeline.GetBoundToArguments(processor2.InArguments[0]).Contains(processor1.OutArguments[0]),
                "Expected GetBoundTo(in) to show we unbound out to in");
        }
        public void Pipeline_BindArgumentToPipelineInput_By_Index()
        {
            MockProcessor1 processor = new MockProcessor1();
            MockPipeline pipeline = new MockPipeline(
                new Processor[] { processor },
                new ProcessorArgument[] { new ProcessorArgument("PipelineInput", typeof(int)) },
                Enumerable.Empty<ProcessorArgument>());

            BindArgumentsEventArgs eventArgs = null;
            ProcessorArgument inArgFromBind = null;
            ProcessorArgument outArgFromBind = null;

            pipeline.OnBindArgumentsCalled = (outArg, inArg) =>
                {
                    inArgFromBind = inArg;
                    outArgFromBind = outArg;
                };

            pipeline.BoundArguments = (s, a) => { eventArgs = a as BindArgumentsEventArgs; };
            pipeline.BindArgumentToPipelineInput(0, processor.InArguments[0]);
            Assert.IsNotNull(eventArgs, "Did not receive OnBoundArguments callback");
            Assert.AreSame(pipeline.Processors[0].OutArguments[0], outArgFromBind, "Did not receive correct outArg in OnBind virtual");
            Assert.AreSame(pipeline.Processors[1].InArguments[0], inArgFromBind, "Did not receive correct inArg in OnBind virtual");
            Assert.IsTrue(pipeline.GetBoundToArguments(pipeline.Processors[0].OutArguments[0]).Contains(processor.InArguments[0]),
                            "Failed to find processor 1's in argument in bindings for entry processor");
        }
 public void PipelineContext_Ctor_Internal_Null_ContextInfo_Creates()
 {
     Processor processor = new MockProcessor1();
     Pipeline pipeline = new Pipeline(new[] { processor }, Enumerable.Empty<ProcessorArgument>(), Enumerable.Empty<ProcessorArgument>());
     PipelineContext context = new PipelineContext(pipeline, null);
     Assert.IsNotNull(context.ContextInfo, "Null contextInfo to ctor should have created one");
 }
        /// <summary>
        /// This pipeline has 2 MockProcessor1's in it, both binding their inputs to the pipeline's 'intValue'.
        /// The pipeline has 2 outputs, one bound to each processor's.
        /// </summary>
        /// <returns></returns>
        public static MockPipeline CreateDoubleMockProcessor1Pipeline()
        {
            Processor processor1 = new MockProcessor1();
            Processor processor2 = new MockProcessor1();
            MockPipeline pipeline = new MockPipeline(
                                    new[] { processor1, processor2 },
                                    new[] { new ProcessorArgument("intValue", typeof(int), new object[0]) },
                                    new[] { new ProcessorArgument("theResult1", typeof(string), new object[0]),
                                            new ProcessorArgument("theResult2", typeof(string), new object[0])}
                                    );

            // Pipeline["intValue"] --> Processor1[0]
            pipeline.BindArgumentToPipelineInput("intValue", processor1.InArguments[0]);

            // Pipeline["intValue"] --> Processor2[0]
            pipeline.BindArgumentToPipelineInput("intValue", processor2.InArguments[0]);

            // Processor1[0] --> Pipeline["theResult1"]
            pipeline.BindArgumentToPipelineOutput(processor1.OutArguments[0], "theResult1");

            // Processor2[0] --> Pipeline["theResult2"]
            pipeline.BindArgumentToPipelineOutput(processor2.OutArguments[0], "theResult2");
            pipeline.Initialize();
            return pipeline;
        }
        /// <summary>
        /// This pipeline has 2 MockProcessor1's in it, both binding their inputs to the pipeline's 'intValue'.
        /// The pipeline has 2 outputs, one bound to each processor's.
        /// </summary>
        /// <returns></returns>
        public static MockPipeline CreateDoubleMockProcessor1Pipeline()
        {
            Processor    processor1 = new MockProcessor1();
            Processor    processor2 = new MockProcessor1();
            MockPipeline pipeline   = new MockPipeline(
                new[] { processor1, processor2 },
                new[] { new ProcessorArgument("intValue", typeof(int), new object[0]) },
                new[] { new ProcessorArgument("theResult1", typeof(string), new object[0]),
                        new ProcessorArgument("theResult2", typeof(string), new object[0]) }
                );

            // Pipeline["intValue"] --> Processor1[0]
            pipeline.BindArgumentToPipelineInput("intValue", processor1.InArguments[0]);

            // Pipeline["intValue"] --> Processor2[0]
            pipeline.BindArgumentToPipelineInput("intValue", processor2.InArguments[0]);

            // Processor1[0] --> Pipeline["theResult1"]
            pipeline.BindArgumentToPipelineOutput(processor1.OutArguments[0], "theResult1");

            // Processor2[0] --> Pipeline["theResult2"]
            pipeline.BindArgumentToPipelineOutput(processor2.OutArguments[0], "theResult2");
            pipeline.Initialize();
            return(pipeline);
        }
        public void Pipeline_BindArgumentToPipelineInput_By_Bad_Name_Throws()
        {
            MockProcessor1 processor = new MockProcessor1();
            MockPipeline pipeline = new MockPipeline(
                new Processor[] { processor },
                new ProcessorArgument[] { new ProcessorArgument("PipelineInput", typeof(int)) },
                Enumerable.Empty<ProcessorArgument>());

            ExceptionAssert.Throws(
                typeof(ArgumentException),
                "BindArgumentToPipelineInput should throw with null name",
                () => pipeline.BindArgumentToPipelineInput(null, processor.InArguments[0]),
                "pipelineInputArgumentName"
                );

            ExceptionAssert.Throws(
                typeof(ArgumentException),
                "BindArgumentToPipelineInput should throw with empty name",
                () => pipeline.BindArgumentToPipelineInput(string.Empty, processor.InArguments[0]),
                "pipelineInputArgumentName"
                );

            ExceptionAssert.Throws(
                typeof(ArgumentException),
                "BindArgumentToPipelineInput should throw with whitespace name",
                () => pipeline.BindArgumentToPipelineInput("   ", processor.InArguments[0]),
                "pipelineInputArgumentName"
                );

            ExceptionAssert.ThrowsInvalidOperation(
                "BindArgumentToPipelineInput should throw with non-existent name",
                () => pipeline.BindArgumentToPipelineInput("NotAName", processor.InArguments[0])
                );
        }
        public void PipelineContext_Ctor_Internal_Null_ContextInfo_Creates()
        {
            Processor       processor = new MockProcessor1();
            Pipeline        pipeline  = new Pipeline(new[] { processor }, Enumerable.Empty <ProcessorArgument>(), Enumerable.Empty <ProcessorArgument>());
            PipelineContext context   = new PipelineContext(pipeline, null);

            Assert.IsNotNull(context.ContextInfo, "Null contextInfo to ctor should have created one");
        }
 public void PipelineContext_Ctor_Internal_Accepts_ContextInfo()
 {
     Processor processor = new MockProcessor1();
     Pipeline pipeline = new Pipeline(new[] { processor }, Enumerable.Empty<ProcessorArgument>(), Enumerable.Empty<ProcessorArgument>());
     PipelineContextInfo info = new PipelineContextInfo(pipeline);
     PipelineContext context = new PipelineContext(pipeline, info);
     Assert.AreSame(info, context.ContextInfo, "Ctor should have used the ContextInfo we passed int.");
 }
        public void PipelineContext_Ctor_Internal_Accepts_ContextInfo()
        {
            Processor           processor = new MockProcessor1();
            Pipeline            pipeline  = new Pipeline(new[] { processor }, Enumerable.Empty <ProcessorArgument>(), Enumerable.Empty <ProcessorArgument>());
            PipelineContextInfo info      = new PipelineContextInfo(pipeline);
            PipelineContext     context   = new PipelineContext(pipeline, info);

            Assert.AreSame(info, context.ContextInfo, "Ctor should have used the ContextInfo we passed int.");
        }
        public void PipelineContext_Ctor_Internal_Reuses_Pipeline_ContextInfo()
        {
            Processor processor = new MockProcessor1();
            Pipeline pipeline = new Pipeline(new[] { processor }, Enumerable.Empty<ProcessorArgument>(), Enumerable.Empty<ProcessorArgument>());
            PipelineContext context1 = new PipelineContext(pipeline);
            Assert.IsNotNull(context1.ContextInfo, "ContextInfo should have been created");

            PipelineContext context2 = new PipelineContext(pipeline);
            Assert.AreSame(context1.ContextInfo, context2.ContextInfo, "Expected 2nd context to reuse same ContextInfo");
        }
Example #17
0
        public void PipelineBuilder_OnGetRelativeExecutionOrder_Virtual_IsCalled()
        {
            Processor processor1 = new MockProcessor1();
            Processor processor2 = new MockProcessorEchoString();
            Processor processor3 = new MockProcessorNoArgs();

            Processor[]         processors = new Processor[] { processor1, processor2, processor3 };
            ProcessorArgument[] inArgs     = new[] { new ProcessorArgument("intValue", typeof(int)) };
            ProcessorArgument[] outArgs    = new ProcessorArgument[0];

            // Bind input of echo processor to mock proc 1
            processor2.InArguments[0].Name = processor1.OutArguments[0].Name;

            bool firstOrderSet  = false;
            bool secondOrderSet = false;
            bool thirdOrderSet  = false;
            ProcessorExecutionOrder firstOrder  = default(ProcessorExecutionOrder);
            ProcessorExecutionOrder secondOrder = default(ProcessorExecutionOrder);
            ProcessorExecutionOrder thirdOrder  = default(ProcessorExecutionOrder);

            // Get a new pipeline because the prior one is now in a damaged state
            MockPipelineBuilder pb = new MockPipelineBuilder();

            pb.OnGetRelativeExecutionOrderCalled = (p1, p2, order) =>
            {
                if (p1 == processors[0] && p2 == processors[1])
                {
                    firstOrder    = order;
                    firstOrderSet = true;
                }

                if (p1 == processors[1] && p2 == processors[0])
                {
                    secondOrder    = order;
                    secondOrderSet = true;
                }

                if (p1 == processors[2] && p2 == processors[0])
                {
                    thirdOrder    = order;
                    thirdOrderSet = true;
                }
                return(order);
            };

            Pipeline pipeline = pb.Build(processors, inArgs, outArgs);

            Assert.IsTrue(firstOrderSet, "OnGetRelativeExecutionOrder virtual was not called for (p1,p2)");
            Assert.IsTrue(secondOrderSet, "OnGetRelativeExecutionOrder virtual was not called for (p2,p1)");
            Assert.IsTrue(thirdOrderSet, "OnGetRelativeExecutionOrder virtual was not called for (p3,p1)");

            Assert.AreEqual(ProcessorExecutionOrder.Before, firstOrder, "The (p1,p2) call should have yielded 'before'");
            Assert.AreEqual(ProcessorExecutionOrder.After, secondOrder, "The (p2, p1) call should have yielded 'after'");
            Assert.AreEqual(ProcessorExecutionOrder.Impartial, thirdOrder, "The (p3, p1) call should have yielded 'impartial'");
        }
        public void Pipeline_Ctor_Throws_Null_OutArguments()
        {
            Processor processor = new MockProcessor1();
            Pipeline  p;

            ExceptionAssert.ThrowsArgumentNull(
                "Pipeline ctor should throw if processor collection is null",
                "outArguments",
                () => p = new Pipeline(new[] { processor }, Enumerable.Empty <ProcessorArgument>(), null)
                );
        }
        public void PipelineContext_Ctor_Internal_Reuses_Pipeline_ContextInfo()
        {
            Processor       processor = new MockProcessor1();
            Pipeline        pipeline  = new Pipeline(new[] { processor }, Enumerable.Empty <ProcessorArgument>(), Enumerable.Empty <ProcessorArgument>());
            PipelineContext context1  = new PipelineContext(pipeline);

            Assert.IsNotNull(context1.ContextInfo, "ContextInfo should have been created");

            PipelineContext context2 = new PipelineContext(pipeline);

            Assert.AreSame(context1.ContextInfo, context2.ContextInfo, "Expected 2nd context to reuse same ContextInfo");
        }
        /// <summary>
        /// Creates an uninitialized Pipeline with a single MockProcessor1 in it, binding its inputs to the pipeline inputs
        /// and its outputs to the pipeline outputs.
        /// </summary>
        /// <returns></returns>
        public static MockPipeline CreateMockProcessor1PipelineUninitialized()
        {
            Processor    processor = new MockProcessor1();
            MockPipeline pipeline  = new MockPipeline(
                new[] { processor },
                new[] { new ProcessorArgument("intValue", typeof(int), new object[0]) },
                new[] { new ProcessorArgument("theResult", typeof(string), new object[0]) }
                );

            pipeline.BindArgumentToPipelineInput("intValue", processor.InArguments[0]);
            pipeline.BindArgumentToPipelineOutput(processor.OutArguments[0], "theResult");
            return(pipeline);
        }
        /// <summary>
        /// Creates an uninitialized Pipeline with a single MockProcessor1 in it, binding its inputs to the pipeline inputs
        /// and its outputs to the pipeline outputs.
        /// </summary>
        /// <returns></returns>
        public static MockPipeline CreateMockProcessor1PipelineUninitialized()
        {
            Processor processor = new MockProcessor1();
            MockPipeline pipeline = new MockPipeline(
                                    new[] { processor },
                                    new[] { new ProcessorArgument("intValue", typeof(int), new object[0]) },
                                    new[] { new ProcessorArgument("theResult", typeof(string), new object[0]) }
                                    );

            pipeline.BindArgumentToPipelineInput("intValue", processor.InArguments[0]);
            pipeline.BindArgumentToPipelineOutput(processor.OutArguments[0], "theResult");
            return pipeline;
        }
        public void PipelineContext_ReadAllInputs_Throws_If_Processor_Not_In_Pipeline()
        {
            Processor       processor = new MockProcessor1();
            MockPipeline    pipeline  = TestPipelines.CreateMockProcessor1Pipeline();
            PipelineContext context   = new PipelineContext(pipeline);

            ExceptionAssert.Throws(
                typeof(ArgumentException),
                "PipelineContext should throw if processor from different pipeline specified",
                () => context.ReadAllInputs(processor),
                "processor"
                );
        }
        public void PipelineContext_WriteInput_Throws_If_External_ProcessorArgument()
        {
            Processor       processor = new MockProcessor1();
            MockPipeline    pipeline  = TestPipelines.CreateMockProcessor1Pipeline();
            PipelineContext context   = new PipelineContext(pipeline);

            ExceptionAssert.Throws(
                typeof(ArgumentException),
                "PipelineContext should throw if processor argument belongs to different pipeline",
                () => context.WriteInput(processor.InArguments[0], new object()),
                "inArgument"
                );
        }
        public void Pipeline_BindArgument_Throws_Null_InArg()
        {
            MockProcessor1 processor = new MockProcessor1();
            Pipeline       pipeline  = new Pipeline(
                new Processor[] { processor },
                Enumerable.Empty <ProcessorArgument>(),
                Enumerable.Empty <ProcessorArgument>());

            ExceptionAssert.ThrowsArgumentNull(
                "BindArgument with null in should throw",
                "inArgument",
                () => pipeline.BindArguments(processor.OutArguments[0], null)
                );
        }
        public void Pipeline_UnbindArgument_Throws_Null_OutArg()
        {
            MockProcessor1 processor = new MockProcessor1();
            Pipeline       pipeline  = new Pipeline(
                new Processor[] { processor },
                Enumerable.Empty <ProcessorArgument>(),
                Enumerable.Empty <ProcessorArgument>());

            ExceptionAssert.ThrowsArgumentNull(
                "UnbindArgument with null out should throw",
                "outArgument",
                () => pipeline.UnbindArguments(null, processor.InArguments[0])
                );
        }
        public void Pipeline_Processor_Belongs_To_Only_1_Pipeline()
        {
            Processor processor = new MockProcessor1();
            Pipeline  pipeline1 = new Pipeline(new[] { processor }, Enumerable.Empty <ProcessorArgument>(), Enumerable.Empty <ProcessorArgument>());

            Assert.AreEqual(pipeline1, processor.ContainingCollection.ContainerProcessor, "Processor.Pipeline must be the pipeline we created");

            Pipeline pipeline2;

            ExceptionAssert.ThrowsInvalidOperation(
                "Adding a processor to a 2nd pipeline should throw",
                () => pipeline2 = new Pipeline(new[] { processor }, Enumerable.Empty <ProcessorArgument>(), Enumerable.Empty <ProcessorArgument>())
                );
        }
        public void Pipeline_GetBoundToArguments_Throws_Null_Parameer()
        {
            MockProcessor1 processor = new MockProcessor1();
            Pipeline       pipeline  = new Pipeline(
                Enumerable.Empty <Processor>(),
                Enumerable.Empty <ProcessorArgument>(),
                Enumerable.Empty <ProcessorArgument>());

            ExceptionAssert.ThrowsArgumentNull(
                "GetBoundToArguments should throw for null parameter",
                "argument",
                () => pipeline.GetBoundToArguments(null)
                );
        }
        public void Pipeline_UnbindArgument_Throws_After_Initialize()
        {
            MockProcessor1          processor1 = new MockProcessor1();
            MockProcessorEchoString processor2 = new MockProcessorEchoString();
            Pipeline pipeline = new Pipeline(
                new Processor[] { processor1, processor2 },
                Enumerable.Empty <ProcessorArgument>(),
                Enumerable.Empty <ProcessorArgument>());

            pipeline.Initialize();

            ExceptionAssert.ThrowsInvalidOperation(
                "UnbindArgument should throw if called after initialize",
                () => pipeline.UnbindArguments(processor1.OutArguments[0], processor2.InArguments[0])
                );
        }
Example #29
0
        public void Pipeline_Executes_With_No_Bindings()
        {
            MockProcessor1          processor1 = new MockProcessor1();
            MockProcessorEchoString processor2 = new MockProcessorEchoString();
            MockPipeline            pipeline   = new MockPipeline(
                new Processor[] { processor1, processor2 },
                Enumerable.Empty <ProcessorArgument>(),
                Enumerable.Empty <ProcessorArgument>());

            pipeline.Initialize();
            ProcessorResult result = pipeline.Execute(new object[0]);

            Assert.IsNotNull(result, "Expected non-null ProcessorResult");
            Assert.IsNotNull(result.Output, "Expected non-null output from unbound pipeline");
            Assert.AreEqual(0, result.Output.Length, "Expected empty array from unbound pipeline");
            Assert.AreEqual(ProcessorStatus.Ok, result.Status, "Expected OK status from pipeline");
        }
Example #30
0
        public void PipelineBuilder_Build_Orders_Processors()
        {
            MockPipelineBuilder pb         = new MockPipelineBuilder();
            MockProcessor1      processor1 = new MockProcessor1()
            {
                Name = "Processor1"
            };
            OrderableMockProcessorEchoString processor2 = new OrderableMockProcessorEchoString()
            {
                Name = "Processor2"
            };
            OrderableMockProcessorEchoString processor3 = new OrderableMockProcessorEchoString()
            {
                Name = "Processor3"
            };

            // Only P2 provides an answer -- all the rest must adjust to that
            processor2.RunAfter = processor3;

            // Rename processor inputs and outputs to bind by name to pipeline arguments and to each other:
            // pipeline[intInput] --> [intInput]p1[echoInput] --> [echoInput]p2[stringOutput] --> [stringOutput]pipeline
            //                        [intInput]p1[echoInput] --> [echoInput]p3[stringOutput2]
            processor1.InArguments[0].Name  = "intInput";
            processor3.InArguments[0].Name  = processor2.InArguments[0].Name = processor1.OutArguments[0].Name = "echoInput";
            processor2.OutArguments[0].Name = "stringOutput";
            processor3.OutArguments[0].Name = "stringOutput2";

            Pipeline pipeline = pb.Build(
                new Processor[] { processor1, processor2, processor3 },
                new ProcessorArgument[] { new ProcessorArgument("intInput", typeof(int)) },
                new ProcessorArgument[] { new ProcessorArgument("stringOutput", typeof(string)) }
                );

            Assert.IsNotNull(pipeline, "Build should produce non-null pipeline");
            Assert.AreEqual(5, pipeline.Processors.Count, "Should have 5 processors");
            int index2 = pipeline.Processors.IndexOf(processor2);
            int index3 = pipeline.Processors.IndexOf(processor3);

            Assert.IsTrue(index2 > index3, "Processor2 should have been ordered after processor3");
        }
        public void Pipeline_BindArgumentToPipelineInput_By_Bad_Index_Throws()
        {
            MockProcessor1 processor = new MockProcessor1();
            MockPipeline pipeline = new MockPipeline(
                new Processor[] { processor },
                new ProcessorArgument[] { new ProcessorArgument("PipelineInput", typeof(int)) },
                Enumerable.Empty<ProcessorArgument>());

            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "BindArgumentToPipelineInput should throw with negative index",
                () => pipeline.BindArgumentToPipelineInput(-1, processor.InArguments[0]),
                "pipelineInputArgumentIndex"
                );

            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "BindArgumentToPipelineInput should throw with too large an index",
                () => pipeline.BindArgumentToPipelineInput(1, processor.InArguments[0]),
                "pipelineInputArgumentIndex"
                );
        }
        public void Processor_Fires_Initialized_Events_On_Initialize()
        {
            Processor mock = new MockProcessor1();

            bool      initializedCalled    = false;
            object    initializedObject    = null;
            EventArgs initializedEventArgs = null;

            mock.Initialized = new EventHandler(
                (obj, eArgs) =>
            {
                initializedCalled    = true;
                initializedObject    = obj;
                initializedEventArgs = eArgs;
            });

            mock.Initialize();

            Assert.IsTrue(initializedCalled, "The Initialized event should have fired.");
            Assert.AreSame(mock, initializedObject, "The event sender should have been the processor itself.");
            Assert.AreSame(EventArgs.Empty, initializedEventArgs, "The event args should have been the EventArgs.Empty instance.");
        }
        public void Pipeline_BindArgumentToPipelineOutput_By_Bad_Index_Throws()
        {
            MockProcessor1 processor = new MockProcessor1();
            MockPipeline   pipeline  = new MockPipeline(
                new Processor[] { processor },
                Enumerable.Empty <ProcessorArgument>(),
                new ProcessorArgument[] { new ProcessorArgument("PipelineOutput", typeof(string)) });

            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "BindArgumentToPipelineOutput should throw with negative index",
                () => pipeline.BindArgumentToPipelineOutput(processor.OutArguments[0], -1),
                "pipelineOutputArgumentIndex"
                );

            ExceptionAssert.Throws(
                typeof(ArgumentOutOfRangeException),
                "BindArgumentToPipelineOutput should throw with too large an index",
                () => pipeline.BindArgumentToPipelineOutput(processor.OutArguments[0], 1),
                "pipelineOutputArgumentIndex"
                );
        }
Example #34
0
        public void Pipeline_Executes_With_No_Bindings_To_Pipeline()
        {
            MockProcessor1          processor1 = new MockProcessor1();
            MockProcessorEchoString processor2 = new MockProcessorEchoString();
            MockPipeline            pipeline   = new MockPipeline(
                new Processor[] { processor1, processor2 },
                Enumerable.Empty <ProcessorArgument>(),
                Enumerable.Empty <ProcessorArgument>());

            pipeline.BindArguments(processor1.OutArguments[0], processor2.InArguments[0]);
            pipeline.Initialize();
            ProcessorResult result = pipeline.Execute(new object[0]);

            Assert.IsNotNull(result, "Expected non-null ProcessorResult");
            Assert.IsNotNull(result.Output, "Expected non-null output from unbound pipeline");
            Assert.AreEqual(0, result.Output.Length, "Expected empty array from unbound pipeline");

            // Verify processor1 pushed default(int) through to processor2
            object value = pipeline.Context.ReadInput(processor2.InArguments[0]);

            Assert.IsNotNull(value);
            Assert.AreEqual(default(int).ToString(), value, "Expected default(int) to be passed from processor1 to processor2");
        }
Example #35
0
        public void PipelineBuilder_Validate_Throws_Input_Before_Output()
        {
            MockPipelineBuilder     pb         = new MockPipelineBuilder();
            MockProcessor1          processor1 = new MockProcessor1();
            MockProcessorEchoString processor2 = new MockProcessorEchoString();

            // Rename processor inputs and outputs to bind by name to pipeline arguments and to each other:
            // pipeline[intInput] --> [intInput]p1[echoInput] --> [echoInput]p2[stringOutput] --> [stringOutput]pipeline
            processor1.InArguments[0].Name  = "intInput";
            processor2.InArguments[0].Name  = processor1.OutArguments[0].Name = "echoInput";
            processor2.OutArguments[0].Name = "stringOutput";

            // Defeat normal ordering
            pb.OnOrderCalled = p => p;

            ExceptionAssert.ThrowsInvalidOperation(
                "PipelineBuilder should throw when required input occurs before output",
                () => pb.Build(
                    new Processor[] { processor2, processor1 }, // <<<<<<<<< notice the order is flipped
                    new ProcessorArgument[] { new ProcessorArgument("intInput", typeof(int)) },
                    new ProcessorArgument[] { new ProcessorArgument("stringOutput", typeof(string)) }
                    )
                );
        }
        public void Pipeline_UnbindArgument_Throws_After_Initialize()
        {
            MockProcessor1 processor1 = new MockProcessor1();
            MockProcessorEchoString processor2 = new MockProcessorEchoString();
            Pipeline pipeline = new Pipeline(
                new Processor[] { processor1, processor2 },
                Enumerable.Empty<ProcessorArgument>(),
                Enumerable.Empty<ProcessorArgument>());

            pipeline.Initialize();

            ExceptionAssert.ThrowsInvalidOperation(
                "UnbindArgument should throw if called after initialize",
                () => pipeline.UnbindArguments(processor1.OutArguments[0], processor2.InArguments[0])
                );
        }
        public void Pipeline_UnbindArgument_Throws_Null_OutArg()
        {
            MockProcessor1 processor = new MockProcessor1();
            Pipeline pipeline = new Pipeline(
                new Processor[] { processor },
                Enumerable.Empty<ProcessorArgument>(),
                Enumerable.Empty<ProcessorArgument>());

            ExceptionAssert.ThrowsArgumentNull(
                "UnbindArgument with null out should throw",
                "outArgument",
                () => pipeline.UnbindArguments(null, processor.InArguments[0])
                );
        }
Example #38
0
        public void PipelineBuilder_Build_Invokes_All_Virtuals()
        {
            MockPipelineBuilder pb      = new MockPipelineBuilder();
            bool onOrderCalled          = false;
            bool onFilterCalled         = false;
            bool onCreatePipelineCalled = false;
            bool onInitializeCalled     = false;
            bool onValidateCalled       = false;
            bool onShouldBindCalled     = false;

            MockProcessor1          processor1 = new MockProcessor1();
            MockProcessorEchoString processor2 = new MockProcessorEchoString();

            pb.OnFilterCalled = p =>
            {
                onFilterCalled = true;
                Assert.IsFalse(onOrderCalled || onInitializeCalled || onCreatePipelineCalled || onValidateCalled || onShouldBindCalled,
                               "OnFilter should be called before OnOrder, OnInitialize, OnCreatePipeline, OnValidate, and OnShouldBind");
                return(p);
            };

            pb.OnOrderCalled = p =>
            {
                onOrderCalled = true;
                Assert.IsTrue(onFilterCalled, "OnOrder should be called after OnFilter");
                Assert.IsFalse(onInitializeCalled || onCreatePipelineCalled || onValidateCalled || onShouldBindCalled,
                               "OnOrder should be called before OnInitialize, OnCreatePipeline, OnValidate, and OnShouldBind");
                return(p);
            };

            pb.OnCreatePipelineCalled = (p, aIn, aOut) =>
            {
                onCreatePipelineCalled = true;
                Assert.IsTrue(onFilterCalled && onOrderCalled, "OnCreatePipeline should be called after OnFilter and OnOrder");
                Assert.IsFalse(onInitializeCalled || onValidateCalled || onShouldBindCalled,
                               "OnCreatePipeline should be called before OnInitialize, OnValidate, and OnShouldBind");
                return(new Pipeline(p, aIn, aOut));
            };

            pb.OnInitializeCalled = p =>
            {
                onInitializeCalled = true;
                Assert.IsNotNull(p, "Oninitialize passed null pipeline");
                Assert.IsTrue(onFilterCalled && onOrderCalled && onCreatePipelineCalled, "OnInitialize should be called after OnFilter, OnCreatePipeline and OnOrder");
                Assert.IsFalse(onValidateCalled || onShouldBindCalled,
                               "OnInitialize should be called before OnValidate and OnShouldBind");
                return(p);
            };

            pb.OnShouldArgumentBindCalled = (aOut, aIn) =>
            {
                onShouldBindCalled = true;
                Assert.IsTrue(onFilterCalled && onOrderCalled && onInitializeCalled && onCreatePipelineCalled, "OnInitialize should be called after OnFilter, OnCreatePipeline, OnOrder and OnInitialize");
                Assert.IsFalse(onValidateCalled, "OnShouldArgmentBind should be called before OnValidate");
                return(null);
            };

            pb.OnValidateCalled = p =>
            {
                Assert.IsTrue(onFilterCalled && onOrderCalled && onInitializeCalled && onShouldBindCalled && onCreatePipelineCalled,
                              "OnInitialize should be called after OnFilter, OnOrder, OnInitialize, OnCreatePipeline and OnShouldBind");
                onValidateCalled = true;
                return(true);    // call base.validate
            };

            // Rename processor inputs and outputs to bind by name to pipeline arguments and to each other:
            // pipeline[intInput] --> [intInput]p1[echoInput] --> [echoInput]p2[stringOutput] --> [stringOutput]pipeline
            processor1.InArguments[0].Name  = "intInput";       // same as pipeline input
            processor2.InArguments[0].Name  = processor1.OutArguments[0].Name = "echoInput";
            processor2.OutArguments[0].Name = "stringOutput";   // same as pipeline output

            Pipeline pipeline = pb.Build(
                new Processor[] { processor1, processor2 },
                new ProcessorArgument[] { new ProcessorArgument("intInput", typeof(int)) },
                new ProcessorArgument[] { new ProcessorArgument("stringOutput", typeof(string)) }
                );

            Assert.IsNotNull(pipeline, "Build should produce non-null pipeline");

            Assert.IsTrue(onFilterCalled, "OnFilter was not called");
            Assert.IsTrue(onOrderCalled, "OnOrder was not called");
            Assert.IsTrue(onInitializeCalled, "OnInitialize was not called");
            Assert.IsTrue(onShouldBindCalled, "OnShouldBind was not called");
            Assert.IsTrue(onValidateCalled, "OnValidate was not called");
        }
        public void Pipeline_GetBoundToArguments_Throws_Null_Parameer()
        {
            MockProcessor1 processor = new MockProcessor1();
            Pipeline pipeline = new Pipeline(
                Enumerable.Empty <Processor>(),
                Enumerable.Empty<ProcessorArgument>(),
                Enumerable.Empty<ProcessorArgument>());

            ExceptionAssert.ThrowsArgumentNull(
                "GetBoundToArguments should throw for null parameter",
                "argument",
                () => pipeline.GetBoundToArguments(null)
                );
        }
 public void Pipeline_Ctor_Throws_Null_OutArguments()
 {
     Processor processor = new MockProcessor1();
     Pipeline p;
     ExceptionAssert.ThrowsArgumentNull(
         "Pipeline ctor should throw if processor collection is null",
         "outArguments",
         () => p = new Pipeline(new[] { processor }, Enumerable.Empty<ProcessorArgument>(), null)
         );
 }
        public void Pipeline_Executes_With_No_Bindings_To_Pipeline()
        {
            MockProcessor1 processor1 = new MockProcessor1();
            MockProcessorEchoString processor2 = new MockProcessorEchoString();
            MockPipeline pipeline = new MockPipeline(
                                        new Processor[] { processor1, processor2 },
                                        Enumerable.Empty<ProcessorArgument>(),
                                        Enumerable.Empty<ProcessorArgument>());
            pipeline.BindArguments(processor1.OutArguments[0], processor2.InArguments[0]);
            pipeline.Initialize();
            ProcessorResult result = pipeline.Execute(new object[0]);
            Assert.IsNotNull(result, "Expected non-null ProcessorResult");
            Assert.IsNotNull(result.Output, "Expected non-null output from unbound pipeline");
            Assert.AreEqual(0, result.Output.Length, "Expected empty array from unbound pipeline");

            // Verify processor1 pushed default(int) through to processor2
            object value = pipeline.Context.ReadInput(processor2.InArguments[0]);
            Assert.IsNotNull(value);
            Assert.AreEqual(default(int).ToString(), value, "Expected default(int) to be passed from processor1 to processor2");
        }
        public void Pipeline_BindArgument_Throws_Null_InArg()
        {
            MockProcessor1 processor = new MockProcessor1();
            Pipeline pipeline = new Pipeline(
                new Processor[] { processor },
                Enumerable.Empty<ProcessorArgument>(),
                Enumerable.Empty<ProcessorArgument>());

            ExceptionAssert.ThrowsArgumentNull(
                "BindArgument with null in should throw",
                "inArgument",
                () => pipeline.BindArguments(processor.OutArguments[0], null)
                );
        }
 public void PipelineContext_WriteInput_Throws_If_External_ProcessorArgument()
 {
     Processor processor = new MockProcessor1();
     MockPipeline pipeline = TestPipelines.CreateMockProcessor1Pipeline();
     PipelineContext context = new PipelineContext(pipeline);
     ExceptionAssert.Throws(
         typeof(ArgumentException),
         "PipelineContext should throw if processor argument belongs to different pipeline",
         () => context.WriteInput(processor.InArguments[0], new object()),
         "inArgument"
         );
 }
 public void PipelineContext_ReadAllInputs_Throws_If_Processor_Not_In_Pipeline()
 {
     Processor processor = new MockProcessor1();
     MockPipeline pipeline = TestPipelines.CreateMockProcessor1Pipeline();
     PipelineContext context = new PipelineContext(pipeline);
     ExceptionAssert.Throws(
         typeof(ArgumentException),
         "PipelineContext should throw if processor from different pipeline specified",
         () => context.ReadAllInputs(processor),
         "processor"
         );
 }
        public void Pipeline_Processor_Belongs_To_Only_1_Pipeline()
        {
            Processor processor = new MockProcessor1();
            Pipeline pipeline1 = new Pipeline(new[] { processor }, Enumerable.Empty<ProcessorArgument>(), Enumerable.Empty<ProcessorArgument>());

            Assert.AreEqual(pipeline1, processor.ContainingCollection.ContainerProcessor, "Processor.Pipeline must be the pipeline we created");

            Pipeline pipeline2;
            ExceptionAssert.ThrowsInvalidOperation(
                "Adding a processor to a 2nd pipeline should throw",
                () => pipeline2 = new Pipeline(new[] { processor }, Enumerable.Empty<ProcessorArgument>(), Enumerable.Empty<ProcessorArgument>())
                );
        }
        public void Pipeline_Bind_OnBinding_OnBind_OnBound_Callbacks()
        {
            MockProcessor1 processor1 = new MockProcessor1();
            MockProcessorEchoString processor2 = new MockProcessorEchoString();
            MockPipeline pipeline = new MockPipeline(
                new Processor[] { processor1, processor2 },
                Enumerable.Empty<ProcessorArgument>(),
                Enumerable.Empty<ProcessorArgument>());
            BindArgumentsEventArgs bindingEventArgs = null;
            BindArgumentsEventArgs boundEventArgs = null;
            ProcessorArgument inArgFromBind = null;
            ProcessorArgument outArgFromBind = null;

            pipeline.OnBindArgumentsCalled = (outArg, inArg) =>
            {
                inArgFromBind = inArg;
                outArgFromBind = outArg;
            };

            pipeline.BindingArguments = (s, a) => { bindingEventArgs = a as BindArgumentsEventArgs; };
            pipeline.BoundArguments = (s, a) => { boundEventArgs = a as BindArgumentsEventArgs; };

            pipeline.BindArguments(processor1.OutArguments[0], processor2.InArguments[0]);
            Assert.IsNotNull(bindingEventArgs, "Did not receive BindingArguments callback");
            Assert.AreSame(processor1.OutArguments[0], bindingEventArgs.OutArgument, "Did not receive correct outArg in BindingArgument callback");
            Assert.AreSame(processor2.InArguments[0], bindingEventArgs.InArgument, "Did not receive correct inArg in BindingArgument callback");

            Assert.IsNotNull(boundEventArgs, "Did not receive BoundArguments callback");
            Assert.AreSame(processor1.OutArguments[0], boundEventArgs.OutArgument, "Did not receive correct outArg in BoundArgument callback");
            Assert.AreSame(processor2.InArguments[0], boundEventArgs.InArgument, "Did not receive correct inArg in BoundArgument callback");

            Assert.AreSame(processor1.OutArguments[0], outArgFromBind, "Did not receive correct outArg in OnBind virtual");
            Assert.AreSame(processor2.InArguments[0], inArgFromBind, "Did not receive correct inArg in OnBind virtual");
        }
        public void Pipeline_UnbindArgument_Succeeds()
        {
            MockProcessor1 processor1 = new MockProcessor1();
            MockProcessorEchoString processor2 = new MockProcessorEchoString();
            Pipeline pipeline = new Pipeline(
                new Processor[] { processor1, processor2 },
                Enumerable.Empty<ProcessorArgument>(),
                Enumerable.Empty<ProcessorArgument>());

            pipeline.BindArguments(processor1.OutArguments[0], processor2.InArguments[0]);
            Assert.IsTrue(
                pipeline.GetBoundToArguments(processor1.OutArguments[0]).Contains(processor2.InArguments[0]),
                "Expected GetBoundTo(out) to show we bound out to in");
            Assert.IsTrue(
                pipeline.GetBoundToArguments(processor2.InArguments[0]).Contains(processor1.OutArguments[0]),
                "Expected GetBoundTo(in) to show we bound out to in");

            pipeline.UnbindArguments(processor1.OutArguments[0], processor2.InArguments[0]);

            Assert.IsFalse(
                pipeline.GetBoundToArguments(processor1.OutArguments[0]).Contains(processor2.InArguments[0]),
                "Expected GetBoundTo(out) to show we unbound out to in");
            Assert.IsFalse(
                pipeline.GetBoundToArguments(processor2.InArguments[0]).Contains(processor1.OutArguments[0]),
                "Expected GetBoundTo(in) to show we unbound out to in");
        }
 public void Pipeline_Executes_With_No_Bindings()
 {
     MockProcessor1 processor1 = new MockProcessor1();
     MockProcessorEchoString processor2 = new MockProcessorEchoString();
     MockPipeline pipeline = new MockPipeline(
                                 new Processor[] { processor1, processor2 },
                                 Enumerable.Empty<ProcessorArgument>(),
                                 Enumerable.Empty<ProcessorArgument>());
     pipeline.Initialize();
     ProcessorResult result = pipeline.Execute(new object[0]);
     Assert.IsNotNull(result, "Expected non-null ProcessorResult");
     Assert.IsNotNull(result.Output, "Expected non-null output from unbound pipeline");
     Assert.AreEqual(0, result.Output.Length, "Expected empty array from unbound pipeline");
     Assert.AreEqual(ProcessorStatus.Ok, result.Status, "Expected OK status from pipeline");
 }
Example #49
0
        private void AssertOrderingCorrect(bool startWithABeforeB, bool aAndBadjacent)
        {
            for (int iTruth = 0; iTruth < truthTable.Length; ++iTruth)
            {
                ProcessorExecutionOrder orderA = (ProcessorExecutionOrder)truthTable[iTruth][0];
                ProcessorExecutionOrder orderB = (ProcessorExecutionOrder)truthTable[iTruth][1];
                int swapValue = (int)truthTable[iTruth][2];

                MockPipelineBuilder pb = new MockPipelineBuilder();

                // Tell mock not to call validate, since we only want to order
                pb.OnValidateCalled = p => false;

                OrderableMockProcessorEchoString processorA = new OrderableMockProcessorEchoString()
                {
                    Name = "ProcessorA"
                };
                OrderableMockProcessorEchoString processorB = new OrderableMockProcessorEchoString()
                {
                    Name = "ProcessorB"
                };
                MockProcessor1 processorC = new MockProcessor1()
                {
                    Name = "ProcessorC"
                };

                if (orderA == ProcessorExecutionOrder.Before)
                {
                    processorA.RunBefore = processorB;
                }
                if (orderA == ProcessorExecutionOrder.After)
                {
                    processorA.RunAfter = processorB;
                }
                if (orderB == ProcessorExecutionOrder.Before)
                {
                    processorB.RunBefore = processorA;
                }
                if (orderB == ProcessorExecutionOrder.After)
                {
                    processorB.RunAfter = processorA;
                }

                Processor[] processors = (startWithABeforeB)
                                            ? (aAndBadjacent)
                                                ? new Processor[] { processorA, processorB }
                                                : new Processor[] { processorA, processorC, processorB }
                                            : (aAndBadjacent)
                                                ? new Processor[] { processorB, processorA }
                                                : new Processor[] { processorB, processorC, processorA };

                Pipeline  pipeline        = null;
                Exception thrownException = null;
                try
                {
                    pipeline = pb.Build(
                        processors,
                        Enumerable.Empty <ProcessorArgument>(),
                        Enumerable.Empty <ProcessorArgument>()
                        );
                }
                catch (Exception e)
                {
                    thrownException = e;
                }

                if (swapValue < 0)
                {
                    Assert.IsNotNull(thrownException, "Expected exception when orderA=" + orderA + " and orderB=" + orderB + ", aFirst=" + startWithABeforeB + ", adjacent=" + aAndBadjacent);
                }
                else
                {
                    Assert.IsNull(thrownException, "Expected no exception when orderA=" + orderA + " and orderB=" + orderB + ", aFirst=" + startWithABeforeB + ", adjacent=" + aAndBadjacent);

                    int indexA = pipeline.Processors.IndexOf(processorA);
                    int indexB = pipeline.Processors.IndexOf(processorB);
                    if (orderA == ProcessorExecutionOrder.Before || orderB == ProcessorExecutionOrder.After)
                    {
                        Assert.IsTrue(indexA < indexB, "Expected A to come before when orderA=" + orderA + " and orderB=" + orderB);
                    }

                    else if (orderB == ProcessorExecutionOrder.Before || orderA == ProcessorExecutionOrder.After)
                    {
                        Assert.IsTrue(indexB < indexA, "Expected B to come before when orderA=" + orderA + " and orderB=" + orderB + ", aFirst=" + startWithABeforeB + ", adjacent=" + aAndBadjacent);
                    }

                    else
                    {
                        if (startWithABeforeB)
                        {
                            Assert.IsTrue(indexA < indexB, "Expected A to come before when orderA=" + orderA + " and orderB=" + orderB + ", aFirst=" + startWithABeforeB + ", adjacent=" + aAndBadjacent);
                        }
                        else
                        {
                            Assert.IsTrue(indexB < indexA, "Expected A to come before when orderA=" + orderA + " and orderB=" + orderB + ", aFirst=" + startWithABeforeB + ", adjacent=" + aAndBadjacent);
                        }
                    }
                }
            }
        }
        public void Processor_Fires_Initializing_Event_On_Initialize()
        {
            Processor mock = new MockProcessor1();

            bool initializingCalled = false;
            object initializingObject = null;
            EventArgs initializingEventArgs = null;

            mock.Initializing = new EventHandler(
                (obj, eArgs) =>
                {
                    initializingCalled = true;
                    initializingObject = obj;
                    initializingEventArgs = eArgs;
                });

            mock.Initialize();

            Assert.IsTrue(initializingCalled, "The Initializing event should have fired.");
            Assert.AreSame(mock, initializingObject, "The event sender should have been the processor itself.");
            Assert.AreSame(EventArgs.Empty, initializingEventArgs, "The event args should have been the EventArgs.Empty instance.");
        }