public void Client_Disconnect_ServerShouldFireClientDisconnectedEvent() { // Prepare var isDisconnected = false; _server = new PipeServer(); _server.ClientDisconnectedEvent += (sender, args) => { isDisconnected = true; }; _server.Start(); Assert.IsFalse(isDisconnected); _client = new PipeClient(_server.ServerId); _client.Start(); // Act _client.Stop(); _client = null; Thread.Sleep(100); // Verify Assert.IsTrue(isDisconnected); }
public void Client_SendMessage_ServerShouldFireMessageReceivedEvent() { // Prepare _server = new PipeServer(); _client = new PipeClient(_server.ServerId); string message = null; var autoEvent = new AutoResetEvent(false); _server.MessageReceivedEvent += (sender, args) => { message = args.Message; autoEvent.Set(); }; _server.Start(); _client.Start(); // Act _client.SendMessage("Client's message"); // Verify autoEvent.WaitOne(); Assert.AreEqual("Client's message", message); }