public void InvokeRequest_AmbiguousRequest_ErrorResponse() { RpcRequest stringRequest = new RpcRequest("1", "AmbiguousMethod", 1); RpcRoute route = new RpcRoute(); route.AddClass <TestRouteClass>(); IRpcInvoker invoker = new DefaultRpcInvoker(); RpcResponse response = invoker.InvokeRequest(stringRequest, route); Assert.NotNull(response.Error); Assert.Equal(response.Error.Code, RpcErrorCode.AmbiguousMethod); }
public void InvokeRequest_StringParam_ParseAsGuidType() { Guid randomGuid = Guid.NewGuid(); RpcRequest stringRequest = new RpcRequest("1", "GuidTypeMethod", randomGuid.ToString()); RpcRoute route = new RpcRoute(); route.AddClass <TestRouteClass>(); IRpcInvoker invoker = new DefaultRpcInvoker(); RpcResponse stringResponse = invoker.InvokeRequest(stringRequest, route); Assert.Equal(stringResponse.Result, randomGuid); }
public void InvokeRequest_AsyncMethod_Valid() { RpcRequest stringRequest = new RpcRequest("1", "2.0", "AddAsync", 1, 1); RpcRoute route = new RpcRoute(); route.AddClass <TestRouteClass>(); IRpcInvoker invoker = new DefaultRpcInvoker(); RpcResponseBase response = invoker.InvokeRequest(stringRequest, route); RpcResultResponse resultResponse = Assert.IsType <RpcResultResponse>(response); Assert.NotNull(resultResponse.Result); Assert.Equal(resultResponse.Result, 2); }
public void InvokeRequest_Int64RequestParam_ConvertToInt32Param() { RpcRequest stringRequest = new RpcRequest("1", "2.0", "IntParameter", (long)1); RpcRoute route = new RpcRoute(); route.AddClass <TestRouteClass>(); IRpcInvoker invoker = new DefaultRpcInvoker(); RpcResponseBase response = invoker.InvokeRequest(stringRequest, route); RpcResultResponse resultResponse = Assert.IsType <RpcResultResponse>(response); Assert.NotNull(resultResponse.Result); Assert.IsType <int>(resultResponse.Result); Assert.Equal(resultResponse.Result, 1); }
public void InvokeRequest_ServiceProvider_Pass() { RpcRequest stringRequest = new RpcRequest("1", "Test"); RpcRoute route = new RpcRoute(); route.AddClass <TestIoCRouteClass>(); IRpcInvoker invoker = new DefaultRpcInvoker(); IServiceCollection serviceCollection = new ServiceCollection(); serviceCollection.AddScoped <TestInjectionClass>(); serviceCollection.AddScoped <TestIoCRouteClass>(); IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider(); RpcResponse response = invoker.InvokeRequest(stringRequest, route, serviceProvider); RpcResponse resultResponse = Assert.IsType <RpcResponse>(response); Assert.NotNull(resultResponse.Result); Assert.Equal(JTokenType.Integer, resultResponse.Result.Type); Assert.Equal(resultResponse.Result.Value <int>(), 1); }