Example #1
0
        public void Ctor_Default_Creates_Instance()
        {
            //Act
            var port = new InputNetworkPort();

            //Assert
            Assert.NotNull(port);
        }
Example #2
0
        public void Ctor_Creates_Instance_When_Parent_Element_Param_Is_Null_But_Parent_Element_Remains_Null()
        {
            //Act
            var port = new InputNetworkPort(null);

            //Assert
            Assert.NotNull(port);
            Assert.Null(port.ParentElement);
        }
 public void VerifyConnectionChangeEventHandlerIsImplementedForNetworkPipes()
 {
     // this just runs through event handlers to insure there are no notImplementedExceptions
     IInputNetworkPort port = new InputNetworkPort();
     InputPortMgr mgr = new InputPortMgr();
     mgr.Add(port);
     INetworkPipe nPipe = _pipeFactory.CreateNetworkPipe();
     port.InboundPipe = nPipe;
 }
Example #4
0
        internal IInputNetworkPort _CreateInputNetworkPort(Guid id, IElement parent)
        {
            if (parent == null)
                return null;

            IInputNetworkPort port = new InputNetworkPort(id, parent);

            return port;
        }
Example #5
0
        public void Ctor_Creates_Instance_When_Parent_Element_Param_Is_Not_Null()
        {
            //Arrange
            var port = new InputNetworkPort();
            var mockElement = new Mock<IElement>();

            //Act
            port = new InputNetworkPort(mockElement.Object);

            //Assert
            Assert.NotNull(port);
            Assert.NotNull(port.ParentElement);
        }
        public void InputPortMgrHandlesConnectionChangeEventFiredByIInputNetworkPortWhenAConnectionChanged()
        {
            IInputNetworkPort port = new InputNetworkPort();
            InputPortMgr mgr = new InputPortMgr();
            var helper = new HelperForInputPortMgr();
            mgr.ConnectionChanging += helper.ConnectionChanging_DummyHandler;
            mgr.ConnectionChanged += helper.ConnectionChanged_DummyHandler;
            mgr.Add(port);

            INetworkPipe nPipe = _pipeFactory.CreateNetworkPipe();

            port.InboundPipe = nPipe;
            Assert.Equal(1, helper.ConnectionChanging_TimesCalled);
            Assert.Equal(1, helper.ConnectionChanged_TimesCalled);
        }
Example #7
0
        public void Blob_Gets_Network_As_A_IBlob()
        {
            //Arrange
            var port = new InputNetworkPort();
            var mockData = new Mock<INetwork>();
            var mockPipe = new Mock<INetworkPipe>();

            mockPipe.Setup(m => m.NetworkObj).Returns(mockData.Object);

            port.InboundPipe = mockPipe.Object;

            //Act
            IBlob actualData = port.Blob;

            //Assert
            Assert.Same(mockData.Object, actualData);
        }
        public void SetIndex_Assigns_Port_Index_For_InputNetworkPort()
        {
            //Arrange
            IPort port = new InputNetworkPort();
            ISetIndex setter = port as ISetIndex;

            int initialIndex = port.Index;
            int actualIndex = 2;

            Assert.Equal(-1, initialIndex);

            //Act
            setter.SetIndex(actualIndex);

            //Assert
            int finalIndex = port.Index;

            Guid newId = Guid.NewGuid();
            Assert.Equal(actualIndex, finalIndex);
        }
Example #9
0
        public void InboundPipe_Gets_And_Sets_The_DataPipe()
        {
            //Arrange
            var port = new InputNetworkPort();
            var mockPipe = new Mock<INetworkPipe>();

            //Act
            port.InboundPipe = mockPipe.Object;
            INetworkPipe actual = port.InboundPipe;

            //Assert
            Assert.Same(mockPipe.Object, actual);
        }
Example #10
0
        public void InputNetwork_Gets_And_Sets_DataBlob()
        {
            //Arrange
            var port = new InputNetworkPort();
            var mockData = new Mock<INetwork>();
            var mockPipe = new Mock<INetworkPipe>();

            mockPipe.Setup(m => m.NetworkObj).Returns(mockData.Object);

            port.InboundPipe = mockPipe.Object;

            //Act
            INetwork actualData = port.InputNetwork;

            //Assert
            Assert.NotNull(actualData);
            Assert.Same(mockData.Object, actualData);
        }
Example #11
0
        public void InputNetwork_Returns_Null_If_Inbound_Pipe_Is_Not_Set()
        {
            //Arrange
            var port = new InputNetworkPort();

            //Act
            INetwork actualBlob = port.InputNetwork;

            //Assert
            Assert.Null(actualBlob);
        }
Example #12
0
        public void ParentElement_Assigns_Parent_Element()
        {
            //Arrange
            var port = new InputNetworkPort();
            var mockElement = new Mock<IElement>();

            //Act
            port.ParentElement = mockElement.Object;

            //Assert
            Assert.NotNull(port.ParentElement);
            Assert.Same(mockElement.Object, port.ParentElement);
        }
Example #13
0
        public void _inPipe_ContentStatusChangedEventHandler_Fires_Input_AvailabilityChangedEvent()
        {
            //Arrange
            var port = new InputNetworkPort();
            var helper = new HelperForInputPorts();
            var mockPipe = new Mock<INetworkPipe>();
            port.InputAvailabilityChanged += new InputAvailabilityChangedEventHandler<IInputNetworkPort, InputAvailabilityChangedEventArgs>
                                                (helper.InputAvailabilityChanged_DummyHandler);
            var ea = new PipeStatusChangeEventArgs(PayLoadStatus.Unavailable, PayLoadStatus.Available);

            //Act
            port._inPipe_ContentStatusChanged(mockPipe.Object, ea);

            //Assert
            Assert.Equal(1, helper.InputAvailabilityChanged_TimesCalled);
            Assert.NotNull(helper.RecievedEventArgs);
        }
Example #14
0
        public void SourceElement_Returns_Upstream_Element()
        {
            //Arrange
            var port = new InputNetworkPort();
            var mockEl0 = new Mock<IElement>();
            var mockPipe0 = new Mock<INetworkPipe>();

            port.InboundPipe = mockPipe0.Object;
            mockPipe0.Setup(m => m.SourceElement).Returns(mockEl0.Object);

            //Act
            IElement element = (port as InputNetworkPort).SourceElement;

            //Assert
            Assert.NotNull(element);
        }
Example #15
0
        public void SourceElement_Returns_Null_If_No_Pipes()
        {
            //Arrange
            var port = new InputNetworkPort();

            //Act
            IElement element = (port as InputNetworkPort).SourceElement;

            //Assert
            Assert.Null(element);
        }
Example #16
0
        public void Setting_InboundPipe_UnSubscribes_From_ContentStatusChangeEvent_Of_Pipe_When_Nullified()
        {
            //Arrange
            var port = new InputNetworkPort();
            var mockPipe = new Mock<INetworkPipe>();
            var mockPipe2 = new Mock<INetworkPipe>();
            var inPort = new InputNetworkPort_TestStub();

            inPort.InboundPipe = mockPipe.Object;  // initialize

            //Act
            inPort.InboundPipe = mockPipe2.Object; // replace

            // rais the event the port subscribed to
            mockPipe2.Raise(m => m.StatusChanged += null, new PipeStatusChangeEventArgs(PayLoadStatus.Unavailable, PayLoadStatus.Available));

            //Assert
            Assert.Equal(0, inPort._inPipe_ContentStatusChanged_TimesCalled);
            Assert.Null(inPort.RecievedEventArgs);
            Assert.Null(inPort.RecievedSender);
        }
Example #17
0
        public void Setting_InboundPipe_Subscribes_To_Content_StatusChangeEvent_Of_Pipe_When_Pipe_Is_Replaced()
        {
            //Arrange
            var port = new InputNetworkPort();
            var mockPipe = new Mock<INetworkPipe>();
            var mockPipe2 = new Mock<INetworkPipe>();
            var inPort = port as InputNetworkPort;
            // the event should not be fired.
            var helper = new HelperForInputPorts(); ;
            // final check is if this even is fired
            port.InputAvailabilityChanged += new InputAvailabilityChangedEventHandler<IInputNetworkPort, InputAvailabilityChangedEventArgs>
                                            (helper.InputAvailabilityChanged_DummyHandler);

            inPort.InboundPipe = mockPipe.Object;  // initialize

            //Act
            inPort.InboundPipe = mockPipe2.Object; // replace

            // raise the event the port subscribed to
            mockPipe2.Raise(m => m.StatusChanged += null, new PipeStatusChangeEventArgs(PayLoadStatus.Unavailable, PayLoadStatus.Available));

            //Assert
            Assert.Equal(1, helper.InputAvailabilityChanged_TimesCalled);
            Assert.NotNull(helper.RecievedEventArgs);
            Assert.Same(inPort, helper.RecievedSender);
        }
Example #18
0
        public void Setting_InboundPipe_Fires_The_ConnectionChangingEvent_With_Action_Set_2_Replace_Before_Value_Changes()
        {
            //Arrange
            var port = new InputNetworkPort();
            var mockPipe = new Mock<INetworkPipe>();
            var mockPipe2 = new Mock<INetworkPipe>();
            var helper = new HelperForInputPorts();
            ;
            port.ConnectionChanging += new ConnectionChangingEventHandler<IInputNetworkPort, ConnectionChangingEventArgs>
                                        (helper.InputConnecting_DummyHandler);

            port.InboundPipe = mockPipe.Object;   // set pipe, then delete it

            //Act
            port.InboundPipe = mockPipe2.Object;   // replace

            //Assert
            Assert.Equal(2, helper.InputConnecting_TimesCalled);
            var resultArgs = helper.RecievedEventArgs as ConnectionChangingEventArgs;
            Assert.NotNull(resultArgs);
            Assert.Equal(ConnectionAction.Replace, resultArgs.Action);
        }
Example #19
0
        public void Setting_InboundPipe_Fires_The_ConnectionChangedEvent_With_Action_Set_2_Delete_After_Value_Changes()
        {
            //Arrange
            var port = new InputNetworkPort();
            var mockPipe = new Mock<INetworkPipe>();
            var helper = new HelperForInputPorts();

            port.ConnectionChanged += new ConnectionChangedEventHandler<IInputNetworkPort, ConnectionChangedEventArgs>
                                        (helper.InputConnected_DummyHandler);

            port.InboundPipe = mockPipe.Object;   // set pipe, then delete it

            //Act
            port.InboundPipe = null;   // effectively deletes the connection

            //Assert
            Assert.Equal(2, helper.InputConnected_TimesCalled); // firse 2x, for each setting
            var resultArgs = helper.RecievedEventArgs as ConnectionChangedEventArgs;
            Assert.NotNull(resultArgs);
            Assert.Equal(ConnectionAction.Delete, resultArgs.Action);
        }
Example #20
0
        public void Setting_InboundPipe_Fires_The_ConnectionChangedEvent_With_Action_Set_2_Add_After_Value_Changes()
        {
            //Arrange
            var port = new InputNetworkPort();
            var mockPipe = new Mock<INetworkPipe>();
            var helper = new HelperForInputPorts();

            port.ConnectionChanged += new ConnectionChangedEventHandler<IInputNetworkPort, ConnectionChangedEventArgs>
                                        (helper.InputConnected_DummyHandler);

            //Act
            port.InboundPipe = mockPipe.Object;

            //Assert
            Assert.Equal(1, helper.InputConnected_TimesCalled);
            var resultArgs = helper.RecievedEventArgs as ConnectionChangedEventArgs;
            Assert.NotNull(resultArgs);
            Assert.Equal(ConnectionAction.Add, resultArgs.Action);
        }
Example #21
0
        public void Setting_InboundPipe_Does_Not_Fire_ConnectionChangingEvent_When_Null_Value_Does_Not_Change()
        {
            //Arrange
            var port = new InputNetworkPort();
            var helper = new HelperForInputPorts();
            port.ConnectionChanging += new ConnectionChangingEventHandler<IInputNetworkPort, ConnectionChangingEventArgs>
                                        (helper.InputConnecting_DummyHandler);

            //Act
            port.InboundPipe = null;

            //Assert
            Assert.Equal(0, helper.InputConnecting_TimesCalled);
            var resultArgs = helper.RecievedEventArgs as ConnectionChangingEventArgs;
            Assert.Null(resultArgs);
        }