Beispiel #1
0
        public void Bind_Unbind_Bind_Is_Equivalent_To_Bind()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();

            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(string)));

            MockNonGenericProcessor p2 = new MockNonGenericProcessor();

            p2.SetInputArguments(new ProcessorArgument("p2In1", typeof(string)));

            ProcessorCollection       collection = new ProcessorCollection(new MockNonGenericProcessor(), p1, p2);
            PipelineBindingCollection bindings   = new PipelineBindingCollection(collection);

            bindings.BindArguments(p1.OutArguments[0], p2.InArguments[0]);
            Assert.AreEqual(1, bindings.GetBoundToArguments(p2.InArguments[0]).Count(), "Processor2 InArgument1 should have been bound to one other argument.");
            Assert.AreEqual(1, bindings.GetBoundToArguments(p1.OutArguments[0]).Count(), "Processor1 OutArgument1 should have been bound to one other argument.");
            Assert.AreSame(p1.OutArguments[0], bindings.GetBoundToArguments(p2.InArguments[0]).Single(), "Processor2 InArgument1 should have been bound to Processor1 OutArgument1.");
            Assert.AreSame(p2.InArguments[0], bindings.GetBoundToArguments(p1.OutArguments[0]).Single(), "Processor1 OutArgument1 should have been bound to Processor2 InArgument1.");

            bindings.UnbindArguments(p1.OutArguments[0], p2.InArguments[0]);
            Assert.AreEqual(0, bindings.GetBoundToArguments(p2.InArguments[0]).Count(), "Processor2 InArgument1 should not have been bound to any other arguments.");
            Assert.AreEqual(0, bindings.GetBoundToArguments(p1.OutArguments[0]).Count(), "Processor1 OutArgument1 should not have been bound to any other arguments.");

            bindings.BindArguments(p1.OutArguments[0], p2.InArguments[0]);
            Assert.AreEqual(1, bindings.GetBoundToArguments(p2.InArguments[0]).Count(), "Processor2 InArgument1 should have been bound to one other argument.");
            Assert.AreEqual(1, bindings.GetBoundToArguments(p1.OutArguments[0]).Count(), "Processor1 OutArgument1 should have been bound to one other argument.");
            Assert.AreSame(p1.OutArguments[0], bindings.GetBoundToArguments(p2.InArguments[0]).Single(), "Processor2 InArgument1 should have been bound to Processor1 OutArgument1.");
            Assert.AreSame(p2.InArguments[0], bindings.GetBoundToArguments(p1.OutArguments[0]).Single(), "Processor1 OutArgument1 should have been bound to Processor2 InArgument1.");
        }
        public void OutArguments_Does_Not_Change_ProcessorArguments()
        {
            MockNonGenericProcessor processor = new MockNonGenericProcessor();
            ProcessorArgument       arg1      = new ProcessorArgument("arg1", typeof(string), "someProperty");
            ProcessorArgument       arg2      = new ProcessorArgument("arg2", typeof(Uri), "someOtherProperty", 5);
            ProcessorArgument       arg3      = new ProcessorArgument("arg3", typeof(int));

            processor.SetOutputArguments(arg1, arg2, arg3);

            ProcessorArgumentCollection arguments = processor.OutArguments;

            Assert.IsNotNull(arguments, "OutArguments should never be null.");
            Assert.AreEqual(3, arguments.Count, "OutArguments.Count should have returned 3.");

            Assert.AreSame(arg1, arguments[0], "The argument should have been the same instance as was provided by OnGetOutputArguments.");
            Assert.AreSame(arg2, arguments[1], "The argument should have been the same instance as was provided by OnGetOutputArguments.");
            Assert.AreSame(arg3, arguments[2], "The argument should have been the same instance as was provided by OnGetOutputArguments.");

            Assert.AreEqual("arg1", arguments[0].Name, "The argument name should have been the same as when it was created.");
            Assert.AreEqual("arg2", arguments[1].Name, "The argument name should have been the same as when it was created.");
            Assert.AreEqual("arg3", arguments[2].Name, "The argument name should have been the same as when it was created.");

            Assert.AreEqual(typeof(string), arguments[0].ArgumentType, "The argument type should have been the same as when it was created.");
            Assert.AreEqual(typeof(Uri), arguments[1].ArgumentType, "The argument type should have been the same as when it was created.");
            Assert.AreEqual(typeof(int), arguments[2].ArgumentType, "The argument type should have been the same as when it was created.");

            Assert.AreEqual(1, arguments[0].Properties.Count, "The argument should have the one property that it was created with.");
            Assert.AreEqual("someProperty", arguments[0].Properties.Find <string>(), "The argument should have the property value that it was created with.");

            Assert.AreEqual(2, arguments[1].Properties.Count, "The argument should have the two properties that it was created with.");
            Assert.AreEqual("someOtherProperty", arguments[1].Properties.Find <string>(), "The argument should have the property value that it was created with.");
            Assert.AreEqual(5, arguments[1].Properties.Find <int>(), "The argument should have the property value that it was created with.");

            Assert.AreEqual(0, arguments[2].Properties.Count, "The argument should not have any properties since it was not created with any.");
        }
Beispiel #3
0
        public void Bind_Can_Bind_One_OutArgument_Multiple_Times()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();

            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(string)));

            MockNonGenericProcessor p2 = new MockNonGenericProcessor();

            p2.SetInputArguments(new ProcessorArgument("p2In1", typeof(string)));

            MockNonGenericProcessor p3 = new MockNonGenericProcessor();

            p3.SetInputArguments(new ProcessorArgument("p3In1", typeof(string)));

            ProcessorCollection       collection = new ProcessorCollection(new MockNonGenericProcessor(), p1, p2, p3);
            PipelineBindingCollection bindings   = new PipelineBindingCollection(collection);

            bindings.BindArguments(p1.OutArguments[0], p2.InArguments[0]);
            bindings.BindArguments(p1.OutArguments[0], p3.InArguments[0]);
            Assert.AreEqual(2, bindings.GetBoundToArguments(p1.OutArguments[0]).Count(), "Processor1 OutArgument1 should have been bound to two other arguments.");
            Assert.AreSame(p2.InArguments[0], bindings.GetBoundToArguments(p1.OutArguments[0]).First(), "Processor1 OutArgument1 should have been bound to Processor2 InArgument1.");
            Assert.AreSame(p3.InArguments[0], bindings.GetBoundToArguments(p1.OutArguments[0]).Skip(1).First(), "Processor1 OutArgument1 should have been bound to Processor3 InArgument1.");
            Assert.AreSame(p1.OutArguments[0], bindings.GetBoundToArguments(p2.InArguments[0]).Single(), "Processor2 InArgument1 should have been bound to Processor1 OutArgument1.");
            Assert.AreSame(p1.OutArguments[0], bindings.GetBoundToArguments(p3.InArguments[0]).Single(), "Processor3 InArgument1 should have been bound to Processor1 OutArgument1.");
        }
Beispiel #4
0
        public void UnBind_Does_Nothing_If_Arguments_Are_Not_Bound()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();

            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(string)));

            MockNonGenericProcessor p2 = new MockNonGenericProcessor();

            p2.SetOutputArguments(new ProcessorArgument("p2Out1", typeof(string)));

            MockNonGenericProcessor p3 = new MockNonGenericProcessor();

            p3.SetInputArguments(new ProcessorArgument("p3In1", typeof(string)));

            ProcessorCollection       collection = new ProcessorCollection(new MockNonGenericProcessor(), p1, p2, p3);
            PipelineBindingCollection bindings   = new PipelineBindingCollection(collection);

            bindings.BindArguments(p2.OutArguments[0], p3.InArguments[0]);
            Assert.AreEqual(0, bindings.GetBoundToArguments(p1.OutArguments[0]).Count(), "Processor1 OutArgument1 should not have been bound to any other arguments.");
            Assert.AreEqual(1, bindings.GetBoundToArguments(p2.OutArguments[0]).Count(), "Processor2 OutArgument1 should not have been bound to any other arguments.");
            Assert.AreEqual(1, bindings.GetBoundToArguments(p3.InArguments[0]).Count(), "Processor3 InArgument1 should not have been bound to any other arguments.");
            Assert.AreSame(p2.OutArguments[0], bindings.GetBoundToArguments(p3.InArguments[0]).Single(), "Processor3 InArgument1 should have been bound to Processor2 OutArgument1.");
            Assert.AreSame(p3.InArguments[0], bindings.GetBoundToArguments(p2.OutArguments[0]).Single(), "Processor2 OutArgument1 should have been bound to Processor3 InArgument1.");

            bindings.UnbindArguments(p1.OutArguments[0], p3.InArguments[0]);
            Assert.AreEqual(1, bindings.GetBoundToArguments(p2.OutArguments[0]).Count(), "Processor2 OutArgument1 should not have been bound to any other arguments.");
            Assert.AreEqual(1, bindings.GetBoundToArguments(p3.InArguments[0]).Count(), "Processor3 InArgument1 should not have been bound to any other arguments.");
            Assert.AreSame(p2.OutArguments[0], bindings.GetBoundToArguments(p3.InArguments[0]).Single(), "Processor3 InArgument1 should have been bound to Processor2 OutArgument1.");
            Assert.AreSame(p3.InArguments[0], bindings.GetBoundToArguments(p2.OutArguments[0]).Single(), "Processor2 OutArgument1 should have been bound to Processor3 InArgument1.");
        }
        public void OutArguments_Returns_ProcessorArgumentCollection_with_Null_ProcessorArgument_Array()
        {
            MockNonGenericProcessor processor = new MockNonGenericProcessor();

            processor.SetOutputArguments(null);

            ProcessorArgumentCollection arguments = processor.OutArguments;

            Assert.IsNotNull(arguments, "OutArguments should never be null.");
            Assert.AreEqual(ProcessorArgumentDirection.Out, arguments.Direction, "OutArguments.Direction ProcessorArgumentDirection.Out");
            Assert.AreEqual(0, arguments.Count, "OutArguments.Count should have been 0.");
        }
        public void OutArguments_Returns_ProcessorArgumentCollection()
        {
            MockNonGenericProcessor processor = new MockNonGenericProcessor();

            processor.SetOutputArguments(new ProcessorArgument("arg1", typeof(string)));

            ProcessorArgumentCollection arguments = processor.OutArguments;

            Assert.IsNotNull(arguments, "OutArguments should never be null.");
            Assert.AreEqual(ProcessorArgumentDirection.Out, arguments.Direction, "OutArguments.Direction ProcessorArgumentDirection.Out");
            Assert.AreEqual(1, arguments.Count, "OutArguments.Count should have been 1.");
        }
        public void OutArguments_Returns_The_Same_ProcessorArgumentCollection_Instance_Every_Time()
        {
            MockNonGenericProcessor processor = new MockNonGenericProcessor();

            processor.SetOutputArguments(new ProcessorArgument("arg1", typeof(string)));

            ProcessorArgumentCollection arguments1 = processor.OutArguments;
            ProcessorArgumentCollection arguments2 = processor.OutArguments;
            ProcessorArgumentCollection arguments3 = processor.OutArguments;

            Assert.IsNotNull(arguments1, "OutArguments should never be null.");
            Assert.AreSame(arguments1, arguments2, "OutArguments should return the same instance every time.");
            Assert.AreSame(arguments1, arguments3, "OutArguments should return the same instance every time.");
        }
        public void OutArguments_Returns_ProcessorArguments_With_ContainingCollection_Set()
        {
            MockNonGenericProcessor processor = new MockNonGenericProcessor();
            ProcessorArgument       arg1      = new ProcessorArgument("arg1", typeof(string), "someProperty");
            ProcessorArgument       arg2      = new ProcessorArgument("arg2", typeof(Uri), "someOtherProperty", 5);
            ProcessorArgument       arg3      = new ProcessorArgument("arg3", typeof(int));

            processor.SetOutputArguments(arg1, arg2, arg3);

            ProcessorArgumentCollection arguments = processor.OutArguments;

            Assert.AreSame(arguments, arguments[0].ContainingCollection, "The argument ContainingCollection should have been set by the ProcessorArgumentCollection.");
            Assert.AreSame(arguments, arguments[1].ContainingCollection, "The argument ContainingCollection should have been set by the ProcessorArgumentCollection.");
            Assert.AreSame(arguments, arguments[2].ContainingCollection, "The argument ContainingCollection should have been set by the ProcessorArgumentCollection.");
        }
        public void OutArguments_With_Two_ProcessorArguments_With_Same_Name_Throws()
        {
            MockNonGenericProcessor processor = new MockNonGenericProcessor();
            ProcessorArgument       arg1      = new ProcessorArgument("arg1", typeof(string), "someProperty");
            ProcessorArgument       arg2      = new ProcessorArgument("arg1", typeof(int));

            processor.SetOutputArguments(arg1, arg2);

            ExceptionAssert.ThrowsInvalidOperation(
                "OutArguments should have thrown since there were two arguments with the same name.",
                () =>
            {
                ProcessorArgumentCollection arguments = processor.OutArguments;
            });
        }
Beispiel #10
0
        public void Unbind_With_In_Argument_Not_Attached_To_Processors_Throws()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();

            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(string)));
            ProcessorCollection       collection = new ProcessorCollection(new MockNonGenericProcessor(), p1);
            PipelineBindingCollection bindings   = new PipelineBindingCollection(collection);

            ExceptionAssert.ThrowsInvalidOperation(
                "Unbind should have thrown because the in arugment does not belong to a processor",
                () =>
            {
                bindings.UnbindArguments(p1.OutArguments[0], new ProcessorArgument("someName", typeof(string)));
            });
        }
        public void OutArguments_Returns_ProcessorArguments_With_Index_Set()
        {
            MockNonGenericProcessor processor = new MockNonGenericProcessor();
            ProcessorArgument       arg1      = new ProcessorArgument("arg1", typeof(string), "someProperty");
            ProcessorArgument       arg2      = new ProcessorArgument("arg2", typeof(Uri), "someOtherProperty", 5);
            ProcessorArgument       arg3      = new ProcessorArgument("arg3", typeof(int));

            processor.SetOutputArguments(arg1, arg2, arg3);

            ProcessorArgumentCollection arguments = processor.OutArguments;

            Assert.AreEqual(0, arguments[0].Index, "The argument index should have been determined by the order it was returned from OnGetOutputArguments.");
            Assert.AreEqual(1, arguments[1].Index, "The argument index should have been determined by the order it was returned from OnGetOutputArguments.");
            Assert.AreEqual(2, arguments[2].Index, "The argument index should have been determined by the order it was returned from OnGetOutputArguments.");
        }
Beispiel #12
0
        public void Unbind_With_Arguments_On_The_Same_Processor_Throws()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();

            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(string)));
            p1.SetInputArguments(new ProcessorArgument("p1In1", typeof(string)));
            ProcessorCollection       collection = new ProcessorCollection(new MockNonGenericProcessor(), p1);
            PipelineBindingCollection bindings   = new PipelineBindingCollection(collection);

            ExceptionAssert.ThrowsInvalidOperation(
                "Unbind should have thrown because the in arugment and out argument belong to the same processor",
                () =>
            {
                bindings.UnbindArguments(p1.OutArguments[0], p1.InArguments[0]);
            });
        }
        public void ProcessorArgument_Cannot_Belong_to_Both_In_And_Out_Collections()
        {
            ProcessorArgument       arg        = new ProcessorArgument("AName", typeof(string));
            MockNonGenericProcessor processor1 = new MockNonGenericProcessor();

            processor1.SetInputArguments(arg);
            ProcessorArgumentCollection processor1InArguments = processor1.InArguments;

            processor1.SetOutputArguments(arg);

            ExceptionAssert.ThrowsInvalidOperation(
                "Adding processor argument to in and out arguments should throw",
                () =>
            {
                ProcessorArgumentCollection processor1OutArguments = processor1.OutArguments;
            });
        }
        public void OutArguments_With_A_Null_ProcessorArgument_Throws()
        {
            MockNonGenericProcessor processor = new MockNonGenericProcessor();
            ProcessorArgument       arg1      = new ProcessorArgument("arg1", typeof(string), "someProperty");
            ProcessorArgument       arg2      = null;
            ProcessorArgument       arg3      = new ProcessorArgument("arg3", typeof(int));

            processor.SetOutputArguments(arg1, arg2, arg3);

            ExceptionAssert.ThrowsArgumentNull(
                "OutArguments should have thrown since a null ProcessorArgument was provided.",
                string.Empty,
                () =>
            {
                ProcessorArgumentCollection arguments = processor.OutArguments;
            });
        }
        public void OutArguments_Returns_Same_ProcessorArguments_In_The_Same_Order()
        {
            MockNonGenericProcessor processor = new MockNonGenericProcessor();
            ProcessorArgument       arg1      = new ProcessorArgument("arg1", typeof(string), "someProperty");
            ProcessorArgument       arg2      = new ProcessorArgument("arg2", typeof(Uri), "someOtherProperty", 5);
            ProcessorArgument       arg3      = new ProcessorArgument("arg3", typeof(int));

            processor.SetOutputArguments(arg1, arg2, arg3);

            ProcessorArgumentCollection arguments = processor.OutArguments;

            Assert.IsNotNull(arguments, "OutArguments should never be null.");
            Assert.AreEqual(3, arguments.Count, "OutArguments.Count should have returned 3.");

            Assert.AreSame(arg1, arguments[0], "The argument should have been the same instance as was provided by OnGetOutputArguments.");
            Assert.AreSame(arg2, arguments[1], "The argument should have been the same instance as was provided by OnGetOutputArguments.");
            Assert.AreSame(arg3, arguments[2], "The argument should have been the same instance as was provided by OnGetOutputArguments.");
        }
Beispiel #16
0
        public void Unbind_With_Out_Argument_On_Processors_Not_In_A_ProcessorCollection_Throws()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();

            p1.SetInputArguments(new ProcessorArgument("p1In1", typeof(string)));
            ProcessorCollection       collection = new ProcessorCollection(new MockNonGenericProcessor(), p1);
            PipelineBindingCollection bindings   = new PipelineBindingCollection(collection);

            MockNonGenericProcessor p2 = new MockNonGenericProcessor();

            p2.SetOutputArguments(new ProcessorArgument("p2Out1", typeof(string)));

            ExceptionAssert.ThrowsInvalidOperation(
                "Unbind should have thrown because the out arugment processor does not belong to any processor collection",
                () =>
            {
                bindings.UnbindArguments(p2.OutArguments[0], p1.InArguments[0]);
            });
        }
Beispiel #17
0
        public void Bind_With_OutArgument_Type_Assignable_To_InArgument_Type()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();

            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(Uri)));

            MockNonGenericProcessor p2 = new MockNonGenericProcessor();

            p2.SetInputArguments(new ProcessorArgument("p2In1", typeof(object)));

            ProcessorCollection       collection = new ProcessorCollection(new MockNonGenericProcessor(), p1, p2);
            PipelineBindingCollection bindings   = new PipelineBindingCollection(collection);

            bindings.BindArguments(p1.OutArguments[0], p2.InArguments[0]);
            Assert.AreEqual(1, bindings.GetBoundToArguments(p2.InArguments[0]).Count(), "Processor2 InArgument1 should have been bound to one other argument.");
            Assert.AreEqual(1, bindings.GetBoundToArguments(p1.OutArguments[0]).Count(), "Processor1 OutArgument1 should have been bound to one other argument.");
            Assert.AreSame(p1.OutArguments[0], bindings.GetBoundToArguments(p2.InArguments[0]).First(), "Processor2 InArgument1 should have been bound to Processor1 OutArgument1.");
            Assert.AreSame(p2.InArguments[0], bindings.GetBoundToArguments(p1.OutArguments[0]).First(), "Processor1 OutArgument1 should have been bound to Processor2 InArgument1.");
        }
Beispiel #18
0
        public void Unbind_With_In_Arguments_On_Processors_Not_In_The_Same_ProcessorCollection_Throws()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();

            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(string)));
            ProcessorCollection       collection = new ProcessorCollection(new MockNonGenericProcessor(), p1);
            PipelineBindingCollection bindings   = new PipelineBindingCollection(collection);

            MockNonGenericProcessor p2 = new MockNonGenericProcessor();

            p2.SetInputArguments(new ProcessorArgument("p2In1", typeof(string)));
            ProcessorCollection otherCollection = new ProcessorCollection(new MockNonGenericProcessor(), p2);

            ExceptionAssert.ThrowsInvalidOperation(
                "Unbind should have thrown because the in arugment processor belongs to a different processor collection",
                () =>
            {
                bindings.UnbindArguments(p1.OutArguments[0], p2.InArguments[0]);
            });
        }
Beispiel #19
0
        public void GetBoundToArguments_Never_Returns_Null()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();

            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(string)));

            ProcessorArgument arg2 = new ProcessorArgument("arg1", typeof(string));

            ProcessorCollection       collection = new ProcessorCollection(new MockNonGenericProcessor(), p1);
            PipelineBindingCollection bindings   = new PipelineBindingCollection(collection);

            IEnumerable <ProcessorArgument> boundArguments = bindings.GetBoundToArguments(p1.OutArguments[0]);

            Assert.IsNotNull(boundArguments, "ProcessorBindingCollection.GetBoundArguments should never return null.");
            Assert.AreEqual(0, boundArguments.Count(), "ProcessorBindingCollection.GetBoundArguments should have returned an empty collection.");

            boundArguments = bindings.GetBoundToArguments(arg2);
            Assert.IsNotNull(boundArguments, "ProcessorBindingCollection.GetBoundArguments should never return null.");
            Assert.AreEqual(0, boundArguments.Count(), "ProcessorBindingCollection.GetBoundArguments should have returned an empty collection.");
        }
Beispiel #20
0
        public void Unbind_With_InArgument_Processor_Before_OutArgument_Processor_Throws()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();

            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(string)));

            MockNonGenericProcessor p2 = new MockNonGenericProcessor();

            p2.SetInputArguments(new ProcessorArgument("p2In1", typeof(string)));

            ProcessorCollection       collection = new ProcessorCollection(new MockNonGenericProcessor(), p2, p1);
            PipelineBindingCollection bindings   = new PipelineBindingCollection(collection);

            ExceptionAssert.ThrowsInvalidOperation(
                "Unbind should have thrown because processor 1 comes after processor 2.",
                () =>
            {
                bindings.UnbindArguments(p1.OutArguments[0], p2.InArguments[0]);
            });
        }
Beispiel #21
0
        public void Unbind_With_OutArgument_Type_Not_Assignable_To_InArgument_Type_Throws()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();

            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(object)));

            MockNonGenericProcessor p2 = new MockNonGenericProcessor();

            p2.SetInputArguments(new ProcessorArgument("p2In1", typeof(Uri)));

            ProcessorCollection       collection = new ProcessorCollection(new MockNonGenericProcessor(), p1, p2);
            PipelineBindingCollection bindings   = new PipelineBindingCollection(collection);

            ExceptionAssert.ThrowsInvalidOperation(
                "Unbind should have thrown because the out arugment is not assignable to the in argument.",
                () =>
            {
                bindings.UnbindArguments(p1.OutArguments[0], p2.InArguments[0]);
            });
        }
Beispiel #22
0
        public void Unbind_With_InArgument_That_Is_Not_In_Direction_Throws()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();

            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(string)));

            MockNonGenericProcessor p2 = new MockNonGenericProcessor();

            p2.SetOutputArguments(new ProcessorArgument("p2Out1", typeof(string)));

            ProcessorCollection       collection = new ProcessorCollection(new MockNonGenericProcessor(), p1, p2);
            PipelineBindingCollection bindings   = new PipelineBindingCollection(collection);

            ExceptionAssert.ThrowsInvalidOperation(
                "Unbind should have thrown because the in arugment is not in the in direction.",
                () =>
            {
                bindings.UnbindArguments(p1.OutArguments[0], p2.OutArguments[0]);
            });
        }
        public void Bind_Can_Bind_One_OutArgument_Multiple_Times()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();
            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(string)));

            MockNonGenericProcessor p2 = new MockNonGenericProcessor();
            p2.SetInputArguments(new ProcessorArgument("p2In1", typeof(string)));

            MockNonGenericProcessor p3 = new MockNonGenericProcessor();
            p3.SetInputArguments(new ProcessorArgument("p3In1", typeof(string)));

            ProcessorCollection collection = new ProcessorCollection(new MockNonGenericProcessor(), p1, p2, p3);
            PipelineBindingCollection bindings = new PipelineBindingCollection(collection);

            bindings.BindArguments(p1.OutArguments[0], p2.InArguments[0]);
            bindings.BindArguments(p1.OutArguments[0], p3.InArguments[0]);
            Assert.AreEqual(2, bindings.GetBoundToArguments(p1.OutArguments[0]).Count(), "Processor1 OutArgument1 should have been bound to two other arguments.");
            Assert.AreSame(p2.InArguments[0], bindings.GetBoundToArguments(p1.OutArguments[0]).First(), "Processor1 OutArgument1 should have been bound to Processor2 InArgument1.");
            Assert.AreSame(p3.InArguments[0], bindings.GetBoundToArguments(p1.OutArguments[0]).Skip(1).First(), "Processor1 OutArgument1 should have been bound to Processor3 InArgument1.");
            Assert.AreSame(p1.OutArguments[0], bindings.GetBoundToArguments(p2.InArguments[0]).Single(), "Processor2 InArgument1 should have been bound to Processor1 OutArgument1.");
            Assert.AreSame(p1.OutArguments[0], bindings.GetBoundToArguments(p3.InArguments[0]).Single(), "Processor3 InArgument1 should have been bound to Processor1 OutArgument1.");
        }
        public void Bind_Is_Idempotent()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();
            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(string)));

            MockNonGenericProcessor p2 = new MockNonGenericProcessor();
            p2.SetInputArguments(new ProcessorArgument("p2In1", typeof(string)));

            ProcessorCollection collection = new ProcessorCollection(new MockNonGenericProcessor(), p1, p2);
            PipelineBindingCollection bindings = new PipelineBindingCollection(collection);

            bindings.BindArguments(p1.OutArguments[0], p2.InArguments[0]);
            Assert.AreEqual(1, bindings.GetBoundToArguments(p2.InArguments[0]).Count(), "Processor2 InArgument1 should have been bound to one other argument.");
            Assert.AreEqual(1, bindings.GetBoundToArguments(p1.OutArguments[0]).Count(), "Processor1 OutArgument1 should have been bound to one other argument.");
            Assert.AreSame(p1.OutArguments[0], bindings.GetBoundToArguments(p2.InArguments[0]).First(), "Processor2 InArgument1 should have been bound to Processor1 OutArgument1.");
            Assert.AreSame(p2.InArguments[0], bindings.GetBoundToArguments(p1.OutArguments[0]).First(), "Processor1 OutArgument1 should have been bound to Processor2 InArgument1.");

            bindings.BindArguments(p1.OutArguments[0], p2.InArguments[0]);
            Assert.AreEqual(1, bindings.GetBoundToArguments(p2.InArguments[0]).Count(), "Processor2 InArgument1 should have been bound to one other argument.");
            Assert.AreEqual(1, bindings.GetBoundToArguments(p1.OutArguments[0]).Count(), "Processor1 OutArgument1 should have been bound to one other argument.");
            Assert.AreSame(p1.OutArguments[0], bindings.GetBoundToArguments(p2.InArguments[0]).First(), "Processor2 InArgument1 should have been bound to Processor1 OutArgument1.");
            Assert.AreSame(p2.InArguments[0], bindings.GetBoundToArguments(p1.OutArguments[0]).First(), "Processor1 OutArgument1 should have been bound to Processor2 InArgument1.");
        }
        public void Unbind_With_In_Arguments_On_Processors_Not_In_The_Same_ProcessorCollection_Throws()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();
            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(string)));
            ProcessorCollection collection = new ProcessorCollection(new MockNonGenericProcessor(), p1);
            PipelineBindingCollection bindings = new PipelineBindingCollection(collection);

            MockNonGenericProcessor p2 = new MockNonGenericProcessor();
            p2.SetInputArguments(new ProcessorArgument("p2In1", typeof(string)));
            ProcessorCollection otherCollection = new ProcessorCollection(new MockNonGenericProcessor(), p2);

            ExceptionAssert.ThrowsInvalidOperation(
                "Unbind should have thrown because the in arugment processor belongs to a different processor collection",
                () =>
                {
                    bindings.UnbindArguments(p1.OutArguments[0], p2.InArguments[0]);
                });
        }
        public void Unbind_With_InArgument_Processor_Before_OutArgument_Processor_Throws()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();
            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(string)));

            MockNonGenericProcessor p2 = new MockNonGenericProcessor();
            p2.SetInputArguments(new ProcessorArgument("p2In1", typeof(string)));

            ProcessorCollection collection = new ProcessorCollection(new MockNonGenericProcessor(), p2, p1);
            PipelineBindingCollection bindings = new PipelineBindingCollection(collection);

            ExceptionAssert.ThrowsInvalidOperation(
                "Unbind should have thrown because processor 1 comes after processor 2.",
                () =>
                {
                    bindings.UnbindArguments(p1.OutArguments[0], p2.InArguments[0]);
                });
        }
        public void Unbind_With_InArgument_That_Is_Not_In_Direction_Throws()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();
            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(string)));

            MockNonGenericProcessor p2 = new MockNonGenericProcessor();
            p2.SetOutputArguments(new ProcessorArgument("p2Out1", typeof(string)));

            ProcessorCollection collection = new ProcessorCollection(new MockNonGenericProcessor(), p1, p2);
            PipelineBindingCollection bindings = new PipelineBindingCollection(collection);

            ExceptionAssert.ThrowsInvalidOperation(
                "Unbind should have thrown because the in arugment is not in the in direction.",
                () =>
                {
                    bindings.UnbindArguments(p1.OutArguments[0], p2.OutArguments[0]);
                });
        }
        public void UnBind_Removes_The_Binding_If_Arguments_Are_Bound()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();
            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(string)));

            MockNonGenericProcessor p2 = new MockNonGenericProcessor();
            p2.SetInputArguments(new ProcessorArgument("p2In1", typeof(string)));

            ProcessorCollection collection = new ProcessorCollection(new MockNonGenericProcessor(), p1, p2);
            PipelineBindingCollection bindings = new PipelineBindingCollection(collection);

            bindings.BindArguments(p1.OutArguments[0], p2.InArguments[0]);
            Assert.AreEqual(1, bindings.GetBoundToArguments(p2.InArguments[0]).Count(), "Processor2 InArgument1 should have been bound to one other argument.");
            Assert.AreEqual(1, bindings.GetBoundToArguments(p1.OutArguments[0]).Count(), "Processor1 OutArgument1 should have been bound to one other argument.");
            Assert.AreSame(p1.OutArguments[0], bindings.GetBoundToArguments(p2.InArguments[0]).Single(), "Processor2 InArgument1 should have been bound to Processor1 OutArgument1.");
            Assert.AreSame(p2.InArguments[0], bindings.GetBoundToArguments(p1.OutArguments[0]).Single(), "Processor1 OutArgument1 should have been bound to Processor2 InArgument1.");

            bindings.UnbindArguments(p1.OutArguments[0], p2.InArguments[0]);
            Assert.AreEqual(0, bindings.GetBoundToArguments(p2.InArguments[0]).Count(), "Processor2 InArgument1 should not have been bound to any other arguments.");
            Assert.AreEqual(0, bindings.GetBoundToArguments(p1.OutArguments[0]).Count(), "Processor1 OutArgument1 should not have been bound to any other arguments.");
        }
        public void Unbind_With_Arguments_On_The_Same_Processor_Throws()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();
            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(string)));
            p1.SetInputArguments(new ProcessorArgument("p1In1", typeof(string)));
            ProcessorCollection collection = new ProcessorCollection(new MockNonGenericProcessor(), p1);
            PipelineBindingCollection bindings = new PipelineBindingCollection(collection);

            ExceptionAssert.ThrowsInvalidOperation(
                "Unbind should have thrown because the in arugment and out argument belong to the same processor",
                () =>
                {
                    bindings.UnbindArguments(p1.OutArguments[0], p1.InArguments[0]);
                });
        }
        public void Unbind_With_Out_Argument_On_Processors_Not_In_A_ProcessorCollection_Throws()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();
            p1.SetInputArguments(new ProcessorArgument("p1In1", typeof(string)));
            ProcessorCollection collection = new ProcessorCollection(new MockNonGenericProcessor(), p1);
            PipelineBindingCollection bindings = new PipelineBindingCollection(collection);

            MockNonGenericProcessor p2 = new MockNonGenericProcessor();
            p2.SetOutputArguments(new ProcessorArgument("p2Out1", typeof(string)));

            ExceptionAssert.ThrowsInvalidOperation(
                "Unbind should have thrown because the out arugment processor does not belong to any processor collection",
                () =>
                {
                    bindings.UnbindArguments(p2.OutArguments[0], p1.InArguments[0]);
                });
        }
        public void ProcessorArgument_Cannot_Belong_to_Both_In_And_Out_Collections()
        {
            ProcessorArgument arg = new ProcessorArgument("AName", typeof(string));
            MockNonGenericProcessor processor1 = new MockNonGenericProcessor();
            processor1.SetInputArguments(arg);
            ProcessorArgumentCollection processor1InArguments = processor1.InArguments;
            processor1.SetOutputArguments(arg);

            ExceptionAssert.ThrowsInvalidOperation(
                "Adding processor argument to in and out arguments should throw",
                () =>
                {
                    ProcessorArgumentCollection processor1OutArguments = processor1.OutArguments;
                });
        }
        public void OutArguments_Returns_ProcessorArguments_With_ContainingCollection_Set()
        {
            MockNonGenericProcessor processor = new MockNonGenericProcessor();
            ProcessorArgument arg1 = new ProcessorArgument("arg1", typeof(string), "someProperty");
            ProcessorArgument arg2 = new ProcessorArgument("arg2", typeof(Uri), "someOtherProperty", 5);
            ProcessorArgument arg3 = new ProcessorArgument("arg3", typeof(int));
            processor.SetOutputArguments(arg1, arg2, arg3);

            ProcessorArgumentCollection arguments = processor.OutArguments;

            Assert.AreSame(arguments, arguments[0].ContainingCollection, "The argument ContainingCollection should have been set by the ProcessorArgumentCollection.");
            Assert.AreSame(arguments, arguments[1].ContainingCollection, "The argument ContainingCollection should have been set by the ProcessorArgumentCollection.");
            Assert.AreSame(arguments, arguments[2].ContainingCollection, "The argument ContainingCollection should have been set by the ProcessorArgumentCollection.");
        }
        public void GetBoundToArguments_Never_Returns_Null()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();
            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(string)));

            ProcessorArgument arg2 = new ProcessorArgument("arg1", typeof(string));

            ProcessorCollection collection = new ProcessorCollection(new MockNonGenericProcessor(), p1);
            PipelineBindingCollection bindings = new PipelineBindingCollection(collection);

            IEnumerable<ProcessorArgument> boundArguments = bindings.GetBoundToArguments(p1.OutArguments[0]);
            Assert.IsNotNull(boundArguments, "ProcessorBindingCollection.GetBoundArguments should never return null.");
            Assert.AreEqual(0, boundArguments.Count(), "ProcessorBindingCollection.GetBoundArguments should have returned an empty collection.");

            boundArguments = bindings.GetBoundToArguments(arg2);
            Assert.IsNotNull(boundArguments, "ProcessorBindingCollection.GetBoundArguments should never return null.");
            Assert.AreEqual(0, boundArguments.Count(), "ProcessorBindingCollection.GetBoundArguments should have returned an empty collection.");
        }
        public void OutArguments_Returns_Same_ProcessorArguments_In_The_Same_Order()
        {
            MockNonGenericProcessor processor = new MockNonGenericProcessor();
            ProcessorArgument arg1 = new ProcessorArgument("arg1", typeof(string), "someProperty");
            ProcessorArgument arg2 = new ProcessorArgument("arg2", typeof(Uri), "someOtherProperty", 5);
            ProcessorArgument arg3 = new ProcessorArgument("arg3", typeof(int));
            processor.SetOutputArguments(arg1, arg2, arg3);

            ProcessorArgumentCollection arguments = processor.OutArguments;

            Assert.IsNotNull(arguments, "OutArguments should never be null.");
            Assert.AreEqual(3, arguments.Count, "OutArguments.Count should have returned 3.");

            Assert.AreSame(arg1, arguments[0], "The argument should have been the same instance as was provided by OnGetOutputArguments.");
            Assert.AreSame(arg2, arguments[1], "The argument should have been the same instance as was provided by OnGetOutputArguments.");
            Assert.AreSame(arg3, arguments[2], "The argument should have been the same instance as was provided by OnGetOutputArguments.");
        }
        public void OutArguments_Returns_ProcessorArguments_With_Index_Set()
        {
            MockNonGenericProcessor processor = new MockNonGenericProcessor();
            ProcessorArgument arg1 = new ProcessorArgument("arg1", typeof(string), "someProperty");
            ProcessorArgument arg2 = new ProcessorArgument("arg2", typeof(Uri), "someOtherProperty", 5);
            ProcessorArgument arg3 = new ProcessorArgument("arg3", typeof(int));
            processor.SetOutputArguments(arg1, arg2, arg3);

            ProcessorArgumentCollection arguments = processor.OutArguments;

            Assert.AreEqual(0, arguments[0].Index, "The argument index should have been determined by the order it was returned from OnGetOutputArguments.");
            Assert.AreEqual(1, arguments[1].Index, "The argument index should have been determined by the order it was returned from OnGetOutputArguments.");
            Assert.AreEqual(2, arguments[2].Index, "The argument index should have been determined by the order it was returned from OnGetOutputArguments.");
        }
        public void OutArguments_Returns_The_Same_ProcessorArgumentCollection_Instance_Every_Time()
        {
            MockNonGenericProcessor processor = new MockNonGenericProcessor();
            processor.SetOutputArguments(new ProcessorArgument("arg1", typeof(string)));

            ProcessorArgumentCollection arguments1 = processor.OutArguments;
            ProcessorArgumentCollection arguments2 = processor.OutArguments;
            ProcessorArgumentCollection arguments3 = processor.OutArguments;

            Assert.IsNotNull(arguments1, "OutArguments should never be null.");
            Assert.AreSame(arguments1, arguments2, "OutArguments should return the same instance every time.");
            Assert.AreSame(arguments1, arguments3, "OutArguments should return the same instance every time.");
        }
        public void OutArguments_With_A_Null_ProcessorArgument_Throws()
        {
            MockNonGenericProcessor processor = new MockNonGenericProcessor();
            ProcessorArgument arg1 = new ProcessorArgument("arg1", typeof(string), "someProperty");
            ProcessorArgument arg2 = null;
            ProcessorArgument arg3 = new ProcessorArgument("arg3", typeof(int));
            processor.SetOutputArguments(arg1, arg2, arg3);

            ExceptionAssert.ThrowsArgumentNull(
                "OutArguments should have thrown since a null ProcessorArgument was provided.",
                string.Empty,
                () =>
                {
                    ProcessorArgumentCollection arguments = processor.OutArguments;
                });
        }
        public void OutArguments_With_Two_ProcessorArguments_With_Same_Name_Throws()
        {
            MockNonGenericProcessor processor = new MockNonGenericProcessor();
            ProcessorArgument arg1 = new ProcessorArgument("arg1", typeof(string), "someProperty");
            ProcessorArgument arg2 = new ProcessorArgument("arg1", typeof(int));
            processor.SetOutputArguments(arg1, arg2);

            ExceptionAssert.ThrowsInvalidOperation(
                "OutArguments should have thrown since there were two arguments with the same name.",
                () =>
                {
                    ProcessorArgumentCollection arguments = processor.OutArguments;
                });
        }
        public void Unbind_With_In_Argument_Not_Attached_To_Processors_Throws()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();
            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(string)));
            ProcessorCollection collection = new ProcessorCollection(new MockNonGenericProcessor(), p1);
            PipelineBindingCollection bindings = new PipelineBindingCollection(collection);

            ExceptionAssert.ThrowsInvalidOperation(
                "Unbind should have thrown because the in arugment does not belong to a processor",
                () =>
                {
                    bindings.UnbindArguments(p1.OutArguments[0], new ProcessorArgument("someName", typeof(string)));
                });
        }
        public void UnBind_Does_Not_Remove_Other_Bindings_On_An_InArgument()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();
            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(string)));

            MockNonGenericProcessor p2 = new MockNonGenericProcessor();
            p2.SetOutputArguments(new ProcessorArgument("p2Out1", typeof(string)));

            MockNonGenericProcessor p3 = new MockNonGenericProcessor();
            p3.SetInputArguments(new ProcessorArgument("p3In1", typeof(string)));

            ProcessorCollection collection = new ProcessorCollection(new MockNonGenericProcessor(), p1, p2, p3);
            PipelineBindingCollection bindings = new PipelineBindingCollection(collection);

            bindings.BindArguments(p1.OutArguments[0], p3.InArguments[0]);
            bindings.BindArguments(p2.OutArguments[0], p3.InArguments[0]);

            bindings.UnbindArguments(p1.OutArguments[0], p3.InArguments[0]);
            Assert.AreEqual(1, bindings.GetBoundToArguments(p2.OutArguments[0]).Count(), "Processor2 OutArgument1 should not have been bound to any other arguments.");
            Assert.AreEqual(1, bindings.GetBoundToArguments(p3.InArguments[0]).Count(), "Processor3 InArgument1 should not have been bound to any other arguments.");
            Assert.AreSame(p2.OutArguments[0], bindings.GetBoundToArguments(p3.InArguments[0]).Single(), "Processor3 InArgument1 should have been bound to Processor2 OutArgument1.");
            Assert.AreSame(p3.InArguments[0], bindings.GetBoundToArguments(p2.OutArguments[0]).Single(), "Processor2 OutArgument1 should have been bound to Processor3 InArgument1.");
        }
        public void Unbind_With_OutArgument_Type_Not_Assignable_To_InArgument_Type_Throws()
        {
            MockNonGenericProcessor p1 = new MockNonGenericProcessor();
            p1.SetOutputArguments(new ProcessorArgument("p1Out1", typeof(object)));

            MockNonGenericProcessor p2 = new MockNonGenericProcessor();
            p2.SetInputArguments(new ProcessorArgument("p2In1", typeof(Uri)));

            ProcessorCollection collection = new ProcessorCollection(new MockNonGenericProcessor(), p1, p2);
            PipelineBindingCollection bindings = new PipelineBindingCollection(collection);

            ExceptionAssert.ThrowsInvalidOperation(
                "Unbind should have thrown because the out arugment is not assignable to the in argument.",
                () =>
                {
                    bindings.UnbindArguments(p1.OutArguments[0], p2.InArguments[0]);
                });
        }
        public void OutArguments_Returns_ProcessorArgumentCollection_with_Null_ProcessorArgument_Array()
        {
            MockNonGenericProcessor processor = new MockNonGenericProcessor();
            processor.SetOutputArguments(null);

            ProcessorArgumentCollection arguments = processor.OutArguments;

            Assert.IsNotNull(arguments, "OutArguments should never be null.");
            Assert.AreEqual(ProcessorArgumentDirection.Out, arguments.Direction, "OutArguments.Direction ProcessorArgumentDirection.Out");
            Assert.AreEqual(0, arguments.Count, "OutArguments.Count should have been 0.");
        }
        public void OutArguments_Does_Not_Change_ProcessorArguments()
        {
            MockNonGenericProcessor processor = new MockNonGenericProcessor();
            ProcessorArgument arg1 = new ProcessorArgument("arg1", typeof(string), "someProperty");
            ProcessorArgument arg2 = new ProcessorArgument("arg2", typeof(Uri), "someOtherProperty", 5);
            ProcessorArgument arg3 = new ProcessorArgument("arg3", typeof(int));
            processor.SetOutputArguments(arg1, arg2, arg3);

            ProcessorArgumentCollection arguments = processor.OutArguments;

            Assert.IsNotNull(arguments, "OutArguments should never be null.");
            Assert.AreEqual(3, arguments.Count, "OutArguments.Count should have returned 3.");

            Assert.AreSame(arg1, arguments[0], "The argument should have been the same instance as was provided by OnGetOutputArguments.");
            Assert.AreSame(arg2, arguments[1], "The argument should have been the same instance as was provided by OnGetOutputArguments.");
            Assert.AreSame(arg3, arguments[2], "The argument should have been the same instance as was provided by OnGetOutputArguments.");

            Assert.AreEqual("arg1", arguments[0].Name, "The argument name should have been the same as when it was created.");
            Assert.AreEqual("arg2", arguments[1].Name, "The argument name should have been the same as when it was created.");
            Assert.AreEqual("arg3", arguments[2].Name, "The argument name should have been the same as when it was created.");

            Assert.AreEqual(typeof(string), arguments[0].ArgumentType, "The argument type should have been the same as when it was created.");
            Assert.AreEqual(typeof(Uri), arguments[1].ArgumentType, "The argument type should have been the same as when it was created.");
            Assert.AreEqual(typeof(int), arguments[2].ArgumentType, "The argument type should have been the same as when it was created.");

            Assert.AreEqual(1, arguments[0].Properties.Count, "The argument should have the one property that it was created with.");
            Assert.AreEqual("someProperty", arguments[0].Properties.Find<string>(), "The argument should have the property value that it was created with.");

            Assert.AreEqual(2, arguments[1].Properties.Count, "The argument should have the two properties that it was created with.");
            Assert.AreEqual("someOtherProperty", arguments[1].Properties.Find<string>(), "The argument should have the property value that it was created with.");
            Assert.AreEqual(5, arguments[1].Properties.Find<int>(), "The argument should have the property value that it was created with.");

            Assert.AreEqual(0, arguments[2].Properties.Count, "The argument should not have any properties since it was not created with any.");
        }
        public void OutArguments_Returns_ProcessorArgumentCollection()
        {
            MockNonGenericProcessor processor = new MockNonGenericProcessor();
            processor.SetOutputArguments(new ProcessorArgument("arg1", typeof(string)));

            ProcessorArgumentCollection arguments = processor.OutArguments;

            Assert.IsNotNull(arguments, "OutArguments should never be null.");
            Assert.AreEqual(ProcessorArgumentDirection.Out, arguments.Direction, "OutArguments.Direction ProcessorArgumentDirection.Out");
            Assert.AreEqual(1, arguments.Count, "OutArguments.Count should have been 1.");
        }