Beispiel #1
0
        public void Connect_Fires_ConnectionCreatingEvent_Before_Creating_The_Connection()
        {
            //Arrange
            var plumber = new NetworkPlumber();
            var helper = new HelperForPlumbers();
            plumber.ConnectionCreating += new PlumbingEventHandler(helper.ConnectionCreating_DummyHandler);

            var mockDestPort = new Mock<IInputNetworkPort>();
            var mockSrcPort = new Mock<IOutputNetworkPort>();
            var mockPipe = new Mock<INetworkPipe>();

            plumber.SetInitialPort(mockDestPort.Object);
            plumber.SetFinalPort(mockSrcPort.Object);
            (plumber as NetworkPlumber).NetworkPipe = mockPipe.Object;

            //Act
            plumber.Connect();

            //Assert
            Assert.Equal(1, helper.ConnectionCreating_TimesCalled);
        }
Beispiel #2
0
        public void SetFinalPort_With_IOutput_Port_As_Param()
        {
            //Arrange
            var plumber = new NetworkPlumber();
            var mockInitPort = new Mock<IInputPort>();
            plumber.InitialPort = mockInitPort.Object;
            var mockPort = new Mock<IOutputPort>();

            //Act
            plumber.SetFinalPort(mockPort.Object);

            //Assert
            Assert.True(plumber.IsInitialPortSet);
        }
Beispiel #3
0
        public void SetFinalPort_With_IOutputPort_Fires_FinalPortSetEvent()
        {
            //Arrange
            var plumber = new NetworkPlumber();
            var helper = new HelperForPlumbers();
            plumber.FinalPortSet += new PortSetEventHandler(helper.FinalPortSet_DummyHandler);

            var mockInitPort = new Mock<IInputPort>();
            plumber.InitialPort = mockInitPort.Object;
            var mockPort = new Mock<IOutputNetworkPort>();
            var mockOPort = mockPort.As<IOutputPort>();

            //Act
            plumber.SetFinalPort(mockOPort.Object);

            //Assert
            Assert.Equal(1, helper.FinalPortSet_TimesCalled);
        }
Beispiel #4
0
        public void SetFinalPort_With_IOutputPort_As_Param_Throws_Ex_If_Init_Port_Not_Yet_Sett()
        {
            //Arrange
            var plumber = new NetworkPlumber();
            var mockPort = new Mock<IOutputPort>();

            //Act, Assert
            var ex = Assert.Throws<InvalidOperationException>(() => plumber.SetFinalPort(mockPort.Object));
        }
Beispiel #5
0
        public void Pipe_Returns_IPipeObject_Resulting_From_Connect()
        {
            //Arrange
            var plumber = new NetworkPlumber();
            var mockDestPort = new Mock<IInputNetworkPort>();
            var mockSrcPort = new Mock<IOutputNetworkPort>();
            var mockPipe = new Mock<INetworkPipe>();

            plumber.SetInitialPort(mockSrcPort.Object);
            plumber.SetFinalPort(mockDestPort.Object);
            (plumber as NetworkPlumber).NetworkPipe = mockPipe.Object;

            //Act
            bool result = plumber.Connect();

            //Assert
            IPipe pipe = plumber.Pipe;

            Assert.NotNull(pipe);
        }
Beispiel #6
0
        public void Connect_Returns_True_And_Creates_Connection_When_Output_Port_Is_Initial_Port_Then_Input_Port_Is_Final_Port()
        {
            //Arrange
            var plumber = new NetworkPlumber();
            var mockDestPort = new Mock<IInputNetworkPort>();
            var mockSrcPort = new Mock<IOutputNetworkPort>();
            var mockPipe = new Mock<INetworkPipe>();

            plumber.SetInitialPort(mockSrcPort.Object);
            plumber.SetFinalPort(mockDestPort.Object);
            (plumber as NetworkPlumber).NetworkPipe = mockPipe.Object;

            //Act
            bool result = plumber.Connect();

            //Assert
            Assert.True(result);
        }