Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
 protected PipeArgument(PipeDirection direction)
 {
     PipeName   = PipeHelpers.GetUnqiuePipeName();
     _direction = direction;
 }