Esempio n. 1
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'");
        }
Esempio n. 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);
                        }
                    }
                }
            }
        }