Exemplo n.º 1
0
        public void FindSender_GivenThereIsNoSender_ReturnsNull()
        {
            // Act
            var sender = capacityZeroPipe.FindSender(capacityZeroPipe.Outlet);

            // Assert
            sender.Should().BeNull();
        }
Exemplo n.º 2
0
        public void FindSender_GivenThePipeIsHoldingAMessage_ReturnsThatMessage()
        {
            // Arrange
            const int message = 14;

            capacityThreePipe.Inlet.Send(message);

            // Act
            var sender = capacityThreePipe.FindSender(capacityThreePipe.Outlet);

            // Assert
            sender.Should().NotBeNull();
            sender().Should().Be(message);
        }
Exemplo n.º 3
0
        public void FindSender_AppliedToConnectedCapacityPipes_ReturnsTheMessagesFromAllConnectedPipesInTheRightOrder()
        {
            // Arrange
            capacityThreePipe.Outlet.ConnectTo(capacityTwoPipe.Inlet);

            const int expectedFirstMessage  = 1;
            const int expectedSecondMessage = 2;
            const int expectedThirdMessage  = 3;
            const int expectedFourthMessage = 4;
            const int expectedFifthMessage  = 5;
            const int expectedSixthMessage  = 6;

            capacityThreePipe.FindReceiver(capacityThreePipe.Inlet)(expectedFirstMessage);
            capacityThreePipe.FindReceiver(capacityThreePipe.Inlet)(expectedSecondMessage);
            capacityThreePipe.FindReceiver(capacityThreePipe.Inlet)(expectedThirdMessage);
            capacityThreePipe.FindReceiver(capacityThreePipe.Inlet)(expectedFourthMessage);
            capacityThreePipe.FindReceiver(capacityThreePipe.Inlet)(expectedFifthMessage);

            var thread = new Thread(() => capacityThreePipe.Inlet.Send(expectedSixthMessage));

            thread.Start();
            Thread.Sleep(500);

            // Act
            var actualFirstMessage  = capacityTwoPipe.FindSender(capacityTwoPipe.Outlet)();
            var actualSecondMessage = capacityTwoPipe.FindSender(capacityTwoPipe.Outlet)();
            var actualThirdMessage  = capacityTwoPipe.FindSender(capacityTwoPipe.Outlet)();
            var actualFourthMessage = capacityTwoPipe.FindSender(capacityTwoPipe.Outlet)();
            var actualFifthMessage  = capacityTwoPipe.FindSender(capacityTwoPipe.Outlet)();
            var actualSixthMessage  = capacityTwoPipe.FindSender(capacityTwoPipe.Outlet)();

            // Assert
            actualFirstMessage.Should().Be(expectedFirstMessage);
            actualSecondMessage.Should().Be(expectedSecondMessage);
            actualThirdMessage.Should().Be(expectedThirdMessage);
            actualFourthMessage.Should().Be(expectedFourthMessage);
            actualFifthMessage.Should().Be(expectedFifthMessage);
            actualSixthMessage.Should().Be(expectedSixthMessage);
        }