public virtual void Duplex_09_StopListening_SendMessage() { ClientMock aClient = new ClientMock(MessagingSystemFactory, ChannelId); ServiceMock aService = new ServiceMock(MessagingSystemFactory, ChannelId); try { aService.InputChannel.StartListening(); aClient.OutputChannel.OpenConnection(); aService.WaitUntilResponseReceiversConnectNotified(1, 1000); aService.InputChannel.StopListening(); Assert.IsFalse(aService.InputChannel.IsListening); bool isSomeException = false; try { // Try to send a message via the duplex output channel. aClient.OutputChannel.SendMessage(myRequestMessage); } catch { // Because the duplex input channel is not listening the sending must // fail with an exception. The type of the exception depends from the type of messaging system. isSomeException = true; } Assert.IsTrue(isSomeException); } finally { EneterTrace.Debug("CLEANING AFTER TEST"); aClient.OutputChannel.CloseConnection(); aService.InputChannel.StopListening(); // Wait for traces. Thread.Sleep(100); } }
public virtual void Duplex_13_DisconnectFromResponseReceiverConnected() { ClientMock aClient = new ClientMock(MessagingSystemFactory, ChannelId); ServiceMock aService = new ServiceMock(MessagingSystemFactory, ChannelId); aService.DoOnResponseReceiverConnected((x, y) => { if (MessagingSystemFactory is SynchronousMessagingSystemFactory == false) { aClient.WaitUntilConnectionOpenIsNotified(1000); } aService.InputChannel.DisconnectResponseReceiver(y.ResponseReceiverId); }); try { aService.InputChannel.StartListening(); // The ecent will try to close connection. aClient.OutputChannel.OpenConnection(); aClient.WaitUntilConnectionOpenIsNotified(1000); //aService.WaitUntilAllResponseReceiversDisconnectNotified(1000); aClient.WaitUntilConnectionClosedIsNotified(1000); } finally { EneterTrace.Debug("CLEANING AFTER TEST"); aClient.OutputChannel.CloseConnection(); aService.InputChannel.StopListening(); // Wait for traces. Thread.Sleep(100); } }
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); } }
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); } }