Ejemplo n.º 1
0
        public void TestProxyRegisterMethod()
        {
            JsonRpcServiceProxyWrapper wrapper = new JsonRpcServiceProxyWrapper();

            wrapper.RegisterMethod("m1", req => { return(Task.FromResult <JsonRpcResponse>(new JsonRpcResponse())); });
            Assert.IsTrue(wrapper.HasMethod("m1"));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public void TestProxyExecuteMethodSync()
        {
            JsonRpcServiceProxyWrapper wrapper = new JsonRpcServiceProxyWrapper();

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

            Assert.IsNotNull(resp);
            Assert.AreEqual("Result", resp.Result);
        }
Ejemplo n.º 4
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);
        }