public void NewSocketDisconnectsOldHandler() { var testHandlerFactory = new TestMessageHandlerFactory(); using (var server = StartServer(testHandlerFactory)) { var socket1 = ConnectSocket(); testHandlerFactory.WaitForMessageHandlerCreated(); var handler1 = testHandlerFactory.LatestHandler; handler1.WaitForConnect(); handler1.AssertNoWaitingEvents(); var socket2 = ConnectSocket(); testHandlerFactory.WaitForMessageHandlerCreated(); var handler2 = testHandlerFactory.LatestHandler; handler2.WaitForConnect(); handler2.AssertNoWaitingEvents(); handler1.WaitForDisconnect(); handler1.AssertNoWaitingEvents(); Assert.IsTrue(handler1.DisposeCalled); testHandlerFactory.AssertNoWaitingEvents(); } }
public void ReceiveEmptyMessage_SendEmptyResponse() { var testHandlerFactory = new TestMessageHandlerFactory(); using (var server = StartServer(testHandlerFactory)) { var socket = ConnectSocket(); testHandlerFactory.WaitForMessageHandlerCreated(); var latestHandler = testHandlerFactory.LatestHandler; latestHandler.WaitForConnect(); latestHandler.AssertNoWaitingEvents(); // socket => server: socket.Send(new byte[] { 0x00, 0x01, 0xFF }); // 1 length message latestHandler.WaitForMessage(); var msg = latestHandler.LastMessage; latestHandler.AssertNoWaitingEvents(); // server => socket: latestHandler.Sink.SendMessageAsync(msg).AsTask().Wait(); var response = ReadPayloadFromSocket(socket); Assert.AreEqual(1, response.Length); Assert.AreEqual(0xFF, response[0]); latestHandler.AssertNoWaitingEvents(); testHandlerFactory.AssertNoWaitingEvents(); } }
public void CloseSocketDisconnectsHandler() { var testHandlerFactory = new TestMessageHandlerFactory(); using (var server = StartServer(testHandlerFactory)) { var socket = ConnectSocket(); testHandlerFactory.WaitForMessageHandlerCreated(); var latestHandler = testHandlerFactory.LatestHandler; latestHandler.WaitForConnect(); latestHandler.AssertNoWaitingEvents(); socket.Close(); latestHandler.WaitForDisconnect(); latestHandler.AssertNoWaitingEvents(); Thread.Sleep(100); Assert.IsTrue(latestHandler.DisposeCalled); testHandlerFactory.AssertNoWaitingEvents(); } }