public void TransmitTest() { //Arrange var objWebSocketClient = Substitute.For <IWebSocketClient>(); var objKeepAliveMonitor = Substitute.For <IKeepAliveMonitor>(); var objClient = new WebsocketClient(objWebSocketClient, objKeepAliveMonitor); objClient.ConnectAsync(new ClientParams() { HostName = "localhost", Port = 80, Secure = false }); objWebSocketClient.Received().OnOpen += Raise.EventWith(objWebSocketClient, new EventArgs()); //Act objClient.Transmit(new byte[] { 1, 2, 3, 4 }); Thread.Sleep(50); //-- wait a bit so the sender queue can call the IWebSocketClient.Send() method //Assert objWebSocketClient.Received(1).SendAsync(Arg.Is <byte[]>(b => b.SequenceEqual(new byte[] { 1, 2, 3, 4 }))); }