public static void Execute___Should_return_registered_protocol___When_called() { // Arrange var systemUnderTest = new ChainOfResponsibilityProtocolFactory(); IProtocol protocol1 = new SharedOperationProtocol1(); IProtocol protocol2 = new SiblingOperationProtocol(); IProtocol protocol3 = new SharedOperationProtocol2(); var protocolFactory1 = protocol1.ToProtocolFactory(); var protocolFactory2 = protocol2.ToProtocolFactory(); var protocolFactory3 = protocol3.ToProtocolFactory(); systemUnderTest.AddToEndOfChain(protocolFactory1); systemUnderTest.AddToEndOfChain(protocolFactory2); systemUnderTest.AddToEndOfChain(protocolFactory3); var operation1 = new GetProtocolOp(new SharedOperation()); var operation2 = new GetProtocolOp(new SiblingOperation1()); var operation3 = new GetProtocolOp(new SiblingOperation2()); // Act var actual1 = systemUnderTest.Execute(operation1); var actual2 = systemUnderTest.Execute(operation2); var actual3 = systemUnderTest.Execute(operation3); // Assert actual1.AsTest().Must().BeSameReferenceAs(protocol1); actual2.AsTest().Must().BeSameReferenceAs(protocol2); actual3.AsTest().Must().BeSameReferenceAs(protocol2); }
public static void Constructor___Should_register_protocol_factories_in_order_specified___When_called() { // Arrange IProtocol protocol1 = new SharedOperationProtocol1(); IProtocol protocol2 = new SiblingOperationProtocol(); IProtocol protocol3 = new SharedOperationProtocol2(); var protocolFactory1 = protocol1.ToProtocolFactory(); var protocolFactory2 = protocol2.ToProtocolFactory(); var protocolFactory3 = protocol3.ToProtocolFactory(); var systemUnderTest = new ChainOfResponsibilityProtocolFactory(new[] { protocolFactory1, protocolFactory2, protocolFactory3 }); var operation1 = new GetProtocolOp(new SharedOperation()); var operation2 = new GetProtocolOp(new SiblingOperation1()); var operation3 = new GetProtocolOp(new SiblingOperation2()); // Act var actual1 = systemUnderTest.Execute(operation1); var actual2 = systemUnderTest.Execute(operation2); var actual3 = systemUnderTest.Execute(operation3); // Assert actual1.AsTest().Must().BeSameReferenceAs(protocol1); actual2.AsTest().Must().BeSameReferenceAs(protocol2); actual3.AsTest().Must().BeSameReferenceAs(protocol2); }