public async Task Test_GetRequestWrapper_StoresSingleRequest() { var notification = new UntypedNotification() { Method = "test" }; var request = new SingleRequestWrapper() { Call = notification, }; var itemsMock = new Mock <IDictionary <object, object> >(); itemsMock.Setup(x => x.ContainsKey(JsonRpcConstants.RequestItemKey)) .Returns(false); itemsMock.SetupSet(x => x[JsonRpcConstants.RequestItemKey] = It.IsAny <IUntypedCall>()); var httpContextMock = new Mock <HttpContext>(); httpContextMock.SetupGet(x => x.Items) .Returns(itemsMock.Object); requestReaderMock.Setup(x => x.ParseRequest(It.IsAny <HttpContext>(), It.IsAny <Encoding>())) .ReturnsAsync(request); var result = await requestReaderMock.Object.GetRequestWrapper(httpContextMock.Object, Encoding.UTF8); result.Should().BeOfType <SingleRequestWrapper>(); result.Should().Be(request); var requestResult = result as SingleRequestWrapper; requestResult.Call.Should().Be(notification); itemsMock.VerifySet(x => x[JsonRpcConstants.RequestItemKey] = It.IsAny <IUntypedCall>()); requestReaderMock.Verify(x => x.ParseRequest(It.IsAny <HttpContext>(), It.IsAny <Encoding>())); requestReaderMock.Verify(x => x.GetRequestWrapper(It.IsAny <HttpContext>(), It.IsAny <Encoding>())); }
public async Task Test_GetRequestWrapper_ReturnsBadOnBadMethod(string method) { var itemsMock = new Mock <IDictionary <object, object> >(); itemsMock.Setup(x => x.ContainsKey(JsonRpcConstants.RequestItemKey)) .Returns(false); var httpContextMock = new Mock <HttpContext>(); httpContextMock.SetupGet(x => x.Items) .Returns(itemsMock.Object); IRequestWrapper wrapper = new SingleRequestWrapper() { Call = new UntypedRequest() { Jsonrpc = "2.0", Method = method } }; requestReaderMock.Setup(x => x.ParseRequest(It.IsAny <HttpContext>(), It.IsAny <Encoding>())) .ReturnsAsync(wrapper); var result = await requestReaderMock.Object.GetRequestWrapper(httpContextMock.Object, Encoding.UTF8); result.Should().BeOfType <BadRequestWrapper>(); var request = result as BadRequestWrapper; request.Exception.Should().BeOfType <JsonRpcInternalException>(); requestReaderMock.Verify(x => x.ParseRequest(It.IsAny <HttpContext>(), It.IsAny <Encoding>())); requestReaderMock.Verify(x => x.GetRequestWrapper(It.IsAny <HttpContext>(), It.IsAny <Encoding>())); }
/// <summary> /// Sends the specified rpc request to the server /// </summary> /// <param name="request">Single rpc request that will goto the rpc server</param> /// <param name="route">(Optional) Route that will append to the base url if the request method call is not located at the base route</param> /// <typeparam name="TResponse">The deserialization type for the response result.</typeparam> /// <returns>The rpc response for the sent request</returns> public Task <RpcResponse <TResponse> > SendAsync <TResponse>(RpcRequest request, string?route = null) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var wrapper = new SingleRequestWrapper <TResponse>(request); return(this.SendAsync(wrapper, route)); }
public async Task Test_HandleSingle_NoFlagWhenNotificationAndCallsNext() { var single = new SingleRequestWrapper { Call = new UntypedNotification() { Jsonrpc = JsonRpcConstants.Version } }; var handlingContext = new HandlingContext(Mock.Of <HttpContext>(), Mock.Of <Encoding>(), Mock.Of <RequestDelegate>()); requestHandlerMock.Setup(x => x.SafeNext(It.IsAny <IUntypedCall>(), It.IsAny <HandlingContext>(), It.IsAny <bool>())) .ReturnsAsync(Mock.Of <IServerResponseWrapper>()); await requestHandlerMock.Object.HandleSingle(single, handlingContext); handlingContext.WriteResponse.Should().BeFalse(); requestHandlerMock.Verify(x => x.SafeNext(It.IsAny <IUntypedCall>(), It.IsAny <HandlingContext>(), It.IsAny <bool>())); requestHandlerMock.Verify(x => x.HandleSingle(It.IsAny <SingleRequestWrapper>(), It.IsAny <HandlingContext>())); }
protected internal virtual async Task <IServerResponseWrapper> HandleSingle(SingleRequestWrapper singleRequestWrapper, HandlingContext context) { context.WriteResponse = singleRequestWrapper.Call is UntypedRequest; log.LogTrace($"{nameof(HandleSingle)}: set writeResponse [{context.WriteResponse}] because call is request"); return(await SafeNext(singleRequestWrapper.Call, context, options.AllowRawResponses)); }