Beispiel #1
0
        public IPlumber CreatePlumber(IPipe pipe)
        {
            IPlumber plumber = null;

            if (pipe != null)
            {
                if (pipe is IDataPipe)
                {
                    plumber = new DataPlumber();
                }
                else if (pipe is INetworkPipe)
                {
                    plumber = new NetworkPlumber();
                }
            }

            return plumber;
        }
Beispiel #2
0
        public IPlumber CreatePlumber(IOutputPort port)
        {
            IPlumber plumber = null;

            if (port != null)
            {
                if (port is IOutputDataPort)
                {
                    plumber = new DataPlumber();
                }
                else if (port is IOutputNetworkPort)
                {
                    plumber = new NetworkPlumber();
                }
            }

            return plumber;
        }
Beispiel #3
0
        public void Connect_Returns_False_And_Does_Not_Create_Connection_When_Input_Port_Is_Initial_PortAndFinalPort_Is_Null()
        {
            //Arrange
            var plumber = new NetworkPlumber();
            var mockDestPort = new Mock<IInputNetworkPort>();
            var mockSrcPort = new Mock<IOutputNetworkPort>();

            plumber.SetInitialPort(mockDestPort.Object);

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

            //Assert
            INetworkPipe dPipe = plumber.NetworkPipe;
            IPipe pipe = plumber.Pipe;

            Assert.False(result);
            Assert.Null(dPipe);
            Assert.Null(pipe);
        }
Beispiel #4
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 #5
0
        public void SetInitialPort_With_IOutput_Port_As_Param_Sets_The_Connections_IsInitialPortSet_Flag()
        {
            //Arrange
            var plumber = new NetworkPlumber();
            var mockPort = new Mock<IOutputNetworkPort>();
            var mockOPort = mockPort.As<IOutputPort>();

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

            //Assert
            IOutputNetworkPort actualNetworkPort = plumber.SourceNetworkPort;
            IOutputPort actualPort = plumber.SourcePort;
            bool isInit = plumber.IsInitialPortSet;
            bool isFinal = plumber.IsFinalPortSet;

            Assert.NotNull(actualNetworkPort);
            Assert.NotNull(actualPort);
            Assert.Same(mockPort.Object, actualNetworkPort);
            Assert.Same(mockPort.Object, actualPort);
            Assert.True(isInit);
            Assert.False(isFinal);
        }
Beispiel #6
0
        public void SetInitialPort_With_IOutputPort_Fires_InitialPortSet_Event()
        {
            //Arrange
            var plumber = new NetworkPlumber();
            var helper = new HelperForPlumbers();
            plumber.InitialPortSet += new PortSetEventHandler(helper.InitialPortSet_DummyHandler);

            var mockPort = new Mock<IOutputNetworkPort>();
            var mockOPort = mockPort.As<IOutputPort>();

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

            //Assert
            Assert.Equal(1, helper.InitialPortSet_TimesCalled);
        }
Beispiel #7
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 #8
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 #9
0
        public void Reset_Resets_The_Plumber_For_A_New_Connection_Creation()
        {
            //Arrange
            var plumber = new NetworkPlumber();
            var mockDestPort = new Mock<IInputNetworkPort>();
            var mockSrcPort = new Mock<IOutputNetworkPort>();
            var mockPipe = new Mock<INetworkPipe>();

            (plumber as NetworkPlumber).NetworkPipe = mockPipe.Object;

            //Act
            plumber.Reset();

            //Assert
            IInputPort actualDestPort = plumber.DestinationPort;
            IOutputPort actualSrcPort = plumber.SourcePort;
            IInputNetworkPort actualDestNetworkPort = plumber.DestinationNetworkPort;
            IOutputNetworkPort actualSrcNetworkPort = plumber.SourceNetworkPort;
            IPipe actualPipe = plumber.Pipe;
            INetworkPipe actualNetworkPipe = plumber.NetworkPipe;

            Assert.Null(actualNetworkPipe);
            Assert.Null(actualPipe);
            Assert.Null(actualDestNetworkPort);
            Assert.Null(actualSrcNetworkPort);
            Assert.Null(actualDestPort);
            Assert.Null(actualSrcPort);
        }
Beispiel #10
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 #11
0
 public void Ctor_Default_Creates_Instance()
 {
     //Arrange
     var plumber = new NetworkPlumber();
     Assert.NotNull(plumber);
 }
Beispiel #12
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);
        }