public async Task WorksWithUnitType() { var outputHandler = Substitute.For <IOutputHandler>(); var router = new ResponseRouter(outputHandler, new JsonRpcSerializer()); outputHandler .When(x => x.Send(Arg.Is <object>(x => x.GetType() == typeof(OutgoingRequest)))) .Do(call => { var(method, tcs) = router.GetRequest((long)call.Arg <OutgoingRequest>().Id); tcs.SetResult(new JObject()); }); await router.SendRequest(new UnitParams(), CancellationToken.None); var request = outputHandler.ReceivedCalls().Single().GetArguments()[0] as OutgoingRequest; request.Method.Should().Be("unit"); }
public async Task WorksWithResultType() { var outputHandler = Substitute.For <IOutputHandler>(); var router = new ResponseRouter(outputHandler, new JsonRpcSerializer()); outputHandler .When(x => x.Send(Arg.Is <object>(x => x.GetType() == typeof(Request)), Arg.Any <CancellationToken>())) .Do(call => { var tcs = router.GetRequest((long)call.Arg <Request>().Id); tcs.SetResult(new JObject()); }); var response = await router.SendRequest(new ItemParams(), CancellationToken.None); var request = outputHandler.ReceivedCalls().Single().GetArguments()[0] as Request; request.Method.Should().Be("abcd"); response.Should().NotBeNull(); response.Should().BeOfType <ItemResult>(); }