Пример #1
0
        public void TestProxyExecuteMethodRequestIsNull()
        {
            JsonRpcServiceProxyWrapper wrapper = new JsonRpcServiceProxyWrapper();

            wrapper.RegisterMethod("m1", req => { return(Task.FromResult <JsonRpcResponse>(new JsonRpcResponse
                {
                    Id = Guid.NewGuid().ToString(),
                    Result = "Result"
                })); });
            var resp = wrapper.ServeAsync(null).GetAwaiter().GetResult();

            Assert.IsNotNull(resp);
            Assert.IsNotNull(resp.Error);
            Assert.AreEqual((int)ErrorCode.InvalidRequest, resp.Error.Code);
        }
Пример #2
0
        public void TestProxyExecuteMethodExceptionAsync()
        {
            JsonRpcServiceProxyWrapper wrapper = new JsonRpcServiceProxyWrapper();

            wrapper.RegisterMethod("m1", req =>
            {
                throw new Exception("Error");
            });
            var resp = wrapper.ServeAsync(new JsonRpcRequest
            {
                Method = "m1"
            }).GetAwaiter().GetResult();

            Assert.IsNotNull(resp);
            Assert.IsNotNull(resp.Error);
            Assert.AreEqual((int)ErrorCode.ServerError, resp.Error.Code);
        }
Пример #3
0
        public void TestProxyExecuteMethodAsync()
        {
            JsonRpcServiceProxyWrapper wrapper = new JsonRpcServiceProxyWrapper();

            wrapper.RegisterMethod("m1", req => { return(Task.FromResult <JsonRpcResponse>(new JsonRpcResponse
                {
                    Id = Guid.NewGuid().ToString(),
                    Result = "Result"
                })); });
            var resp = wrapper.ServeAsync(new JsonRpcRequest
            {
                Method = "m1"
            }).GetAwaiter().GetResult();

            Assert.IsNotNull(resp);
            Assert.AreEqual("Result", resp.Result);
        }