コード例 #1
0
        public void JsonRpcConvert_DeserializeResponse(string json, object result, int?errorNumber, string errorMessage, string id)
        {
            var response = (JsonRpcResponse)JsonRpcConvert.Deserialize(json).First();

            AssertAreEqualJson(result, response.Result);
            Assert.AreEqual(errorNumber, response.Error?.Code);
            Assert.AreEqual(errorMessage, response.Error?.Message);
        }
コード例 #2
0
        public void JsonRpcConvert_DeserializeInvalidJson(string json)
        {
            var error = (JsonRpcError)JsonRpcConvert.Deserialize(json).First();

            Assert.AreEqual(JsonRpcErrorCode.ParseError.Code, error.Code);
            Assert.AreEqual(JsonRpcErrorCode.ParseError.Message, error.Message);
            Assert.IsNotNull(error.Data);
        }
コード例 #3
0
        public void JsonRpcConvert_Deserialize_InvalidBatchNotEmpty()
        {
            var json  = "[1]";
            var error = (JsonRpcError)JsonRpcConvert.Deserialize(json).First();

            Assert.AreEqual(JsonRpcErrorCode.InvalidRequest.Code, error.Code);
            Assert.AreEqual(JsonRpcErrorCode.InvalidRequest.Message, error.Message);
            Assert.IsNull(error.Data);
        }
コード例 #4
0
        public void JsonRpcConvert_DeserializeRequest_BatchAllNotifications()
        {
            var json  = "[ {'jsonrpc': '2.0', 'method': 'notify_sum', 'params': [1,2,4] }, {'jsonrpc': '2.0', 'method': 'notify_hello', 'params': [7] } ]";
            var items = JsonRpcConvert.Deserialize(json).ToArray();

            Assert.AreEqual(2, items.Length);
            Assert.IsInstanceOf <JsonRpcRequest>(items[0]);
            Assert.IsInstanceOf <JsonRpcRequest>(items[1]);
        }
コード例 #5
0
        public void JsonRpcConvert_DeserializeRequest_PositionalParameters(string json, string method, object @params, string id)
        {
            var request = (JsonRpcRequest)JsonRpcConvert.Deserialize(json).First();

            Assert.AreEqual("2.0", request.JsonRpc);
            Assert.AreEqual(method, request.Method);
            AssertAreEqualJson(@params, request.Params);
            Assert.AreEqual(id, request.Id);
        }
コード例 #6
0
        public void JsonRpcRequest_Invoke_NamedParameters()
        {
            var obj     = new MockObject();
            var json    = "{'jsonrpc': '2.0', 'method': 'subtract', 'params': {'subtrahend': 23, 'minuend': 42}, 'id': 3}";
            var request = (JsonRpcRequest)JsonRpcConvert.Deserialize(json).First();
            var result  = request.Invoke(obj);

            Assert.AreEqual(19, result);
        }
コード例 #7
0
        public void JsonRpcRequest_Invoke_PositionalParameters()
        {
            var obj     = new MockObject();
            var json    = "{'jsonrpc': '2.0', 'method': 'subtract', 'params': [42, 23], 'id': 1}";
            var request = (JsonRpcRequest)JsonRpcConvert.Deserialize(json).First();
            var result  = request.Invoke(obj);

            Assert.AreEqual(19, result);
        }
コード例 #8
0
        public void JsonRpcConvert_DeserializeRequest_NamedParameter()
        {
            var json    = "{'jsonrpc': '2.0', 'method': 'subtract', 'params': {'subtrahend': 23, 'minuend': 42}, 'id': 3}";
            var request = (JsonRpcRequest)JsonRpcConvert.Deserialize(json).First();

            Assert.AreEqual("2.0", request.JsonRpc);
            Assert.AreEqual("subtract", request.Method);
            AssertAreEqualJson(new { subtrahend = 23, minuend = 42 }, request.Params);
            Assert.AreEqual("3", request.Id);
        }
コード例 #9
0
        public void JsonRpcConvert_DeserializeRequest_Batch()
        {
            var json  = "[ {'jsonrpc': '2.0', 'method': 'sum', 'params': [1,2,4], 'id': '1'}, {'jsonrpc': '2.0', 'method': 'notify_hello', 'params': [7] }, {'jsonrpc': '2.0', 'method': 'subtract', 'params': [42,23], 'id': '2'}, {'foo': 'boo'}, {'jsonrpc': '2.0', 'method': 'foo.get', 'params': {'name': 'myself'}, 'id': '5'}, {'jsonrpc': '2.0', 'method': 'get_data', 'id': '9'} ]";
            var items = JsonRpcConvert.Deserialize(json).ToArray();

            Assert.AreEqual(6, items.Length);
            Assert.IsInstanceOf <JsonRpcRequest>(items[0]);
            Assert.IsInstanceOf <JsonRpcRequest>(items[1]);
            Assert.IsInstanceOf <JsonRpcRequest>(items[2]);
            Assert.IsInstanceOf <JsonRpcError>(items[3]);
            Assert.IsInstanceOf <JsonRpcRequest>(items[4]);
            Assert.IsInstanceOf <JsonRpcRequest>(items[5]);
        }
コード例 #10
0
        public void JsonRpcConvert_Deserialize_InvalidBatch()
        {
            var json  = "[1,2,3]";
            var items = JsonRpcConvert.Deserialize(json);

            Assert.AreEqual(3, items.Count());
            foreach (var item in items)
            {
                var error = (JsonRpcError)item;
                Assert.AreEqual(JsonRpcErrorCode.InvalidRequest.Code, error.Code);
                Assert.AreEqual(JsonRpcErrorCode.InvalidRequest.Message, error.Message);
                Assert.IsNull(error.Data);
            }
        }