コード例 #1
0
        public virtual void Duplex_08_OpenFromConnectionClosed()
        {
            ClientMock aClient = new ClientMock(MessagingSystemFactory, ChannelId);

            bool anIsConnected = false;

            aClient.DoOnConnectionClosed((x, y) =>
            {
                EneterTrace.Debug("DoOnConnectionClosed");

                anIsConnected = aClient.OutputChannel.IsConnected;

                if (MessagingSystemFactory is SharedMemoryMessagingSystemFactory)
                {
                    Thread.Sleep(300);
                }

                aClient.OutputChannel.OpenConnection();
            });

            ServiceMock aService = new ServiceMock(MessagingSystemFactory, ChannelId);

            try
            {
                aService.InputChannel.StartListening();

                // Client opens the connection.
                aClient.OutputChannel.OpenConnection();

                aClient.WaitUntilConnectionOpenIsNotified(1000);
                Assert.IsFalse(anIsConnected);

                aService.WaitUntilResponseReceiversConnectNotified(1, 1000);
                string aConnectedResponseReceiverId = aService.ConnectedResponseReceivers[0].ResponseReceiverId;

                aClient.ClearTestResults();
                aService.ClearTestResults();

                // Service disconnects the client.
                aService.InputChannel.DisconnectResponseReceiver(aConnectedResponseReceiverId);

                //aService.WaitUntilResponseRecieverIdDisconnectNotified(aConnectedResponseReceiverId, 1000);
                aClient.WaitUntilConnectionClosedIsNotified(3000);
                //Assert.AreEqual(aConnectedResponseReceiverId, aService.DisconnectedResponseReceivers[0].ResponseReceiverId);

                // Client should open the connection again.
                aClient.WaitUntilConnectionOpenIsNotified(1000);

                if (MessagingSystemFactory is SynchronousMessagingSystemFactory == false)
                {
                    aService.WaitUntilResponseReceiversConnectNotified(1, 1000);
                }
            }
            finally
            {
                EneterTrace.Debug("CLEANING AFTER TEST");

                aClient.OutputChannel.CloseConnection();
                aService.InputChannel.StopListening();

                // Wait for traces.
                Thread.Sleep(500);
            }
        }
コード例 #2
0
        public virtual void Duplex_06_OpenCloseOpenSend()
        {
            ClientMock  aClient  = new ClientMock(MessagingSystemFactory, ChannelId);
            ServiceMock aService = new ServiceMock(MessagingSystemFactory, ChannelId);

            aService.DoOnMessageReceived_SendResponse(myResponseMessage);

            try
            {
                aService.InputChannel.StartListening();

                // Client opens the connection.
                aClient.OutputChannel.OpenConnection();
                Assert.IsTrue(aClient.OutputChannel.IsConnected);

                aClient.WaitUntilConnectionOpenIsNotified(1000);
                Assert.AreEqual(aClient.OutputChannel.ChannelId, aClient.NotifiedOpenConnection.ChannelId);
                Assert.AreEqual(aClient.OutputChannel.ResponseReceiverId, aClient.NotifiedOpenConnection.ResponseReceiverId);

                aService.WaitUntilResponseReceiversConnectNotified(1, 1000);
                Assert.AreEqual(1, aService.ConnectedResponseReceivers.Count());
                if (CompareResponseReceiverId)
                {
                    Assert.AreEqual(aClient.OutputChannel.ResponseReceiverId, aService.ConnectedResponseReceivers[0].ResponseReceiverId);
                }

                // Client closes the connection.
                aClient.OutputChannel.CloseConnection();
                Assert.IsFalse(aClient.OutputChannel.IsConnected);

                //aClient.WaitUntilConnectionClosedIsNotified(1000);
                //Assert.AreEqual(aClient.OutputChannel.ChannelId, aClient.NotifiedCloseConnection.ChannelId);
                //Assert.AreEqual(aClient.OutputChannel.ResponseReceiverId, aClient.NotifiedCloseConnection.ResponseReceiverId);

                aService.WaitUntilAllResponseReceiversDisconnectNotified(3000);
                Assert.AreEqual(1, aService.DisconnectedResponseReceivers.Count());
                if (CompareResponseReceiverId)
                {
                    Assert.AreEqual(aClient.OutputChannel.ResponseReceiverId, aService.DisconnectedResponseReceivers[0].ResponseReceiverId);
                }

                aClient.ClearTestResults();
                aService.ClearTestResults();


                // Client opens the connection 2nd time.
                aClient.OutputChannel.OpenConnection();
                Assert.IsTrue(aClient.OutputChannel.IsConnected);

                aClient.WaitUntilConnectionOpenIsNotified(1000);
                Assert.AreEqual(aClient.OutputChannel.ChannelId, aClient.NotifiedOpenConnection.ChannelId);
                Assert.AreEqual(aClient.OutputChannel.ResponseReceiverId, aClient.NotifiedOpenConnection.ResponseReceiverId);

                aService.WaitUntilResponseReceiversConnectNotified(1, 1000);
                Assert.AreEqual(1, aService.ConnectedResponseReceivers.Count());
                if (CompareResponseReceiverId)
                {
                    Assert.AreEqual(aClient.OutputChannel.ResponseReceiverId, aService.ConnectedResponseReceivers[0].ResponseReceiverId);
                }

                // Client sends the message.
                aClient.OutputChannel.SendMessage(myRequestMessage);

                aClient.WaitUntilResponseMessagesAreReceived(1, 1000);

                Assert.AreEqual(myRequestMessage, aService.ReceivedMessages.First().Message);
                Assert.AreEqual(myResponseMessage, aClient.ReceivedMessages.First().Message);
            }
            finally
            {
                EneterTrace.Debug("CLEANING AFTER TEST");

                aClient.OutputChannel.CloseConnection();
                aService.InputChannel.StopListening();

                // Wait for traces.
                Thread.Sleep(100);
            }
        }