public void RpcProxyServiceMakeCallMethodNotAuthorized(IRpcHttpClient client, IRpcHttpClientProvider clientProvider, RpcProxyService proxyService) { var response = new HttpResponseMessage(HttpStatusCode.Accepted) { Content = new StreamContent(new ErrorResponseMessage(JsonRpcErrorCode.UnauthorizedAccess, "Not Authorized").SerializeToStream()) }; client.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(response); clientProvider.GetHttpClient(Arg.Any <string>(), Arg.Any <string>()).Returns(client); var bytes = new byte[] { 0, 1, 1, 0 }; Assert.Throws <AggregateException>(() => proxyService.MakeCallNoReturn("SomeNamespace", "SomeClass", "SomeMethod", bytes, false, false)); }
protected virtual async Task <HttpResponseMessage> SendByteArray(string @namespace, string className, string methodName, byte[] bytes, bool compressRequest, bool compressResponse) { var httpRequest = new HttpRequestMessage(HttpMethod.Post, className) { Content = new ByteArrayContent(bytes) }; httpRequest.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json") { CharSet = "utf-8" }; if (compressRequest) { httpRequest.Content.Headers.Add("Content-Encoding", "gzip"); } if (compressResponse) { httpRequest.Headers.Add("Accept-Encoding", "gzip"); } foreach (var headerProcessorse in _headerProcessors) { headerProcessorse.ProcessRequestHeader(httpRequest); } var client = _clientProvider.GetHttpClient(@namespace, className); var response = await client.SendAsync(httpRequest).ConfigureAwait(false); if (response.IsSuccessStatusCode) { return(response); } if (response.StatusCode == HttpStatusCode.Unauthorized) { throw new UnauthorizedMethodException(methodName); } throw new DynamicMethodException(methodName, $"Error response status {response.StatusCode}"); }
public void RpcProxyServiceMakeCallNoReturn(IRpcHttpClient client, IRpcHttpClientProvider clientProvider, RpcProxyService proxyService) { var response = new HttpResponseMessage(HttpStatusCode.Accepted) { Content = new StreamContent(new EmptyResponseMessage("2.0", "1").SerializeToStream()) }; client.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(response); clientProvider.GetHttpClient(Arg.Any <string>(), Arg.Any <string>()).Returns(client); var bytes = new byte[] { 0, 1, 1, 0 }; proxyService.MakeCallNoReturn("SomeNamespace", "SomeClass", "SomeMethod", bytes, false, false); client.Received().SendAsync(Arg.Is <HttpRequestMessage>(message => ValidateSomeClassSomeMethod(message))); }
public void RpcProxyServiceMakeCallReturnValueCompressResponse(IRpcHttpClient client, IRpcHttpClientProvider clientProvider, RpcProxyService proxyService) { var response = new HttpResponseMessage(HttpStatusCode.Accepted) { Content = new StreamContent(new ResponseMessage <int>(10, "2.0", "1").SerializeToStream("gzip")) }; response.Content.Headers.Add("Content-Encoding", "gzip"); client.SendAsync(Arg.Any <HttpRequestMessage>()).Returns(response); clientProvider.GetHttpClient(Arg.Any <string>(), Arg.Any <string>()).Returns(client); var bytes = new byte[] { 0, 1, 1, 0 }; var intValue = proxyService.MakeCallWithReturn <int>("SomeNamespace", "SomeClass", "SomeMethod", bytes, false, true); Assert.Equal(10, intValue); client.Received().SendAsync(Arg.Is <HttpRequestMessage>(message => ValidateSomeClassSomeMethod(message))); }