public void RcpMethod_ExistingMethod_InvokedAndTaskResultReturned() { // ARRANGE var jsonRpcMethodRequest = new JsonRpcRequest { Id = 1, Method = "TestMethod23", Params = new List <string>() }; var jsonRpcMethod = jsonRpcMethodRequest.ToString(); JObject result = null; _webSocketMock.Setup(m => m.SendAsync(It.IsAny <string>())) .Returns(Task.CompletedTask) .Callback((string s) => { _webSocketMock.Setup(m => m.WebSocketState).Returns(JsonRpcWebSocketState.Closed); result = JObject.Parse(s); }); _webSocketMock.Setup( m => m.ReceiveAsync(CancellationToken.None)) .Returns(() => Task.FromResult((MessageType.Text, new ArraySegment <byte>(Encoding.UTF8.GetBytes(jsonRpcMethod))))); // ACT _webSocketConnection.HandleMessagesAsync(_webSocketMock.Object, CancellationToken.None).Wait(100); // ASSERT Assert.That(_webSocketService.MethodsInvoked, Contains.Item("TestMethod2")); Assert.That(result, Is.Not.Null); Assert.That(jsonRpcMethodRequest.Id, Is.EqualTo(result["id"].Value <int>())); Assert.That(result["result"].ToObject <List <string> >(), Is.EqualTo(new List <string> { "test", "test" })); }