public void FindReceiver_GivenThereIsAReceiverOnBothOutletsAndTheTieBreakerResolvesToRight_UsesTheRightReceiver() { // Arrange var mockLeftPipe = PipeHelpers.CreateMockPipe <int>(); var mockRightPipe = PipeHelpers.CreateMockPipe <int>(); var mockLeftPipeInlet = (IInlet <int>)mockLeftPipe.Object.ConnectableInlets.Single(); var mockRightPipeInlet = (IInlet <int>)mockRightPipe.Object.ConnectableInlets.Single(); eitherOutletPipe.LeftOutlet.ConnectTo(mockLeftPipeInlet); eitherOutletPipe.RightOutlet.ConnectTo(mockRightPipeInlet); Action <int> leftReceiver = m => { }; var receivedMessage = 0; Action <int> rightReceiver = m => { receivedMessage = m; }; mockLeftPipe.Setup(p => p.FindReceiver(mockLeftPipeInlet)).Returns(leftReceiver); mockRightPipe.Setup(p => p.FindReceiver(mockRightPipeInlet)).Returns(rightReceiver); tieBreaker.Setup(t => t.ResolveTie()).Returns(TieResult.Right); // Act var sender = eitherOutletPipe.FindReceiver(eitherOutletPipe.Inlet); const int message = 1313; sender(message); // Assert receivedMessage.Should().Be(message); }
public void FindSender_GivenThereIsASenderOnBothInletsAndTheTieBreakerResolvesToRight_UsesTheRightSender() { // Arrange var mockLeftPipe = PipeHelpers.CreateMockPipe <int>(); var mockRightPipe = PipeHelpers.CreateMockPipe <int>(); var mockLeftPipeOutlet = (IOutlet <int>)mockLeftPipe.Object.ConnectableOutlets.Single(); var mockRightPipeOutlet = (IOutlet <int>)mockRightPipe.Object.ConnectableOutlets.Single(); eitherInletPipe.LeftInlet.ConnectTo(mockLeftPipeOutlet); eitherInletPipe.RightInlet.ConnectTo(mockRightPipeOutlet); Func <int> leftSender = () => 3; const int message = 4; Func <int> rightSender = () => message; mockLeftPipe.Setup(p => p.FindSender(mockLeftPipeOutlet)).Returns(leftSender); mockRightPipe.Setup(p => p.FindSender(mockRightPipeOutlet)).Returns(rightSender); tieBreaker.Setup(t => t.ResolveTie()).Returns(TieResult.Right); // Act var sender = eitherInletPipe.FindSender(eitherInletPipe.Outlet); // Assert sender().Should().Be(message); }
public void FindSender_GivenThereIsAPipeConnectedToItsInlet_AsksThatPipeForASender() { // Arrange var mockPipe = PipeHelpers.CreateMockPipe <int>(); var mockOutlet = (IOutlet <int>)mockPipe.Object.ConnectableOutlets.Single(); capacityZeroPipe.Inlet.ConnectTo(mockOutlet); // Act capacityZeroPipe.FindSender(capacityZeroPipe.Outlet); // Assert mockPipe.Verify(p => p.FindSender(mockOutlet)); }
public void FindReceiver_GivenThereIsAPipeConnectedToItsRightOutlet_AsksThatPipeForAReceiver() { // Arrange var mockPipe = PipeHelpers.CreateMockPipe <int>(); var mockInlet = (IInlet <int>)mockPipe.Object.ConnectableInlets.Single(); eitherOutletPipe.RightOutlet.ConnectTo(mockInlet); // Act eitherOutletPipe.FindReceiver(eitherOutletPipe.Inlet); // Assert mockPipe.Verify(p => p.FindReceiver(mockInlet)); }
public void FindReceiver_GivenThereIsAPipeConnectedToItsOutlet_AsksThatPipeForAReceiver() { // Arrange var mockPipe = PipeHelpers.CreateMockPipe <string>(); var mockInlet = (IInlet <string>)mockPipe.Object.ConnectableInlets.Single(); transformPipe.Outlet.ConnectTo(mockInlet); // Act transformPipe.FindReceiver(transformPipe.Inlet); // Assert mockPipe.Verify(p => p.FindReceiver(mockInlet)); }
public void FindReceiver_GivenThePipeHasAReceiverFromAConnectedPipe_PrefersThatReceiver() { // Arrange var mockPipe = PipeHelpers.CreateMockPipe <int>(); var mockInlet = (IInlet <int>)mockPipe.Object.ConnectableInlets.Single(); capacityThreePipe.Outlet.ConnectTo(mockInlet); var receivedMessage = 0; var expectedReceiver = new Action <int>(m => { receivedMessage = m; }); mockPipe.Setup(p => p.FindReceiver(mockInlet)).Returns(expectedReceiver); // Act var actualReceiver = capacityThreePipe.FindReceiver(capacityThreePipe.Inlet); const int message = 15; actualReceiver(message); // Assert receivedMessage.Should().Be(message); }
protected PipeArgument(PipeDirection direction) { PipeName = PipeHelpers.GetUnqiuePipeName(); _direction = direction; }