public async Task SendRequestNotConnected() { // If: I send an event when the protocol channel isn't connected // Then: I should get an exception var jh = new JsonRpcHost(GetChannelBase(null, null).Object); await Assert.ThrowsAsync <InvalidOperationException>(() => jh.SendRequest(CommonObjects.RequestType, CommonObjects.TestMessageContents.DefaultInstance)); }
public async Task SendRequest() { // If: I send a request with the JSON RPC host var jh = new JsonRpcHost(GetChannelBase(null, null, true).Object); Task <CommonObjects.TestMessageContents> requestTask = jh.SendRequest(CommonObjects.RequestType, CommonObjects.TestMessageContents.DefaultInstance); // Then: There should be a pending request Assert.Single(jh.pendingRequests); // If: I then trick it into completing the request jh.pendingRequests.First().Value.SetResult(CommonObjects.ResponseMessage); var responseContents = await requestTask; // Then: The returned results should be the contents of the message Assert.Equal(CommonObjects.TestMessageContents.DefaultInstance, responseContents); }