public void AsynchronousData()
        {
            // Create the endpoints
            NodeEndpointInProc.EndpointPair endpoints =
                NodeEndpointInProc.CreateInProcEndpoints(
                    NodeEndpointInProc.EndpointMode.Asynchronous, _host);

            // Connect the endpoints
            endpoints.ManagerEndpoint.Listen(_host);
            endpoints.NodeEndpoint.Connect(_host);

            // Create our test packets
            INodePacket managerPacket = new TestPacket();
            INodePacket nodePacket    = new TestPacket();

            // Send data from the manager. We expect to receive it from the node endpoint, and it should
            // be on the same thread.
            endpoints.ManagerEndpoint.SendData(managerPacket);
            if (!_host.DataReceivedEvent.WaitOne(1000, false))
            {
                Assert.Fail("Data not received before timeout expired.");
            }
            Assert.IsTrue(_host.DataReceivedContext.packet == managerPacket);
            Assert.IsTrue(_host.DataReceivedContext.thread.ManagedThreadId != Thread.CurrentThread.ManagedThreadId);

            // Send data from the node.  We expect to receive it from the manager endpoint, and it should
            // be on the same thread.
            endpoints.NodeEndpoint.SendData(nodePacket);
            if (!_host.DataReceivedEvent.WaitOne(1000, false))
            {
                Assert.Fail("Data not received before timeout expired.");
            }
            Assert.IsTrue(_host.DataReceivedContext.packet == nodePacket);
            Assert.IsTrue(_host.DataReceivedContext.thread.ManagedThreadId != Thread.CurrentThread.ManagedThreadId);
        }
        public void SynchronousData()
        {
            // Create the endpoints
            NodeEndpointInProc.EndpointPair endpoints =
                NodeEndpointInProc.CreateInProcEndpoints(
                    NodeEndpointInProc.EndpointMode.Synchronous, _host);

            // Connect the endpoints
            endpoints.ManagerEndpoint.Listen(_host);
            endpoints.NodeEndpoint.Connect(_host);

            // Create our test packets
            INodePacket managerPacket = new TestPacket();
            INodePacket nodePacket    = new TestPacket();

            // Send data from the manager. We expect to receive it from the node endpoint, and it should
            // be on the same thread.
            endpoints.ManagerEndpoint.SendData(managerPacket);
            Assert.Equal(_host.DataReceivedContext.packet, managerPacket);
            Assert.Equal(_host.DataReceivedContext.thread.ManagedThreadId, Thread.CurrentThread.ManagedThreadId);

            // Send data from the node.  We expect to receive it from the manager endpoint, and it should
            // be on the same thread.
            endpoints.NodeEndpoint.SendData(nodePacket);
            Assert.Equal(_host.DataReceivedContext.packet, nodePacket);
            Assert.Equal(_host.DataReceivedContext.thread.ManagedThreadId, Thread.CurrentThread.ManagedThreadId);
        }
 public void ConstructionAsynchronousWithInvalidHost()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         NodeEndpointInProc.CreateInProcEndpoints(
             NodeEndpointInProc.EndpointMode.Asynchronous, null);
     }
                                           );
 }
        public void ConstructionWithValidHost()
        {
            NodeEndpointInProc.EndpointPair endpoints =
                NodeEndpointInProc.CreateInProcEndpoints(
                    NodeEndpointInProc.EndpointMode.Synchronous, _host);

            endpoints =
                NodeEndpointInProc.CreateInProcEndpoints(
                    NodeEndpointInProc.EndpointMode.Asynchronous, _host);
        }
        private NodeEndpointInProc.EndpointPair SetupConnection(NodeEndpointInProc.EndpointMode mode)
        {
            NodeEndpointInProc.EndpointPair endpoints =
                NodeEndpointInProc.CreateInProcEndpoints(mode, _host);

            endpoints.ManagerEndpoint.OnLinkStatusChanged += LinkStatusChanged;
            endpoints.NodeEndpoint.OnLinkStatusChanged    += LinkStatusChanged;

            // Call listen.  This shouldn't have any effect on the link statuses.
            endpoints.ManagerEndpoint.Listen(_host);
            endpoints.NodeEndpoint.Connect(_host);

            return(endpoints);
        }
        private void VerifyDisconnectInvalidOperation(NodeEndpointInProc endpoint)
        {
            bool caught = false;

            try
            {
                endpoint.Disconnect();
            }
            catch (InternalErrorException)
            {
                caught = true;
            }
            Assert.True(caught); // "Did not receive InternalErrorException."
        }
        public void InactiveLinkTestSynchronous()
        {
            NodeEndpointInProc.EndpointPair endpoints =
                NodeEndpointInProc.CreateInProcEndpoints(
                    NodeEndpointInProc.EndpointMode.Synchronous, _host);

            CallOpOnEndpoints(endpoints, VerifyLinkInactive);
            CallOpOnEndpoints(endpoints, VerifySendDataInvalidOperation);
            CallOpOnEndpoints(endpoints, VerifyDisconnectInvalidOperation);

            // The following should not throw
            endpoints.ManagerEndpoint.Listen(_host);
            endpoints.NodeEndpoint.Connect(_host);
        }
        private void VerifySendDataInvalidOperation(NodeEndpointInProc endpoint)
        {
            bool caught = false;

            try
            {
                endpoint.SendData(new TestPacket());
            }
            catch (InternalErrorException)
            {
                caught = true;
            }

            Assert.True(caught); // "Did not receive InternalErrorException."
        }
        public void ConnectionTestSynchronous()
        {
            NodeEndpointInProc.EndpointPair endpoints =
                NodeEndpointInProc.CreateInProcEndpoints(
                    NodeEndpointInProc.EndpointMode.Synchronous, _host);

            endpoints.ManagerEndpoint.OnLinkStatusChanged += LinkStatusChanged;
            endpoints.NodeEndpoint.OnLinkStatusChanged    += LinkStatusChanged;

            // Call listen.  This shouldn't have any effect on the link statuses.
            endpoints.ManagerEndpoint.Listen(_host);
            CallOpOnEndpoints(endpoints, VerifyLinkInactive);
            // No link status callback should have occurred.
            Assert.False(_linkStatusTable.ContainsKey(endpoints.NodeEndpoint));
            Assert.False(_linkStatusTable.ContainsKey(endpoints.ManagerEndpoint));

            // Now call connect on the node side.  This should activate the link on both ends.
            endpoints.NodeEndpoint.Connect(_host);
            CallOpOnEndpoints(endpoints, VerifyLinkActive);

            // We should have received callbacks informing us of the link change.
            Assert.Equal(LinkStatus.Active, _linkStatusTable[endpoints.NodeEndpoint].status);
            Assert.Equal(LinkStatus.Active, _linkStatusTable[endpoints.ManagerEndpoint].status);
        }
 private void VerifyLinkActive(NodeEndpointInProc endpoint)
 {
     Assert.Equal(LinkStatus.Active, endpoint.LinkStatus); // "Expected LinkStatus to be Active"
 }
 private void VerifyConnectCallSuccess(NodeEndpointInProc endpoint)
 {
     endpoint.Connect(_host);
     Assert.Equal(endpoint.LinkStatus, LinkStatus.Active);
 }
 private void VerifyListenCallSuccess(NodeEndpointInProc endpoint)
 {
     endpoint.Listen(_host);
 }
 private void VerifyLinkInactive(NodeEndpointInProc endpoint)
 {
     Assert.Equal(endpoint.LinkStatus, LinkStatus.Inactive); // "Expected LinkStatus to be Inactive"
 }
 private void VerifyLinkActive(NodeEndpointInProc endpoint)
 {
     Assert.IsTrue(endpoint.LinkStatus == LinkStatus.Active, "Expected LinkStatus to be Active");
 }
 public void ConstructionAsynchronousWithInvalidHost()
 {
     NodeEndpointInProc.EndpointPair endpoints =
         NodeEndpointInProc.CreateInProcEndpoints(
             NodeEndpointInProc.EndpointMode.Asynchronous, null);
 }