Example #1
0
        public void ParseRequests_ObjectWithArrayParam_NoException()
        {
            const string json   = "{\"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"Add7\", \"params\": [[{\"test\":2},{\"test\":3}]]}";
            IRpcParser   parser = new DefaultRpcParser(new FakeLogger <DefaultRpcParser>(), Options.Create(new RpcServerConfiguration()));

            ParsingResult result = parser.ParseRequests(json);

            Assert.NotNull(result);
            Assert.Equal(1, result.RequestCount);
            Assert.Single(result.Requests);
            Assert.Equal("1", result.Requests[0].Id);
            Assert.Equal("Add7", result.Requests[0].Method);
            var expectedParams = new Obj[]
            {
                new Obj {
                    Test = 2
                },
                new Obj {
                    Test = 3
                }
            };

            ParserTests.CompareParameters(new object[] { expectedParams }, result.Requests[0].Parameters);
            Assert.False(result.IsBulkRequest);
        }
Example #2
0
        public void ParseRequests_Valid(string json, object id, string method, object[] parameters)
        {
            DefaultRpcParser parser = new DefaultRpcParser(null);

            RpcRequest rpcRequest = parser.ParseRequests(json, out bool isBulkRequest).FirstOrDefault();

            Assert.NotNull(rpcRequest);
            ParserTests.CompareId(id, rpcRequest.Id);
            Assert.Equal(method, rpcRequest.Method);
            Assert.Equal(JsonRpcContants.JsonRpcVersion, rpcRequest.JsonRpcVersion);
            ParserTests.CompareParameters(parameters, rpcRequest.Parameters);
            Assert.False(isBulkRequest);
        }
Example #3
0
        public void ParseRequests_Valid(string json, object id, string method, object[] parameters)
        {
            DefaultRpcParser parser = new DefaultRpcParser(null, Options.Create(new RpcServerConfiguration()));

            ParsingResult result = parser.ParseRequests(json);

            Assert.NotNull(result);
            Assert.Equal(1, result.RequestCount);
            Assert.Single(result.Requests);
            Assert.Equal(RpcId.FromObject(id), result.Requests[0].Id);
            Assert.Equal(method, result.Requests[0].Method);
            ParserTests.CompareParameters(parameters, result.Requests[0].Parameters);
            Assert.False(result.IsBulkRequest);
        }
Example #4
0
        public void ParseRequests_DateTime_Valid()
        {
            const string     json     = "{\"jsonrpc\": \"2.0\", \"method\": \"datetime\", \"params\": [\"2000-12-15T22:11:03\"], \"id\": 1}";
            DateTime         dateTime = DateTime.Parse("2000-12-15T22:11:03");
            DefaultRpcParser parser   = new DefaultRpcParser(null);

            RpcRequest rpcRequest = parser.ParseRequests(json, out bool isBulkRequest).FirstOrDefault();

            Assert.NotNull(rpcRequest);
            ParserTests.CompareId(1, rpcRequest.Id);
            Assert.Equal("datetime", rpcRequest.Method);
            Assert.Equal(JsonRpcContants.JsonRpcVersion, rpcRequest.JsonRpcVersion);
            ParserTests.CompareParameters(new object[] { dateTime }, rpcRequest.Parameters);
            Assert.False(isBulkRequest);
        }
Example #5
0
        public void ParseRequests_MissingId_NoException()
        {
            const string     json   = "{\"method\": \"datetime\", \"jsonrpc\": \"2.0\", \"params\": [\"2000-12-15T22:11:03\"]}";
            DefaultRpcParser parser = new DefaultRpcParser(null, Options.Create(new RpcServerConfiguration()));

            ParsingResult result = parser.ParseRequests(json);

            Assert.NotNull(result);
            Assert.Equal(1, result.RequestCount);
            Assert.Single(result.Requests);
            Assert.Equal(default(RpcId), result.Requests[0].Id);
            Assert.Equal("datetime", result.Requests[0].Method);
            ParserTests.CompareParameters(new object[] { "2000-12-15T22:11:03" }, result.Requests[0].Parameters);
            Assert.False(result.IsBulkRequest);
        }
Example #6
0
        public void ParseRequests_SingleBatchRequest_Valid()
        {
            const string json = "[{\"jsonrpc\": \"2.0\", \"method\": \"one\", \"params\": [\"1\"], \"id\": \"1\"}]";

            DefaultRpcParser parser = new DefaultRpcParser(null);

            List <RpcRequest> rpcRequests = parser.ParseRequests(json, out bool isBulkRequest);

            Assert.NotNull(rpcRequests);
            Assert.Single(rpcRequests);
            ParserTests.CompareId("1", rpcRequests[0].Id);
            Assert.Equal("one", rpcRequests[0].Method);
            Assert.Equal(JsonRpcContants.JsonRpcVersion, rpcRequests[0].JsonRpcVersion);
            ParserTests.CompareParameters(new object[] { "1" }, rpcRequests[0].Parameters);
            Assert.True(isBulkRequest);
        }
Example #7
0
        public void ParseRequests_SingleBatchRequest_Valid()
        {
            const string json = "[{\"jsonrpc\": \"2.0\", \"method\": \"one\", \"params\": [\"1\"], \"id\": \"1\"}]";

            DefaultRpcParser parser = new DefaultRpcParser(null, Options.Create(new RpcServerConfiguration()));

            ParsingResult result = parser.ParseRequests(json);

            Assert.NotNull(result);
            Assert.Equal(1, result.RequestCount);
            Assert.Single(result.Requests);
            Assert.Equal("1", result.Requests[0].Id);
            Assert.Equal("one", result.Requests[0].Method);
            ParserTests.CompareParameters(new object[] { "1" }, result.Requests[0].Parameters);
            Assert.True(result.IsBulkRequest);
        }
Example #8
0
        public void ParseRequests_ObjectParam_NoException()
        {
            const string json   = "{\"method\": \"obj\", \"jsonrpc\": \"2.0\", \"params\": [{\"test\":1}], \"id\": \"1\"}";
            IRpcParser   parser = new DefaultRpcParser(new FakeLogger <DefaultRpcParser>(), Options.Create(new RpcServerConfiguration()));

            ParsingResult result = parser.ParseRequests(json);

            Assert.NotNull(result);
            Assert.Equal(1, result.RequestCount);
            Assert.Single(result.Requests);
            Assert.Equal("1", result.Requests[0].Id);
            Assert.Equal("obj", result.Requests[0].Method);
            ParserTests.CompareParameters(new object[] { new Obj {
                                                             Test = 1
                                                         } }, result.Requests[0].Parameters);
            Assert.False(result.IsBulkRequest);
        }
Example #9
0
        public void ParseRequests_DateTime_Valid()
        {
            const string json     = "{\"jsonrpc\": \"2.0\", \"method\": \"datetime\", \"params\": [\"2000-12-15T22:11:03\"], \"id\": 1}";
            DateTime     dateTime = DateTime.Parse("2000-12-15T22:11:03");
            IRpcParser   parser   = new DefaultRpcParser(new FakeLogger <DefaultRpcParser>(), Options.Create(new RpcServerConfiguration()));

            ParsingResult result = parser.ParseRequests(json);


            Assert.NotNull(result);
            Assert.Equal(1, result.RequestCount);
            Assert.Single(result.Requests);
            Assert.Equal(1, result.Requests[0].Id);
            Assert.Equal("datetime", result.Requests[0].Method);
            ParserTests.CompareParameters(new object[] { dateTime }, result.Requests[0].Parameters);
            Assert.False(result.IsBulkRequest);
        }