Example #1
0
        public void Connect_Returns_False_And_Does_Not_Create_Connection_When_Input_Port_Is_Initial_PortAndFinalPort_Is_Null()
        {
            //Arrange
            var plumber = new DataPlumber();
            var mockDestPort = new Mock<IInputDataPort>();
            var mockSrcPort = new Mock<IOutputDataPort>();

            plumber.SetInitialPort(mockDestPort.Object);

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

            //Assert
            IDataPipe dPipe = plumber.DataPipe;
            IPipe pipe = plumber.Pipe;

            Assert.False(result);
            Assert.Null(dPipe);
            Assert.Null(pipe);
        }
Example #2
0
        public void Connect_Fires_ConnectionCreatingEvent_Before_Creating_The_Connection()
        {
            //Arrange
            var plumber = new DataPlumber();
            var helper = new HelperForPlumbers();
            plumber.ConnectionCreating += new PlumbingEventHandler(helper.ConnectionCreating_DummyHandler);

            var mockDestPort = new Mock<IInputDataPort>();
            var mockSrcPort = new Mock<IOutputDataPort>();
            var mockPipe = new Mock<IDataPipe>();

            plumber.SetInitialPort(mockDestPort.Object);
            plumber.SetFinalPort(mockSrcPort.Object);
            (plumber as DataPlumber).DataPipe = mockPipe.Object;

            //Act
            plumber.Connect();

            //Assert
            Assert.Equal(1, helper.ConnectionCreating_TimesCalled);
        }
Example #3
0
        public void SetInitialPort_With_IOutput_Port_As_Param_Sets_The_Connections_IsInitialPortSet_Flag()
        {
            //Arrange
            var plumber = new DataPlumber();
            var mockPort = new Mock<IOutputDataPort>();
            var mockOPort = mockPort.As<IOutputPort>();

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

            //Assert
            IOutputDataPort actualDataPort = plumber.SourceDataPort;
            IOutputPort actualPort = plumber.SourcePort;
            bool isInit = plumber.IsInitialPortSet;
            bool isFinal = plumber.IsFinalPortSet;

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

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

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

            //Assert
            Assert.Equal(1, helper.InitialPortSet_TimesCalled);
        }
Example #5
0
        public void Pipe_Returns_IPipeObject_Resulting_From_Connect()
        {
            //Arrange
            var plumber = new DataPlumber();
            var mockDestPort = new Mock<IInputDataPort>();
            var mockSrcPort = new Mock<IOutputDataPort>();
            var mockPipe = new Mock<IDataPipe>();

            plumber.SetInitialPort(mockSrcPort.Object);
            plumber.SetFinalPort(mockDestPort.Object);
            (plumber as DataPlumber).DataPipe = mockPipe.Object;

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

            //Assert
            IPipe pipe = plumber.Pipe;

            Assert.NotNull(pipe);
        }
Example #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 DataPlumber();
            var mockDestPort = new Mock<IInputDataPort>();
            var mockSrcPort = new Mock<IOutputDataPort>();
            var mockPipe = new Mock<IDataPipe>();

            plumber.SetInitialPort(mockSrcPort.Object);
            plumber.SetFinalPort(mockDestPort.Object);
            (plumber as DataPlumber).DataPipe = mockPipe.Object;

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

            //Assert
            Assert.True(result);
        }