示例#1
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");
        }
示例#2
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);
                        }
                    }
                }
            }
        }