public async Task InvokeRequest_ComplexParam_TwoRequests_NotCached() { string methodName = nameof(TestRouteClass.ComplexParam); DefaultRpcInvoker invoker = this.GetInvoker(methodName); async Task Test(TestComplexParam param) { var rpcParameter = InvokerTests.FromRaw(param); RpcRequest stringRequest = new RpcRequest("1", methodName, parameters: new RpcParameters(rpcParameter)); RpcResponse?response = await invoker.InvokeRequestAsync(stringRequest); RpcResponse resultResponse = Assert.IsType <RpcResponse>(response); Assert.False(resultResponse.HasError); Assert.Equal(param, resultResponse.Result); } TestComplexParam param1 = new TestComplexParam { A = "Test", B = 5 }; await Test(param1); TestComplexParam param2 = new TestComplexParam { A = "Test2", B = 6 }; await Test(param2); }
public async Task InvokeRequest_WithAudit() { Guid randomGuid = Guid.NewGuid(); var parameters = new RpcParameters(InvokerTests.FromRaw(randomGuid.ToString())); string methodName = nameof(TestRouteClass.GuidTypeMethod); var stringRequest = new RpcRequest("1", methodName, parameters); int startCalledCount = 0; int endCalledCount = 0; object data = new object(); DefaultRpcInvoker invoker = this.GetInvoker(methodName, configure: (config) => { config.OnInvokeStart = (context) => { startCalledCount++; context.CustomContextData = data; }; config.OnInvokeEnd = (context, response) => { endCalledCount++; Assert.Same(data, context.CustomContextData); }; }); RpcResponse?stringResponse = await invoker.InvokeRequestAsync(stringRequest); Assert.Equal(1, startCalledCount); Assert.Equal(1, endCalledCount); }
public async Task InvokeRequest_MultipleDictionaryValues_Valid() { string methodName = nameof(TestRouteClass.AllTypes); DefaultRpcInvoker invoker = this.GetInvoker(methodName); bool a = true; string bb = "Test"; object?ccc = null; var dddd = new TestComplexParam(); int eeeee = 1; var paramDict = new Dictionary <string, IRpcParameter> { ["a"] = InvokerTests.FromRaw(a), ["bb"] = InvokerTests.FromRaw(bb), ["ccc"] = InvokerTests.FromRaw(ccc), ["dddd"] = InvokerTests.FromRaw(dddd), ["eeeee"] = InvokerTests.FromRaw(eeeee) }; RpcRequest stringRequest = new RpcRequest("1", methodName, parameters: new RpcParameters(paramDict)); RpcResponse?response = await invoker.InvokeRequestAsync(stringRequest); RpcResponse resultResponse = Assert.IsType <RpcResponse>(response); Assert.False(resultResponse.HasError); var value = Assert.IsType <ValueTuple <bool, string, object, TestComplexParam, int> >(resultResponse.Result); Assert.Equal((a, bb, ccc, dddd, eeeee), value); }
public async Task InvokeRequest_MethodNotFound_ErrorResponse() { var parameters = new RpcParameters(InvokerTests.FromRaw(1)); var stringRequest = new RpcRequest("1", "MethodNotFound", parameters); DefaultRpcInvoker invoker = this.GetInvoker(methodInfo: null); RpcResponse? response = await invoker.InvokeRequestAsync(stringRequest); Assert.NotNull(response); Assert.NotNull(response !.Error); Assert.Equal((int)RpcErrorCode.MethodNotFound, response.Error !.Code); }
public async Task InvokeRequest_StringParam_ParseAsGuidType() { Guid randomGuid = Guid.NewGuid(); var parameters = new RpcParameters(InvokerTests.FromRaw(randomGuid.ToString())); string methodName = nameof(TestRouteClass.GuidTypeMethod); var stringRequest = new RpcRequest("1", methodName, parameters); DefaultRpcInvoker invoker = this.GetInvoker(methodName); RpcResponse? stringResponse = await invoker.InvokeRequestAsync(stringRequest); Assert.NotNull(stringResponse); Assert.Equal(randomGuid, stringResponse !.Result); }
public async Task InvokeRequest_BoolParam_Valid() { string methodName = nameof(TestRouteClass.BoolParameter); DefaultRpcInvoker invoker = this.GetInvoker(methodName); bool expectedValue = true; var param = InvokerTests.FromRaw(expectedValue); RpcRequest stringRequest = new RpcRequest("1", methodName, parameters: new RpcParameters(param)); RpcResponse?response = await invoker.InvokeRequestAsync(stringRequest); RpcResponse resultResponse = Assert.IsType <RpcResponse>(response); Assert.False(resultResponse.HasError); Assert.Equal(expectedValue, resultResponse.Result); }
public async Task InvokeRequest_Int64RequestParam_ConvertToInt32Param() { var parameters = new RpcParameters(InvokerTests.FromRaw(1L)); string methodName = nameof(TestRouteClass.IntParameter); var stringRequest = new RpcRequest("1", methodName, parameters); DefaultRpcInvoker invoker = this.GetInvoker(methodName); RpcResponse?response = await invoker.InvokeRequestAsync(stringRequest); RpcResponse resultResponse = Assert.IsType <RpcResponse>(response); Assert.NotNull(resultResponse.Result); Assert.Equal(1, resultResponse.Result); }
public async Task InvokeRequest_AsyncMethod_Valid() { var parameters = new RpcParameters(InvokerTests.FromRaw(1), InvokerTests.FromRaw(1)); string methodName = nameof(TestRouteClass.AddAsync); var stringRequest = new RpcRequest("1", methodName, parameters); DefaultRpcInvoker invoker = this.GetInvoker(methodName); RpcResponse?response = await invoker.InvokeRequestAsync(stringRequest); RpcResponse resultResponse = Assert.IsType <RpcResponse>(response); Assert.NotNull(resultResponse.Result); Assert.Equal(2, resultResponse.Result); }
public async Task InvokeRequest_ListParam_Valid() { string methodName = nameof(TestRouteClass.ListParam); DefaultRpcInvoker invoker = this.GetInvoker(methodName); var param = new TestComplexParam[] { new TestComplexParam { A = "Test", B = 5 } }; var rpcParameter = InvokerTests.FromRaw(param); RpcRequest stringRequest = new RpcRequest("1", methodName, parameters: new RpcParameters(rpcParameter)); RpcResponse?response = await invoker.InvokeRequestAsync(stringRequest); RpcResponse resultResponse = Assert.IsType <RpcResponse>(response); Assert.False(resultResponse.HasError); Assert.Equal(param, resultResponse.Result); }
public async Task InvokeRequest_OptionalParameter_Valid() { string methodName = nameof(TestRouteClass.Optional); DefaultRpcInvoker invoker = this.GetInvoker(methodName); //No params specified RpcRequest stringRequest = new RpcRequest("1", methodName, parameters: null); RpcResponse?response = await invoker.InvokeRequestAsync(stringRequest); RpcResponse resultResponse = Assert.IsType <RpcResponse>(response); Assert.Null(resultResponse.Result); Assert.False(resultResponse.HasError, resultResponse.Error?.Message); //Param is empty var parameters = new RpcParameters(new IRpcParameter[0]); stringRequest = new RpcRequest("1", methodName, parameters: parameters); response = await invoker.InvokeRequestAsync(stringRequest); resultResponse = Assert.IsType <RpcResponse>(response); Assert.Null(resultResponse.Result); Assert.False(resultResponse.HasError); //Param is a string const string value = "Test"; parameters = new RpcParameters(new IRpcParameter[] { InvokerTests.FromRaw(value) }); stringRequest = new RpcRequest("1", methodName, parameters: parameters); response = await invoker.InvokeRequestAsync(stringRequest); resultResponse = Assert.IsType <RpcResponse>(response); Assert.NotNull(resultResponse.Result); Assert.IsType <string>(resultResponse.Result); Assert.Equal(value, (string)resultResponse.Result !); }