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 object GetCachedValue(ProcessorArgument inArgument) { object value = null; this.Cache.TryGetValue(inArgument, out value); return(value); }
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"); }
protected override void OnWriteInput(ProcessorArgument outArgument, ProcessorArgument inArgument, object value) { if (this.OnWriteInputCalled != null) { value = this.OnWriteInputCalled(outArgument, inArgument, value); } base.OnWriteInput(outArgument, inArgument, value); }
protected override IEnumerable <ProcessorArgument> OnGetOutArguments() { var argument = new ProcessorArgument(MediaTypeProcessor.ArgumentContentType, typeof(string)); return(new List <ProcessorArgument> { argument }); }
public void ProcessorArgument_Name_Cannot_Be_All_Whitespace() { ExceptionAssert.ThrowsInvalidOperation( "ProcessorArgument 'name' parameter cannot be only whitespace.", () => { ProcessorArgument arg = new ProcessorArgument(" ", typeof(string)); }); }
public void ProcessorArgument_Name_Cannot_Be_Empty_String() { ExceptionAssert.ThrowsInvalidOperation( "ProcessorArgument 'name' parameter cannot be an empty string.", () => { ProcessorArgument arg = new ProcessorArgument("", typeof(string)); }); }
protected override void OnBindArguments(ProcessorArgument outArgument, ProcessorArgument inArgument) { if (this.OnBindArgumentsCalled != null) { this.OnBindArgumentsCalled(outArgument, inArgument); } base.OnBindArguments(outArgument, inArgument); }
public void PipelineBuilder_Derived_Pipeline() { MockPipelineBuilderOfMockPipeline pb = new MockPipelineBuilderOfMockPipeline(); Processor[] processors = new Processor[0]; ProcessorArgument[] inArgs = new ProcessorArgument[0]; ProcessorArgument[] outArgs = new ProcessorArgument[0]; MockPipeline pipeline = pb.Build(processors, inArgs, outArgs); }
public void ProcessorArgument_Type_Cannot_Be_Nullable() { ExceptionAssert.ThrowsInvalidOperation( "ProcessorArgument 'type' parameter cannot be a nullable type.", () => { ProcessorArgument arg = new ProcessorArgument("AName", typeof(Nullable <int>)); }); }
public void Index_Should_Be_Non_Null_After_Adding_To_A_ProcessorArgumentCollection() { ProcessorArgument arg = new ProcessorArgument("AName", typeof(int)); MockNonGenericProcessor processor = new MockNonGenericProcessor(); processor.SetInputArguments(arg); ProcessorArgumentCollection collection = processor.InArguments; Assert.AreEqual(0, arg.Index, "ProcessorArgument.Index should be 0 after being added to the ProcessorArgumentCollection."); }
public void ProcessorArgument_Properties_Cannot_Be_Null() { ExceptionAssert.ThrowsArgumentNull( "ProcessorArgument 'properties' parameter cannot be null.", "properties", () => { ProcessorArgument arg = new ProcessorArgument("AName", typeof(string), null); }); }
public void ProcessorArgument_Type_Cannot_Be_Null() { ExceptionAssert.ThrowsArgumentNull( "ProcessorArgument 'type' parameter cannot be null.", "type", () => { ProcessorArgument arg = new ProcessorArgument("AName", null); }); }
public void ProcessorArgument_Name_Cannot_Be_Null() { ExceptionAssert.ThrowsArgumentNull( "ProcessorArgument 'name' parameter cannot be null.", "name", () => { ProcessorArgument arg = new ProcessorArgument(null, typeof(string)); }); }
public void ContainingCollection_Should_Be_Non_Null_After_Adding_To_A_ProcessorArgumentCollection() { ProcessorArgument arg = new ProcessorArgument("AName", typeof(int)); MockNonGenericProcessor processor = new MockNonGenericProcessor(); processor.SetInputArguments(arg); ProcessorArgumentCollection collection = processor.InArguments; Assert.AreSame(collection, arg.ContainingCollection, "ProcessorArgument.ContainingColelction should be non-null after being added to the ProcessorArgumentCollection."); }
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 ProcessorArgumentCollection_Can_Have_Two_Arguments_With_The_Same_Name_Different_Case() { ProcessorArgument arg1 = new ProcessorArgument("AName", typeof(string)); ProcessorArgument arg2 = new ProcessorArgument("AnotherName", typeof(int)); MockNonGenericProcessor processor1 = new MockNonGenericProcessor(); processor1.SetInputArguments(arg1, arg2); ProcessorArgumentCollection processor1InArguments = processor1.InArguments; arg2.Name = "aname"; }
public void Index_Is_Case_Sensitive() { ProcessorArgument arg1 = new ProcessorArgument("AName", typeof(string)); ProcessorArgument arg2 = new ProcessorArgument("AnotherName", typeof(int)); MockNonGenericProcessor processor1 = new MockNonGenericProcessor(); processor1.SetInputArguments(arg1, arg2); ProcessorArgument processor1Arg = processor1.InArguments["Aname"]; Assert.IsNull(processor1Arg, "ProcessorArgumentCollection.Index should have returned null because the names differed by case."); }
public void Name_Cannot_Be_Set_To_All_Whitespace() { ProcessorArgument arg = new ProcessorArgument("AName", typeof(string)); ExceptionAssert.ThrowsInvalidOperation( "ProcessorArgument.Name cannot be only whitespace.", () => { arg.Name = " "; }); }
public void Index_Returns_Null_For_Non_Existing_Arguments() { ProcessorArgument arg1 = new ProcessorArgument("AName", typeof(string)); ProcessorArgument arg2 = new ProcessorArgument("AnotherName", typeof(int)); MockNonGenericProcessor processor1 = new MockNonGenericProcessor(); processor1.SetInputArguments(arg1, arg2); ProcessorArgument processor1Arg = processor1.InArguments["SomeOtherName"]; Assert.IsNull(processor1Arg, "ProcessorArgumentCollection.Index should have returned null because there is no argument with that name."); }
public void Index_Returns_Argument() { ProcessorArgument arg1 = new ProcessorArgument("AName", typeof(string)); ProcessorArgument arg2 = new ProcessorArgument("AnotherName", typeof(int)); MockNonGenericProcessor processor1 = new MockNonGenericProcessor(); processor1.SetInputArguments(arg1, arg2); ProcessorArgument processor1Arg = processor1.InArguments["AName"]; Assert.AreSame(arg1, processor1Arg, "ProcessorArgumentCollection.Index should have returned the same instance."); }
public void PipelineBuilder_Derived_Pipeline_No_Create() { MockPipelineBuilderOfMockPipelineNoCreate pb = new MockPipelineBuilderOfMockPipelineNoCreate(); Processor[] processors = new Processor[0]; ProcessorArgument[] inArgs = new ProcessorArgument[0]; ProcessorArgument[] outArgs = new ProcessorArgument[0]; ExceptionAssert.ThrowsInvalidOperation( "PipelineBuilder without appropriate OnCreate throws", () => pb.Build(processors, inArgs, outArgs) ); }
public void Name_Cannot_Be_Set_To_Null() { ProcessorArgument arg = new ProcessorArgument("AName", typeof(string)); ExceptionAssert.ThrowsArgumentNull( "ProcessorArgument.Name cannot be null.", "value", () => { arg.Name = null; }); }
public void Copy_Honors_Cloneable_Properties() { Uri uri = new Uri("http://localhost"); MockCloneableProperty cloneable = new MockCloneableProperty { Id = 5, Name = "SomeName" }; ProcessorArgument arg = new ProcessorArgument("AName", typeof(string), uri, cloneable); ProcessorArgument argCopy = arg.Copy(); Assert.AreEqual(2, argCopy.Properties.Count, "The copied ProcessorArgument should have the same properties as the original ProcessorArgument."); Assert.AreSame(uri, argCopy.Properties.Find <Uri>(), "The copied ProcessorArgument should have the same property instance as the original ProcessorArgument."); Assert.AreNotSame(cloneable, argCopy.Properties.Find <MockCloneableProperty>(), "The copied ProcessorArgument should have a new property instance."); }
public void ProcessorArgumentCollection_Cannot_Be_Created_With_The_Same_Argument_Twice() { ProcessorArgument arg1 = new ProcessorArgument("AName", typeof(string)); MockNonGenericProcessor processor1 = new MockNonGenericProcessor(); processor1.SetInputArguments(arg1, arg1); ExceptionAssert.ThrowsInvalidOperation( "Creating the argument collection with the same argument used twice should throw", () => { ProcessorArgumentCollection processor1InArguments = processor1.InArguments; }); }
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_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; }); }
public void ProcessorArgumentCollection_Cannot_Have_Two_Arguments_With_The_Same_Name() { ProcessorArgument arg1 = new ProcessorArgument("AName", typeof(string)); ProcessorArgument arg2 = new ProcessorArgument("AnotherName", typeof(int)); MockNonGenericProcessor processor1 = new MockNonGenericProcessor(); processor1.SetInputArguments(arg1, arg2); ProcessorArgumentCollection processor1InArguments = processor1.InArguments; ExceptionAssert.ThrowsInvalidOperation( "Setting the argument name to something already in the argument collection should throw", () => { arg2.Name = "AName"; }); }