From 76fb4fb08c1cd46d494438d52a8ee0426b7084bb Mon Sep 17 00:00:00 2001 From: Astn Date: Sat, 4 Oct 2014 22:35:59 -0600 Subject: [PATCH 01/81] fix date test to work with data from another time zone --- AustinHarris.JsonRpcTest/UnitTest1.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/AustinHarris.JsonRpcTest/UnitTest1.cs b/AustinHarris.JsonRpcTest/UnitTest1.cs index cdf7ee2..2a32a16 100644 --- a/AustinHarris.JsonRpcTest/UnitTest1.cs +++ b/AustinHarris.JsonRpcTest/UnitTest1.cs @@ -34,10 +34,11 @@ public void NullableDateTimeToNullableDateTime() { string request = @"{method:'NullableDateTimeToNullableDateTime',params:['2014-06-30T14:50:38.5208399+09:00'],id:1}"; string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"2014-06-30T14:50:38.5208399+09:00\",\"id\":1}"; + var expectedDate = DateTime.Parse("2014-06-30T14:50:38.5208399+09:00"); var result = JsonRpcProcessor.Process(request); result.Wait(); - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); + var acutalDate = DateTime.Parse(result.Result.Substring(27, 33)); + Assert.AreEqual(expectedDate, acutalDate); } [TestMethod] From b6c39589478ff6e1123ae9fc0bd0710adc1a561f Mon Sep 17 00:00:00 2001 From: Martin Daetz Date: Fri, 23 Jan 2015 10:39:11 +0100 Subject: [PATCH 02/81] fix optional parameter order issue. --- AustinHarris.JsonRpcTest/UnitTest1.cs | 14 ++++++- AustinHarris.JsonRpcTest/service.cs | 7 +++- Json-Rpc/Handler.cs | 55 ++++++++++++++++----------- 3 files changed, 52 insertions(+), 24 deletions(-) diff --git a/AustinHarris.JsonRpcTest/UnitTest1.cs b/AustinHarris.JsonRpcTest/UnitTest1.cs index 2a32a16..d8ebee4 100644 --- a/AustinHarris.JsonRpcTest/UnitTest1.cs +++ b/AustinHarris.JsonRpcTest/UnitTest1.cs @@ -1320,6 +1320,18 @@ public void TestOptionalParametersStrings_BothExists() result.Wait(); Assert.IsFalse(result.Result.Contains("error")); Assert.AreEqual(expectedResult, result.Result); - } + } + [TestMethod] + public void TestOptionalParametersBoolsAndStrings() + { + string request = + "{\"jsonrpc\":\"2.0\",\"method\":\"TestOptionalParametersBoolsAndStrings\",\"params\":{\"input1\":\"murkel\"},\"Id\":1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } } } diff --git a/AustinHarris.JsonRpcTest/service.cs b/AustinHarris.JsonRpcTest/service.cs index 5d8982c..2b3f434 100644 --- a/AustinHarris.JsonRpcTest/service.cs +++ b/AustinHarris.JsonRpcTest/service.cs @@ -291,7 +291,12 @@ private IList TestOptionalParameters_Strings(string input1 = null, strin input1, input2 }; - } + } + [JsonRpcMethod] + public bool TestOptionalParametersBoolsAndStrings(string input1, bool input2 = true, string input3 = "") + { + return input2; + } } } diff --git a/Json-Rpc/Handler.cs b/Json-Rpc/Handler.cs index 54be5cc..d73e358 100644 --- a/Json-Rpc/Handler.cs +++ b/Json-Rpc/Handler.cs @@ -266,28 +266,39 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null) } parameters[i] = CleanUpParameter(jo[metadata.parameters[i].Name], metadata.parameters[i]); } - } - - // Optional Parameter support - // check if we still miss parameters compared to metadata which may include optional parameters. - // if the rpc-call didn't supply a value for an optional parameter, we should be assinging the default value of it. - if (parameters.Length < metaDataParamCount && metadata.defaultValues.Length > 0) // rpc call didn't set values for all optional parameters, so we need to assign the default values for them. - { - var paramIndex = parameters.Length; // the index we should start storing default values of optional parameters. - var missingParamsCount = metaDataParamCount - parameters.Length; // the amount of optional parameters without a value set by rpc-call. - Array.Resize(ref parameters, parameters.Length + missingParamsCount); // resize the array to include all optional parameters. - - // we need to add in reverse order as parameters can appear after all required parameters. - // as some of the optional parameters could already have assigned their values in rpc-call, - // by starting from the end we can make sure we only add the required default values. - for (int k = missingParamsCount; k > 0; k--) - { - var optionalParamIndex = k - 1; // the index of the optional parameter we will be currently setting a default value. - parameters[paramIndex] = metadata.defaultValues[optionalParamIndex].Value; // set the default value for the optional parameter that rpc-call didn't set a value for. - paramIndex++; - paramCount++; // we need to increase the paramCount by one each time we add default-value for an optional parameter that rpc-call didn't set a value for. - } - } + } + + // Optional Parameter support + // check if we still miss parameters compared to metadata which may include optional parameters. + // if the rpc-call didn't supply a value for an optional parameter, we should be assinging the default value of it. + if (parameters.Length < metaDataParamCount && metadata.defaultValues.Length > 0) // rpc call didn't set values for all optional parameters, so we need to assign the default values for them. + { + var suppliedParamsCount = parameters.Length; // the index we should start storing default values of optional parameters. + var missingParamsCount = metaDataParamCount - parameters.Length; // the amount of optional parameters without a value set by rpc-call. + Array.Resize(ref parameters, parameters.Length + missingParamsCount); // resize the array to include all optional parameters. + + for (int paramIndex = parameters.Length - 1, defaultIndex = metadata.defaultValues.Length - 1; // fill missing parameters from the back + paramIndex >= suppliedParamsCount && defaultIndex >= 0; // to don't overwrite supplied ones. + paramIndex--, defaultIndex--) + { + parameters[paramIndex] = metadata.defaultValues[defaultIndex].Value; + } + + if (missingParamsCount > metadata.defaultValues.Length) + { + return new JsonResponse + { + Error = ProcessException(Rpc, + new JsonRpcException(-32602, + "Invalid params", + string.Format( + "Number of default parameters {0} not sufficient to fill all missing parameters {1}", + metadata.defaultValues.Length, missingParamsCount) + )), + Id = Rpc.Id + }; + } + } if (parameters.Length != metaDataParamCount) { From 96c3d1a3424c8baa2864d05490711daa3863cf6e Mon Sep 17 00:00:00 2001 From: Martin Daetz Date: Thu, 29 Jan 2015 13:22:14 +0100 Subject: [PATCH 03/81] fix batch results removing superfluous commas. refactor JsonRpcProcessor.cs in order to avoid duplicate code. --- AustinHarris.JsonRpcTest/UnitTest1.cs | 22 +- AustinHarris.JsonRpcTest/service.cs | 10 +- Json-Rpc/JsonRpcProcessor.cs | 445 +++++--------------------- 3 files changed, 113 insertions(+), 364 deletions(-) diff --git a/AustinHarris.JsonRpcTest/UnitTest1.cs b/AustinHarris.JsonRpcTest/UnitTest1.cs index 2a32a16..5c5f8af 100644 --- a/AustinHarris.JsonRpcTest/UnitTest1.cs +++ b/AustinHarris.JsonRpcTest/UnitTest1.cs @@ -1,8 +1,9 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using AustinHarris.JsonRpc.Client; -using AustinHarris.JsonRpc; - +using AustinHarris.JsonRpc; +using Newtonsoft.Json.Linq; + namespace UnitTests { [TestClass] @@ -1320,6 +1321,21 @@ public void TestOptionalParametersStrings_BothExists() result.Wait(); Assert.IsFalse(result.Result.Contains("error")); Assert.AreEqual(expectedResult, result.Result); - } + } + + [TestMethod] + public void TestBatchResult() + { + string request = + @"[{},{""jsonrpc"":""2.0"",""id"":4},{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}]"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + + Assert.IsFalse(result.Result.EndsWith(@",]"), "result.Result.EndsWith(@',]')"); + + var parsedArray = JArray.Parse(result.Result); + //var parsed = JObject.Parse(result.Result); + } } } diff --git a/AustinHarris.JsonRpcTest/service.cs b/AustinHarris.JsonRpcTest/service.cs index 5d8982c..59cc7fa 100644 --- a/AustinHarris.JsonRpcTest/service.cs +++ b/AustinHarris.JsonRpcTest/service.cs @@ -1,6 +1,7 @@ using AustinHarris.JsonRpc; using System; -using System.Collections.Generic; +using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; @@ -291,7 +292,12 @@ private IList TestOptionalParameters_Strings(string input1 = null, strin input1, input2 }; + } + + [JsonRpcMethod] + public void Notify(string message) + { + Trace.WriteLine(string.Format("Notified about: {0}", message)); } - } } diff --git a/Json-Rpc/JsonRpcProcessor.cs b/Json-Rpc/JsonRpcProcessor.cs index ffa90b2..f8c3331 100644 --- a/Json-Rpc/JsonRpcProcessor.cs +++ b/Json-Rpc/JsonRpcProcessor.cs @@ -4,7 +4,8 @@ using System.Threading.Tasks; using System.Reflection; using System.IO; -using System.Collections.Generic; +using System.Collections.Generic; +using System.Linq; using System.Text; namespace AustinHarris.JsonRpc @@ -13,10 +14,10 @@ public static class JsonRpcProcessor { public static void Process(JsonRpcStateAsync async, object context = null) { - var t = Task.Factory.StartNew((_async) => + Task.Factory.StartNew((_async) => { - var i = (Tuple)_async; - ProcessJsonRpcState(i.Item1,i.Item2); + var tuple = (Tuple)_async; + ProcessJsonRpcState(tuple.Item1, tuple.Item2); }, new Tuple(async,context)); } @@ -34,183 +35,10 @@ internal static void ProcessJsonRpcState(JsonRpcStateAsync async, object jsonRpc { ProcessJsonRpcState(Handler.DefaultSessionId(), async, jsonRpcContext); } - internal static void ProcessJsonRpcState(string sessionId, JsonRpcStateAsync async, object jsonRpcContext = null) - { - var context = async.AsyncState; - - JsonRequest[] rpcBatch = null; - JsonResponse[] responseBatch = null; - - JsonRequest rpc = null; - var handler = Handler.GetSessionHandler(sessionId); - var callback = string.Empty; - - var response = new JsonResponse(); - - response.Result = null; - response.Error = null; - - string json = async.JsonRpc; - - if (isSingleRpc(json)) - { - try - { - if (json.Length > 0) - { - rpc = Newtonsoft.Json.JsonConvert.DeserializeObject(json); - if (rpc == null) - { - response.Result = null; - response.Id = null; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32700, "Parse error", "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.")); - } - else - { - response.Id = rpc.Id; - if (rpc.Method == null) - { - response.Result = null; - response.Id = rpc.Id; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32600, "Invalid Request", "Missing property 'method'")); - } - } - } - else - { - response.Result = null; - response.Id = null; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32600, "Invalid Request", "The JSON sent is not a valid Request object.")); - } - } - catch (Exception ex) - { - response.Result = null; - if (rpc != null) response.Id = rpc.Id; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32700, "Parse error", ex)); - var result = Newtonsoft.Json.JsonConvert.SerializeObject(response); - async.Result = result; - async.SetCompleted(); - return; - } - - if (response.Error == null - && rpc != null - && rpc.Method != null) - { - var data = Handler.GetSessionHandler(sessionId).Handle(rpc, jsonRpcContext); - if (data != null) - { - response.Error = data.Error; - response.Result = data.Result; - var result = ""; - if (response.Id != null)// dont return a result for notifications - { - result=Newtonsoft.Json.JsonConvert.SerializeObject(response); - } - async.Result = result; - async.SetCompleted(); - return; - } - } - - var err = Newtonsoft.Json.JsonConvert.SerializeObject(response); - - async.Result = err; - async.SetCompleted(); - } - else // this is a batch of requests - { - try - { - rpcBatch = Newtonsoft.Json.JsonConvert.DeserializeObject(json); - responseBatch = new JsonResponse[rpcBatch.Length]; - - for (int i = 0; i < rpcBatch.Length; i++) - { - responseBatch[i] = new JsonResponse(); - if (rpcBatch[i] == null) - { - responseBatch[i].Result = null; - responseBatch[i].Id = null; - responseBatch[i].Error = handler.ProcessParseException(json, new JsonRpcException(-32700, "Parse error", "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.")); - } - else - { - responseBatch[i].Id = rpcBatch[i].Id; - if (rpcBatch[i].Method == null) - { - responseBatch[i].Result = null; - responseBatch[i].Error =handler.ProcessParseException(json, new JsonRpcException(-32600, "Invalid Request", "Missing property 'method'")); - } - } - } - } - catch (Exception ex) - { - response.Result = null; - if (rpc != null) response.Id = rpc.Id; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32700, "Parse error", ex)); - var result = Newtonsoft.Json.JsonConvert.SerializeObject(response); - async.Result = result; - async.SetCompleted(); - return; - } - - // we should have a batch of RPC at this point - var respBuilder = new StringBuilder(); - for (int i = 0; i < rpcBatch.Length; i++) - { - if (i == 0) - { - respBuilder.Append("["); - } - - if (rpcBatch[i] == null || rpcBatch[i].Method == null) - { - responseBatch[i].Error = handler.ProcessParseException(json, new JsonRpcException(-32600, "Invalid Request", "Missing property 'method'")); - } - else if (responseBatch[i].Error == null) - { - var data = handler.Handle(rpcBatch[i], jsonRpcContext); - if (data != null) - { - responseBatch[i].Error = data.Error; - responseBatch[i].Result = data.Result; - - } - } - // dont return a response for notifications. - if (responseBatch[i].Id != null || responseBatch[i].Error != null) - { - var result = Newtonsoft.Json.JsonConvert.SerializeObject(responseBatch[i]); - respBuilder.Append(result); - if (i != rpcBatch.Length - 1) - { - respBuilder.Append(','); - } - } - - if (i == rpcBatch.Length - 1) - { - respBuilder.Append("]"); - var str = respBuilder.ToString(); - async.Result = str; - async.SetCompleted(); // let IIS think we are completed now. - return; - } - } - - // if we made it this far, then there were no items in the array - response.Id = null; - response.Result = null; - response.Error = handler.ProcessParseException(json, new JsonRpcException(3200, "Invalid Request", "Batch of calls was empty.")); - - var err = Newtonsoft.Json.JsonConvert.SerializeObject(response); - - async.Result = err; - async.SetCompleted(); - } + internal static void ProcessJsonRpcState(string sessionId, JsonRpcStateAsync async, object jsonRpcContext = null) + { + async.Result = ProcessInternal(sessionId, async.JsonRpc, jsonRpcContext); + async.SetCompleted(); } public static Task Process(string jsonRpc, object context = null) @@ -219,185 +47,84 @@ public static Task Process(string jsonRpc, object context = null) } public static Task Process(string sessionId, string jsonRpc, object context = null) { - var task = Task.Factory.StartNew((_) => - { - var tup = (Tuple)_; - string _sessionId; - string _jsonRpc; - object _jsonRpcContext = null; - _sessionId = tup.Item1; - _jsonRpc = tup.Item2; - _jsonRpcContext = tup.Item3; - var handler = Handler.GetSessionHandler(_sessionId); - - - JsonRequest[] rpcBatch = null; - JsonResponse[] responseBatch = null; - - JsonRequest rpc = null; - - var callback = string.Empty; - - var response = new JsonResponse(); - - response.Result = null; - response.Error = null; - - string json = _jsonRpc; - - if (isSingleRpc(json)) - { - try - { - if (json.Length > 0) - { - rpc = Newtonsoft.Json.JsonConvert.DeserializeObject(json); - if (rpc == null) - { - response.Result = null; - response.Id = null; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32700, "Parse error", "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.")); - } - else - { - response.Id = rpc.Id; - if (rpc.Method == null) - { - response.Result = null; - response.Id = rpc.Id; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32600, "Invalid Request", "Missing property 'method'")); - } - } - } - else - { - response.Result = null; - response.Id = null; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32600, "Invalid Request", "The JSON sent is not a valid Request object.")); - } - } - catch (Exception ex) - { - response.Result = null; - if (rpc != null) response.Id = rpc.Id; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32700, "Parse error", ex)); - var result = Newtonsoft.Json.JsonConvert.SerializeObject(response); - return result; - } - - if (response.Error == null - && rpc != null - && rpc.Method != null) - { - var data = handler.Handle(rpc, _jsonRpcContext); - if (data != null) - { - response.Error = data.Error; - response.Result = data.Result; - var result = ""; - if (response.Id != null)// dont return a result for notifications - { - result = Newtonsoft.Json.JsonConvert.SerializeObject(response); - } - return result; - } - } - - var err = Newtonsoft.Json.JsonConvert.SerializeObject(response); - - return err; - } - else // this is a batch of requests - { - try - { - rpcBatch = Newtonsoft.Json.JsonConvert.DeserializeObject(json); - responseBatch = new JsonResponse[rpcBatch.Length]; - - for (int i = 0; i < rpcBatch.Length; i++) - { - responseBatch[i] = new JsonResponse(); - if (rpcBatch[i] == null) - { - responseBatch[i].Result = null; - responseBatch[i].Id = null; - responseBatch[i].Error = handler.ProcessParseException(json, new JsonRpcException(-32700, "Parse error", "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.")); - } - else - { - responseBatch[i].Id = rpcBatch[i].Id; - if (rpcBatch[i].Method == null) - { - responseBatch[i].Result = null; - responseBatch[i].Error = handler.ProcessParseException(json, new JsonRpcException(-32600, "Invalid Request", "Missing property 'method'")); - } - } - } - } - catch (Exception ex) - { - response.Result = null; - if (rpc != null) response.Id = rpc.Id; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32700, "Parse error", ex)); - var result = Newtonsoft.Json.JsonConvert.SerializeObject(response); - return result; - } - - // we should have a batch of RPC at this point - var respBuilder = new StringBuilder(); - for (int i = 0; i < rpcBatch.Length; i++) - { - if (i == 0) - { - respBuilder.Append("["); - } - - if (rpcBatch[i] == null || rpcBatch[i].Method == null) - { - responseBatch[i].Error = handler.ProcessParseException(json, new JsonRpcException(-32600, "Invalid Request", "Missing property 'method'")); - } - else if (responseBatch[i].Error == null) - { - var data = Handler.GetSessionHandler(_sessionId).Handle(rpcBatch[i], _jsonRpcContext); - if (data != null) - { - responseBatch[i].Error = data.Error; - responseBatch[i].Result = data.Result; - - } - } - // dont return a response for notifications. - if (responseBatch[i].Id != null || responseBatch[i].Error != null) - { - var result = Newtonsoft.Json.JsonConvert.SerializeObject(responseBatch[i]); - respBuilder.Append(result); - if (i != rpcBatch.Length - 1) - { - respBuilder.Append(','); - } - } - - if (i == rpcBatch.Length - 1) - { - respBuilder.Append("]"); - var str = respBuilder.ToString(); - return str; - } - } - - // if we made it this far, then there were no items in the array - response.Id = null; - response.Result = null; - response.Error = handler.ProcessParseException(json, new JsonRpcException(3200, "Invalid Request", "Batch of calls was empty.")); - - var err = Newtonsoft.Json.JsonConvert.SerializeObject(response); - - return err; - } + return Task.Factory.StartNew((_) => + { + var tuple = (Tuple) _; + return ProcessInternal(tuple.Item1, tuple.Item2, tuple.Item3); }, new Tuple(sessionId, jsonRpc, context)); - return task; - } - + } + + private static string ProcessInternal(string sessionId, string jsonRpc, object jsonRpcContext) + { + var handler = Handler.GetSessionHandler(sessionId); + + try + { + if (isSingleRpc(jsonRpc)) + { + jsonRpc = string.Format("[{0}]", jsonRpc); + } + + var batch = + Newtonsoft.Json.JsonConvert.DeserializeObject(jsonRpc) + .Select(request => new Tuple(request, new JsonResponse())).ToArray(); + + if (batch.Length == 0) + { + return Newtonsoft.Json.JsonConvert.SerializeObject(new JsonResponse + { + Error = handler.ProcessParseException(jsonRpc, + new JsonRpcException(3200, "Invalid Request", "Batch of calls was empty.")) + }); + } + + foreach (var tuple in batch) + { + var jsonRequest = tuple.Item1; + var jsonResponse = tuple.Item2; + + if (jsonRequest == null) + { + jsonResponse.Error = handler.ProcessParseException(jsonRpc, + new JsonRpcException(-32700, "Parse error", + "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.")); + } + else + { + jsonResponse.Id = jsonRequest.Id; + + if (jsonRequest.Method == null) + { + jsonResponse.Error = handler.ProcessParseException(jsonRpc, + new JsonRpcException(-32600, "Invalid Request", "Missing property 'method'")); + } + else + { + var data = handler.Handle(jsonRequest, jsonRpcContext); + + if (data == null) continue; + + jsonResponse.Error = data.Error; + jsonResponse.Result = data.Result; + } + } + } + + var responses = batch.Select(tuple => tuple.Item2) + .Where(resp => resp.Id != null || resp.Error != null) + .Select(Newtonsoft.Json.JsonConvert.SerializeObject).ToArray(); + + return responses.Count() > 1 ? string.Format("[{0}]", string.Join(",", responses)) : responses.First(); + } + catch (Exception ex) + { + return Newtonsoft.Json.JsonConvert.SerializeObject(new JsonResponse + { + Error = handler.ProcessParseException(jsonRpc, new JsonRpcException(-32700, "Parse error", ex)) + }); + } + } + private static bool isSingleRpc(string json) { for (int i = 0; i < json.Length; i++) From 92c660d6466a9fc27aa2e425c4e5b67fcdf0b545 Mon Sep 17 00:00:00 2001 From: Martin Daetz Date: Thu, 29 Jan 2015 14:41:24 +0100 Subject: [PATCH 04/81] fix paramCount Exception, use LastOrDefault instead of paramCount. --- Json-Rpc/Handler.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Json-Rpc/Handler.cs b/Json-Rpc/Handler.cs index d73e358..a192bbb 100644 --- a/Json-Rpc/Handler.cs +++ b/Json-Rpc/Handler.cs @@ -317,8 +317,8 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null) try { - var results = handle.DynamicInvoke(parameters); - var last = parameters.Length>0 ? parameters[paramCount - 1]:null; + var results = handle.DynamicInvoke(parameters); + var last = parameters.LastOrDefault(); JsonRpcException contextException; if (Task.CurrentId.HasValue && RpcExceptions.TryRemove(Task.CurrentId.Value, out contextException)) { From c76a755c751b16bac16c80a83831f7a63dca004e Mon Sep 17 00:00:00 2001 From: Martin Daetz Date: Fri, 30 Jan 2015 08:53:50 +0100 Subject: [PATCH 05/81] add missing reference to Newtonsoft.Json --- .../AustinHarris.JsonRpcTest.csproj | 194 ++++++++++-------- AustinHarris.JsonRpcTest/packages.config | 4 + 2 files changed, 109 insertions(+), 89 deletions(-) create mode 100644 AustinHarris.JsonRpcTest/packages.config diff --git a/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj b/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj index d0a260b..4f73ae8 100644 --- a/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj +++ b/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj @@ -1,96 +1,112 @@ - - - - Debug - AnyCPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD} - Library - Properties - AustinHarris.JsonRpcTest - AustinHarris.JsonRpcTest - v4.0 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - - - 3.5 - - - - - - - - - - - - - - - - - - - - - - {24fc1a2a-0bc3-43a7-9bfe-b628c2c4a307} - AustinHarris.JsonRpc - - - - - - - False - - - False - - - False - - - False - - - - - - + + + + Debug + AnyCPU + {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD} + Library + Properties + AustinHarris.JsonRpcTest + AustinHarris.JsonRpcTest + v4.0 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + ..\ + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + + False + ..\packages\Newtonsoft.Json.6.0.8\lib\net40\Newtonsoft.Json.dll + + + + 3.5 + + + + + + + + + + + + + + + + + + + + + + {24fc1a2a-0bc3-43a7-9bfe-b628c2c4a307} + AustinHarris.JsonRpc + + + + + + + + + + False + + + False + + + False + + + False + + + + + + + + + + Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Aktivieren Sie die Wiederherstellung von NuGet-Paketen, um die fehlende Datei herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". + + + + --> \ No newline at end of file diff --git a/AustinHarris.JsonRpcTest/packages.config b/AustinHarris.JsonRpcTest/packages.config new file mode 100644 index 0000000..0102143 --- /dev/null +++ b/AustinHarris.JsonRpcTest/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From eca13888df47ca0b6668d8ea13ac889fba774974 Mon Sep 17 00:00:00 2001 From: Martin Daetz Date: Thu, 29 Jan 2015 13:22:14 +0100 Subject: [PATCH 06/81] fix batch results removing superfluous commas. refactor JsonRpcProcessor.cs in order to avoid duplicate code. --- AustinHarris.JsonRpcTest/UnitTest1.cs | 22 +- AustinHarris.JsonRpcTest/service.cs | 8 +- Json-Rpc/JsonRpcProcessor.cs | 445 +++++--------------------- 3 files changed, 110 insertions(+), 365 deletions(-) diff --git a/AustinHarris.JsonRpcTest/UnitTest1.cs b/AustinHarris.JsonRpcTest/UnitTest1.cs index d8ebee4..d5f4dbe 100644 --- a/AustinHarris.JsonRpcTest/UnitTest1.cs +++ b/AustinHarris.JsonRpcTest/UnitTest1.cs @@ -1,8 +1,7 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using AustinHarris.JsonRpc.Client; -using AustinHarris.JsonRpc; - +using System; +using AustinHarris.JsonRpc; +using Microsoft.VisualStudio.TestTools.UnitTesting; + namespace UnitTests { [TestClass] @@ -1321,6 +1320,7 @@ public void TestOptionalParametersStrings_BothExists() Assert.IsFalse(result.Result.Contains("error")); Assert.AreEqual(expectedResult, result.Result); } + [TestMethod] public void TestOptionalParametersBoolsAndStrings() { @@ -1333,5 +1333,17 @@ public void TestOptionalParametersBoolsAndStrings() Assert.IsFalse(result.Result.Contains("error")); Assert.AreEqual(expectedResult, result.Result); } + + [TestMethod] + public void TestBatchResult() + { + string request = + @"[{},{""jsonrpc"":""2.0"",""id"":4},{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}]"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + + Assert.IsFalse(result.Result.EndsWith(@",]"), "result.Result.EndsWith(@',]')"); + } } } diff --git a/AustinHarris.JsonRpcTest/service.cs b/AustinHarris.JsonRpcTest/service.cs index 2b3f434..2b36387 100644 --- a/AustinHarris.JsonRpcTest/service.cs +++ b/AustinHarris.JsonRpcTest/service.cs @@ -1,6 +1,7 @@ using AustinHarris.JsonRpc; using System; -using System.Collections.Generic; +using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; @@ -298,5 +299,10 @@ public bool TestOptionalParametersBoolsAndStrings(string input1, bool input2 = t return input2; } + [JsonRpcMethod] + public void Notify(string message) + { + Trace.WriteLine(string.Format("Notified about: {0}", message)); + } } } diff --git a/Json-Rpc/JsonRpcProcessor.cs b/Json-Rpc/JsonRpcProcessor.cs index ffa90b2..f8c3331 100644 --- a/Json-Rpc/JsonRpcProcessor.cs +++ b/Json-Rpc/JsonRpcProcessor.cs @@ -4,7 +4,8 @@ using System.Threading.Tasks; using System.Reflection; using System.IO; -using System.Collections.Generic; +using System.Collections.Generic; +using System.Linq; using System.Text; namespace AustinHarris.JsonRpc @@ -13,10 +14,10 @@ public static class JsonRpcProcessor { public static void Process(JsonRpcStateAsync async, object context = null) { - var t = Task.Factory.StartNew((_async) => + Task.Factory.StartNew((_async) => { - var i = (Tuple)_async; - ProcessJsonRpcState(i.Item1,i.Item2); + var tuple = (Tuple)_async; + ProcessJsonRpcState(tuple.Item1, tuple.Item2); }, new Tuple(async,context)); } @@ -34,183 +35,10 @@ internal static void ProcessJsonRpcState(JsonRpcStateAsync async, object jsonRpc { ProcessJsonRpcState(Handler.DefaultSessionId(), async, jsonRpcContext); } - internal static void ProcessJsonRpcState(string sessionId, JsonRpcStateAsync async, object jsonRpcContext = null) - { - var context = async.AsyncState; - - JsonRequest[] rpcBatch = null; - JsonResponse[] responseBatch = null; - - JsonRequest rpc = null; - var handler = Handler.GetSessionHandler(sessionId); - var callback = string.Empty; - - var response = new JsonResponse(); - - response.Result = null; - response.Error = null; - - string json = async.JsonRpc; - - if (isSingleRpc(json)) - { - try - { - if (json.Length > 0) - { - rpc = Newtonsoft.Json.JsonConvert.DeserializeObject(json); - if (rpc == null) - { - response.Result = null; - response.Id = null; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32700, "Parse error", "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.")); - } - else - { - response.Id = rpc.Id; - if (rpc.Method == null) - { - response.Result = null; - response.Id = rpc.Id; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32600, "Invalid Request", "Missing property 'method'")); - } - } - } - else - { - response.Result = null; - response.Id = null; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32600, "Invalid Request", "The JSON sent is not a valid Request object.")); - } - } - catch (Exception ex) - { - response.Result = null; - if (rpc != null) response.Id = rpc.Id; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32700, "Parse error", ex)); - var result = Newtonsoft.Json.JsonConvert.SerializeObject(response); - async.Result = result; - async.SetCompleted(); - return; - } - - if (response.Error == null - && rpc != null - && rpc.Method != null) - { - var data = Handler.GetSessionHandler(sessionId).Handle(rpc, jsonRpcContext); - if (data != null) - { - response.Error = data.Error; - response.Result = data.Result; - var result = ""; - if (response.Id != null)// dont return a result for notifications - { - result=Newtonsoft.Json.JsonConvert.SerializeObject(response); - } - async.Result = result; - async.SetCompleted(); - return; - } - } - - var err = Newtonsoft.Json.JsonConvert.SerializeObject(response); - - async.Result = err; - async.SetCompleted(); - } - else // this is a batch of requests - { - try - { - rpcBatch = Newtonsoft.Json.JsonConvert.DeserializeObject(json); - responseBatch = new JsonResponse[rpcBatch.Length]; - - for (int i = 0; i < rpcBatch.Length; i++) - { - responseBatch[i] = new JsonResponse(); - if (rpcBatch[i] == null) - { - responseBatch[i].Result = null; - responseBatch[i].Id = null; - responseBatch[i].Error = handler.ProcessParseException(json, new JsonRpcException(-32700, "Parse error", "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.")); - } - else - { - responseBatch[i].Id = rpcBatch[i].Id; - if (rpcBatch[i].Method == null) - { - responseBatch[i].Result = null; - responseBatch[i].Error =handler.ProcessParseException(json, new JsonRpcException(-32600, "Invalid Request", "Missing property 'method'")); - } - } - } - } - catch (Exception ex) - { - response.Result = null; - if (rpc != null) response.Id = rpc.Id; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32700, "Parse error", ex)); - var result = Newtonsoft.Json.JsonConvert.SerializeObject(response); - async.Result = result; - async.SetCompleted(); - return; - } - - // we should have a batch of RPC at this point - var respBuilder = new StringBuilder(); - for (int i = 0; i < rpcBatch.Length; i++) - { - if (i == 0) - { - respBuilder.Append("["); - } - - if (rpcBatch[i] == null || rpcBatch[i].Method == null) - { - responseBatch[i].Error = handler.ProcessParseException(json, new JsonRpcException(-32600, "Invalid Request", "Missing property 'method'")); - } - else if (responseBatch[i].Error == null) - { - var data = handler.Handle(rpcBatch[i], jsonRpcContext); - if (data != null) - { - responseBatch[i].Error = data.Error; - responseBatch[i].Result = data.Result; - - } - } - // dont return a response for notifications. - if (responseBatch[i].Id != null || responseBatch[i].Error != null) - { - var result = Newtonsoft.Json.JsonConvert.SerializeObject(responseBatch[i]); - respBuilder.Append(result); - if (i != rpcBatch.Length - 1) - { - respBuilder.Append(','); - } - } - - if (i == rpcBatch.Length - 1) - { - respBuilder.Append("]"); - var str = respBuilder.ToString(); - async.Result = str; - async.SetCompleted(); // let IIS think we are completed now. - return; - } - } - - // if we made it this far, then there were no items in the array - response.Id = null; - response.Result = null; - response.Error = handler.ProcessParseException(json, new JsonRpcException(3200, "Invalid Request", "Batch of calls was empty.")); - - var err = Newtonsoft.Json.JsonConvert.SerializeObject(response); - - async.Result = err; - async.SetCompleted(); - } + internal static void ProcessJsonRpcState(string sessionId, JsonRpcStateAsync async, object jsonRpcContext = null) + { + async.Result = ProcessInternal(sessionId, async.JsonRpc, jsonRpcContext); + async.SetCompleted(); } public static Task Process(string jsonRpc, object context = null) @@ -219,185 +47,84 @@ public static Task Process(string jsonRpc, object context = null) } public static Task Process(string sessionId, string jsonRpc, object context = null) { - var task = Task.Factory.StartNew((_) => - { - var tup = (Tuple)_; - string _sessionId; - string _jsonRpc; - object _jsonRpcContext = null; - _sessionId = tup.Item1; - _jsonRpc = tup.Item2; - _jsonRpcContext = tup.Item3; - var handler = Handler.GetSessionHandler(_sessionId); - - - JsonRequest[] rpcBatch = null; - JsonResponse[] responseBatch = null; - - JsonRequest rpc = null; - - var callback = string.Empty; - - var response = new JsonResponse(); - - response.Result = null; - response.Error = null; - - string json = _jsonRpc; - - if (isSingleRpc(json)) - { - try - { - if (json.Length > 0) - { - rpc = Newtonsoft.Json.JsonConvert.DeserializeObject(json); - if (rpc == null) - { - response.Result = null; - response.Id = null; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32700, "Parse error", "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.")); - } - else - { - response.Id = rpc.Id; - if (rpc.Method == null) - { - response.Result = null; - response.Id = rpc.Id; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32600, "Invalid Request", "Missing property 'method'")); - } - } - } - else - { - response.Result = null; - response.Id = null; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32600, "Invalid Request", "The JSON sent is not a valid Request object.")); - } - } - catch (Exception ex) - { - response.Result = null; - if (rpc != null) response.Id = rpc.Id; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32700, "Parse error", ex)); - var result = Newtonsoft.Json.JsonConvert.SerializeObject(response); - return result; - } - - if (response.Error == null - && rpc != null - && rpc.Method != null) - { - var data = handler.Handle(rpc, _jsonRpcContext); - if (data != null) - { - response.Error = data.Error; - response.Result = data.Result; - var result = ""; - if (response.Id != null)// dont return a result for notifications - { - result = Newtonsoft.Json.JsonConvert.SerializeObject(response); - } - return result; - } - } - - var err = Newtonsoft.Json.JsonConvert.SerializeObject(response); - - return err; - } - else // this is a batch of requests - { - try - { - rpcBatch = Newtonsoft.Json.JsonConvert.DeserializeObject(json); - responseBatch = new JsonResponse[rpcBatch.Length]; - - for (int i = 0; i < rpcBatch.Length; i++) - { - responseBatch[i] = new JsonResponse(); - if (rpcBatch[i] == null) - { - responseBatch[i].Result = null; - responseBatch[i].Id = null; - responseBatch[i].Error = handler.ProcessParseException(json, new JsonRpcException(-32700, "Parse error", "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.")); - } - else - { - responseBatch[i].Id = rpcBatch[i].Id; - if (rpcBatch[i].Method == null) - { - responseBatch[i].Result = null; - responseBatch[i].Error = handler.ProcessParseException(json, new JsonRpcException(-32600, "Invalid Request", "Missing property 'method'")); - } - } - } - } - catch (Exception ex) - { - response.Result = null; - if (rpc != null) response.Id = rpc.Id; - response.Error = handler.ProcessParseException(json, new JsonRpcException(-32700, "Parse error", ex)); - var result = Newtonsoft.Json.JsonConvert.SerializeObject(response); - return result; - } - - // we should have a batch of RPC at this point - var respBuilder = new StringBuilder(); - for (int i = 0; i < rpcBatch.Length; i++) - { - if (i == 0) - { - respBuilder.Append("["); - } - - if (rpcBatch[i] == null || rpcBatch[i].Method == null) - { - responseBatch[i].Error = handler.ProcessParseException(json, new JsonRpcException(-32600, "Invalid Request", "Missing property 'method'")); - } - else if (responseBatch[i].Error == null) - { - var data = Handler.GetSessionHandler(_sessionId).Handle(rpcBatch[i], _jsonRpcContext); - if (data != null) - { - responseBatch[i].Error = data.Error; - responseBatch[i].Result = data.Result; - - } - } - // dont return a response for notifications. - if (responseBatch[i].Id != null || responseBatch[i].Error != null) - { - var result = Newtonsoft.Json.JsonConvert.SerializeObject(responseBatch[i]); - respBuilder.Append(result); - if (i != rpcBatch.Length - 1) - { - respBuilder.Append(','); - } - } - - if (i == rpcBatch.Length - 1) - { - respBuilder.Append("]"); - var str = respBuilder.ToString(); - return str; - } - } - - // if we made it this far, then there were no items in the array - response.Id = null; - response.Result = null; - response.Error = handler.ProcessParseException(json, new JsonRpcException(3200, "Invalid Request", "Batch of calls was empty.")); - - var err = Newtonsoft.Json.JsonConvert.SerializeObject(response); - - return err; - } + return Task.Factory.StartNew((_) => + { + var tuple = (Tuple) _; + return ProcessInternal(tuple.Item1, tuple.Item2, tuple.Item3); }, new Tuple(sessionId, jsonRpc, context)); - return task; - } - + } + + private static string ProcessInternal(string sessionId, string jsonRpc, object jsonRpcContext) + { + var handler = Handler.GetSessionHandler(sessionId); + + try + { + if (isSingleRpc(jsonRpc)) + { + jsonRpc = string.Format("[{0}]", jsonRpc); + } + + var batch = + Newtonsoft.Json.JsonConvert.DeserializeObject(jsonRpc) + .Select(request => new Tuple(request, new JsonResponse())).ToArray(); + + if (batch.Length == 0) + { + return Newtonsoft.Json.JsonConvert.SerializeObject(new JsonResponse + { + Error = handler.ProcessParseException(jsonRpc, + new JsonRpcException(3200, "Invalid Request", "Batch of calls was empty.")) + }); + } + + foreach (var tuple in batch) + { + var jsonRequest = tuple.Item1; + var jsonResponse = tuple.Item2; + + if (jsonRequest == null) + { + jsonResponse.Error = handler.ProcessParseException(jsonRpc, + new JsonRpcException(-32700, "Parse error", + "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.")); + } + else + { + jsonResponse.Id = jsonRequest.Id; + + if (jsonRequest.Method == null) + { + jsonResponse.Error = handler.ProcessParseException(jsonRpc, + new JsonRpcException(-32600, "Invalid Request", "Missing property 'method'")); + } + else + { + var data = handler.Handle(jsonRequest, jsonRpcContext); + + if (data == null) continue; + + jsonResponse.Error = data.Error; + jsonResponse.Result = data.Result; + } + } + } + + var responses = batch.Select(tuple => tuple.Item2) + .Where(resp => resp.Id != null || resp.Error != null) + .Select(Newtonsoft.Json.JsonConvert.SerializeObject).ToArray(); + + return responses.Count() > 1 ? string.Format("[{0}]", string.Join(",", responses)) : responses.First(); + } + catch (Exception ex) + { + return Newtonsoft.Json.JsonConvert.SerializeObject(new JsonResponse + { + Error = handler.ProcessParseException(jsonRpc, new JsonRpcException(-32700, "Parse error", ex)) + }); + } + } + private static bool isSingleRpc(string json) { for (int i = 0; i < json.Length; i++) From e722a880a115fb852e394eb867444f2e4d01a77f Mon Sep 17 00:00:00 2001 From: Martin Daetz Date: Fri, 30 Jan 2015 08:53:50 +0100 Subject: [PATCH 07/81] add missing reference to Newtonsoft.Json --- .../AustinHarris.JsonRpcTest.csproj | 194 ++++++++++-------- AustinHarris.JsonRpcTest/packages.config | 4 + 2 files changed, 109 insertions(+), 89 deletions(-) create mode 100644 AustinHarris.JsonRpcTest/packages.config diff --git a/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj b/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj index d0a260b..4f73ae8 100644 --- a/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj +++ b/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj @@ -1,96 +1,112 @@ - - - - Debug - AnyCPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD} - Library - Properties - AustinHarris.JsonRpcTest - AustinHarris.JsonRpcTest - v4.0 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - - - 3.5 - - - - - - - - - - - - - - - - - - - - - - {24fc1a2a-0bc3-43a7-9bfe-b628c2c4a307} - AustinHarris.JsonRpc - - - - - - - False - - - False - - - False - - - False - - - - - - + + + + Debug + AnyCPU + {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD} + Library + Properties + AustinHarris.JsonRpcTest + AustinHarris.JsonRpcTest + v4.0 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + ..\ + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + + False + ..\packages\Newtonsoft.Json.6.0.8\lib\net40\Newtonsoft.Json.dll + + + + 3.5 + + + + + + + + + + + + + + + + + + + + + + {24fc1a2a-0bc3-43a7-9bfe-b628c2c4a307} + AustinHarris.JsonRpc + + + + + + + + + + False + + + False + + + False + + + False + + + + + + + + + + Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Aktivieren Sie die Wiederherstellung von NuGet-Paketen, um die fehlende Datei herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". + + + + --> \ No newline at end of file diff --git a/AustinHarris.JsonRpcTest/packages.config b/AustinHarris.JsonRpcTest/packages.config new file mode 100644 index 0000000..0102143 --- /dev/null +++ b/AustinHarris.JsonRpcTest/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From 431b3de00ec51fa2134d5283a71e0a022c31982f Mon Sep 17 00:00:00 2001 From: Martin Daetz Date: Fri, 30 Jan 2015 09:22:08 +0100 Subject: [PATCH 08/81] roll back from reference to Newtonsoft.Json --- AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj | 7 ------- AustinHarris.JsonRpcTest/packages.config | 4 ---- 2 files changed, 11 deletions(-) delete mode 100644 AustinHarris.JsonRpcTest/packages.config diff --git a/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj b/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj index 4f73ae8..52d431d 100644 --- a/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj +++ b/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj @@ -40,10 +40,6 @@ false - - False - ..\packages\Newtonsoft.Json.6.0.8\lib\net40\Newtonsoft.Json.dll - 3.5 @@ -72,9 +68,6 @@ AustinHarris.JsonRpc - - - diff --git a/AustinHarris.JsonRpcTest/packages.config b/AustinHarris.JsonRpcTest/packages.config deleted file mode 100644 index 0102143..0000000 --- a/AustinHarris.JsonRpcTest/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file From c1d066cb5aed77de0aee4d5d1b6a5b5fb9e5d826 Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Fri, 30 Jan 2015 14:57:16 -0700 Subject: [PATCH 09/81] reduce cost of adding [] around a single rpc by 2.2% --- Json-Rpc/JsonRpcProcessor.cs | 119 ++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 58 deletions(-) diff --git a/Json-Rpc/JsonRpcProcessor.cs b/Json-Rpc/JsonRpcProcessor.cs index f8c3331..f094111 100644 --- a/Json-Rpc/JsonRpcProcessor.cs +++ b/Json-Rpc/JsonRpcProcessor.cs @@ -1,57 +1,57 @@ -using System; -using System.Globalization; -using System.Threading; -using System.Threading.Tasks; -using System.Reflection; -using System.IO; +using System; +using System.Globalization; +using System.Threading; +using System.Threading.Tasks; +using System.Reflection; +using System.IO; using System.Collections.Generic; using System.Linq; -using System.Text; - -namespace AustinHarris.JsonRpc -{ - public static class JsonRpcProcessor - { - public static void Process(JsonRpcStateAsync async, object context = null) - { - Task.Factory.StartNew((_async) => - { - var tuple = (Tuple)_async; - ProcessJsonRpcState(tuple.Item1, tuple.Item2); - }, new Tuple(async,context)); - - } - - public static void Process(string sessionId, JsonRpcStateAsync async, object context = null) - { - var t = Task.Factory.StartNew((_async) => - { - var i = (Tuple)_async; - ProcessJsonRpcState(i.Item1, i.Item2, i.Item3); - }, new Tuple(sessionId, async, context)); - - } - internal static void ProcessJsonRpcState(JsonRpcStateAsync async, object jsonRpcContext = null) - { - ProcessJsonRpcState(Handler.DefaultSessionId(), async, jsonRpcContext); - } +using System.Text; + +namespace AustinHarris.JsonRpc +{ + public static class JsonRpcProcessor + { + public static void Process(JsonRpcStateAsync async, object context = null) + { + Task.Factory.StartNew((_async) => + { + var tuple = (Tuple)_async; + ProcessJsonRpcState(tuple.Item1, tuple.Item2); + }, new Tuple(async,context)); + + } + + public static void Process(string sessionId, JsonRpcStateAsync async, object context = null) + { + var t = Task.Factory.StartNew((_async) => + { + var i = (Tuple)_async; + ProcessJsonRpcState(i.Item1, i.Item2, i.Item3); + }, new Tuple(sessionId, async, context)); + + } + internal static void ProcessJsonRpcState(JsonRpcStateAsync async, object jsonRpcContext = null) + { + ProcessJsonRpcState(Handler.DefaultSessionId(), async, jsonRpcContext); + } internal static void ProcessJsonRpcState(string sessionId, JsonRpcStateAsync async, object jsonRpcContext = null) { async.Result = ProcessInternal(sessionId, async.JsonRpc, jsonRpcContext); - async.SetCompleted(); - } - - public static Task Process(string jsonRpc, object context = null) - { - return Process(Handler.DefaultSessionId(), jsonRpc, context); - } - public static Task Process(string sessionId, string jsonRpc, object context = null) - { + async.SetCompleted(); + } + + public static Task Process(string jsonRpc, object context = null) + { + return Process(Handler.DefaultSessionId(), jsonRpc, context); + } + public static Task Process(string sessionId, string jsonRpc, object context = null) + { return Task.Factory.StartNew((_) => { - var tuple = (Tuple) _; + var tuple = (Tuple) _; return ProcessInternal(tuple.Item1, tuple.Item2, tuple.Item3); - }, new Tuple(sessionId, jsonRpc, context)); + }, new Tuple(sessionId, jsonRpc, context)); } private static string ProcessInternal(string sessionId, string jsonRpc, object jsonRpcContext) @@ -62,7 +62,10 @@ private static string ProcessInternal(string sessionId, string jsonRpc, object j { if (isSingleRpc(jsonRpc)) { - jsonRpc = string.Format("[{0}]", jsonRpc); + var sbAddBrackets = new StringBuilder("[", jsonRpc.Length + 2); + sbAddBrackets.Append(jsonRpc); + sbAddBrackets.Append("]"); + jsonRpc = sbAddBrackets.ToString(); } var batch = @@ -125,14 +128,14 @@ private static string ProcessInternal(string sessionId, string jsonRpc, object j } } - private static bool isSingleRpc(string json) - { - for (int i = 0; i < json.Length; i++) - { - if (json[i] == '{') return true; - else if (json[i] == '[') return false; - } - return true; - } - } -} + private static bool isSingleRpc(string json) + { + for (int i = 0; i < json.Length; i++) + { + if (json[i] == '{') return true; + else if (json[i] == '[') return false; + } + return true; + } + } +} From 87d61b7cf02161b5be1362d691f8566d392819d7 Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Fri, 30 Jan 2015 15:11:05 -0700 Subject: [PATCH 10/81] reduce cost of initializing 'batch' in ProcessInternal by 8% when isSignleRpc is true --- Json-Rpc/JsonRpcProcessor.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Json-Rpc/JsonRpcProcessor.cs b/Json-Rpc/JsonRpcProcessor.cs index f094111..6603661 100644 --- a/Json-Rpc/JsonRpcProcessor.cs +++ b/Json-Rpc/JsonRpcProcessor.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using Newtonsoft.Json; namespace AustinHarris.JsonRpc { @@ -60,18 +61,18 @@ private static string ProcessInternal(string sessionId, string jsonRpc, object j try { + Tuple[] batch = null; if (isSingleRpc(jsonRpc)) { - var sbAddBrackets = new StringBuilder("[", jsonRpc.Length + 2); - sbAddBrackets.Append(jsonRpc); - sbAddBrackets.Append("]"); - jsonRpc = sbAddBrackets.ToString(); + batch = new [] { Tuple.Create(JsonConvert.DeserializeObject(jsonRpc), new JsonResponse()) }; } - - var batch = - Newtonsoft.Json.JsonConvert.DeserializeObject(jsonRpc) - .Select(request => new Tuple(request, new JsonResponse())).ToArray(); - + else + { + batch = JsonConvert.DeserializeObject(jsonRpc) + .Select(request => new Tuple(request, new JsonResponse())) + .ToArray(); + } + if (batch.Length == 0) { return Newtonsoft.Json.JsonConvert.SerializeObject(new JsonResponse From 4b08ea9afa62b9072b8e2b3ef71ad11cafa29d2e Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Fri, 30 Jan 2015 15:38:55 -0700 Subject: [PATCH 11/81] Improve perf of ProcessInternal by ~ 4% --- Json-Rpc/JsonRpcProcessor.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Json-Rpc/JsonRpcProcessor.cs b/Json-Rpc/JsonRpcProcessor.cs index 6603661..f8c4e01 100644 --- a/Json-Rpc/JsonRpcProcessor.cs +++ b/Json-Rpc/JsonRpcProcessor.cs @@ -114,11 +114,14 @@ private static string ProcessInternal(string sessionId, string jsonRpc, object j } } - var responses = batch.Select(tuple => tuple.Item2) - .Where(resp => resp.Id != null || resp.Error != null) - .Select(Newtonsoft.Json.JsonConvert.SerializeObject).ToArray(); + var responses = new string[batch.Count(x=>x.Item2.Id!=null || x.Item2.Error != null)]; + var idx = 0; + foreach (var resp in batch.Where(x => x.Item2.Id != null || x.Item2.Error != null)) + { + responses[idx++] = JsonConvert.SerializeObject(resp.Item2); + } - return responses.Count() > 1 ? string.Format("[{0}]", string.Join(",", responses)) : responses.First(); + return responses.Length == 1 ? responses[0] : string.Format("[{0}]", string.Join(",", responses)); } catch (Exception ex) { From 2623b05b0d6bd2e52e58e823516e0ad166fdacb0 Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Fri, 30 Jan 2015 17:34:18 -0700 Subject: [PATCH 12/81] Improve perf of CleanUpParameter significantly for common types that have an explicity converter from JToken --- Json-Rpc/Handler.cs | 846 +++++++++++++++++++++++--------------------- 1 file changed, 443 insertions(+), 403 deletions(-) diff --git a/Json-Rpc/Handler.cs b/Json-Rpc/Handler.cs index a192bbb..4fa7845 100644 --- a/Json-Rpc/Handler.cs +++ b/Json-Rpc/Handler.cs @@ -1,271 +1,271 @@ -namespace AustinHarris.JsonRpc -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Linq; - using System.Reflection; - using Newtonsoft.Json; - using System.Threading.Tasks; - using System.Collections.Concurrent; -using Newtonsoft.Json.Linq; - - public class Handler - { - #region Members - - //private static Handler current; - private static ConcurrentDictionary _sessionHandlers; - private static string _defaultSessionId; - #endregion - - #region Constructors - - static Handler() - { - //current = new Handler(Guid.NewGuid().ToString()); - _defaultSessionId = Guid.NewGuid().ToString(); - _sessionHandlers = new ConcurrentDictionary(); - _sessionHandlers[_defaultSessionId]= new Handler(_defaultSessionId); - } - - private Handler(string sessionId) - { - SessionId = sessionId; - this.MetaData = new SMD(); - this.Handlers = new Dictionary(); - } - - #endregion - - #region Properties - - /// - /// Returns the SessionID of the default session - /// - /// - public static string DefaultSessionId() { return _defaultSessionId; } - - /// - /// Gets a specific session - /// - /// The sessionId of the handler you want to retrieve. - /// - public static Handler GetSessionHandler(string sessionId) - { - return _sessionHandlers.GetOrAdd(sessionId, new Handler(sessionId)); - } - - /// - /// gets the default session - /// - /// The default Session Handler - public static Handler GetSessionHandler() - { - return GetSessionHandler(_defaultSessionId); - } - - /// - /// Removes and clears the Handler with the specific sessionID from the registry of Handlers - /// - /// - public static void DestroySession(string sessionId) - { - Handler h; - _sessionHandlers.TryRemove(sessionId,out h); - h.Handlers.Clear(); - h.MetaData.Services.Clear(); - } - /// - /// Removes and clears the current Handler from the registry of Handlers - /// - public void Destroy() - { - DestroySession(SessionId); - } - - /// - /// Gets the default session handler - /// - public static Handler DefaultHandler { get { return GetSessionHandler(_defaultSessionId); } } - - /// - /// The sessionID of this Handler - /// - public string SessionId { get; private set; } - - private static ConcurrentDictionary RpcContexts = new ConcurrentDictionary(); - private static ConcurrentDictionary RpcExceptions = new ConcurrentDictionary(); - - /// - /// Provides access to a context specific to each JsonRpc method invocation. - /// Warning: Must be called from within the execution context of the jsonRpc Method to return the context - /// - /// - public static object RpcContext() - { - if (Task.CurrentId == null) - return null; - - if (RpcContexts.ContainsKey(Task.CurrentId.Value) == false) - return null; - - return RpcContexts[Task.CurrentId.Value]; - } - - /// - /// Allows you to set the exception used in in the JsonRpc response. - /// Warning: Must be called from within the execution context of the jsonRpc method. - /// - /// - public static void RpcSetException(JsonRpcException exception) - { - if (Task.CurrentId != null) - RpcExceptions[Task.CurrentId.Value] = exception; - else - throw new InvalidOperationException("This method is only valid when used within the context of a method marked as a JsonRpcMethod, and that method must of been invoked by the JsonRpc Handler."); - } - - private void RemoveRpcException() - { - if (Task.CurrentId != null) - { - var id = Task.CurrentId.Value; - RpcExceptions[id] = null; - JsonRpcException va; - RpcExceptions.TryRemove(id, out va); - } - } - - private AustinHarris.JsonRpc.PreProcessHandler externalPreProcessingHandler; - private Func externalErrorHandler; - private Func parseErrorHandler; - private Dictionary Handlers { get; set; } - #endregion - - /// - /// This metadata contains all the types and mappings of all the methods in this handler. Warning: Modifying this directly could cause your handler to no longer function. - /// - public SMD MetaData { get; set; } - - #region Public Methods - - /// - /// Registers a jsonRpc method name (key) to be mapped to a specific function - /// - /// The Method as it will be called from JsonRpc - /// The method that will be invoked - /// - public bool Register(string key, Delegate handle) - { - var result = false; - - if (!this.Handlers.ContainsKey(key)) - { - this.Handlers.Add(key, handle); - } - - return result; - } - - public void UnRegister(string key) - { - this.Handlers.Remove(key); - MetaData.Services.Remove(key); - } - - /// - /// Invokes a method to handle a JsonRpc request. - /// - /// JsonRpc Request to be processed - /// Optional context that will be available from within the jsonRpcMethod. - /// - public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null) - { - AddRpcContext(RpcContext); - - var preProcessingException = PreProcess(Rpc, RpcContext); - if (preProcessingException != null) - { - return new JsonResponse() { Error = preProcessingException, - Id = Rpc.Id }; - } - - SMDService metadata = null; - Delegate handle = null; - var haveDelegate = this.Handlers.TryGetValue(Rpc.Method, out handle); - var haveMetadata = this.MetaData.Services.TryGetValue(Rpc.Method, out metadata); - - if (haveDelegate == false || haveMetadata == false || metadata == null || handle == null) - { - return new JsonResponse() { Result = null, Error = new JsonRpcException(-32601, "Method not found", "The method does not exist / is not available."), Id = Rpc.Id }; - } - if (Rpc.Params is ICollection == false) - { - return new JsonResponse() - { - Result = null, - Error = new JsonRpcException(-32602, - "Invalid params", "The number of parameters could not be counted"), - Id = Rpc.Id - }; - } - - bool isJObject = Rpc.Params is Newtonsoft.Json.Linq.JObject; - bool isJArray = Rpc.Params is Newtonsoft.Json.Linq.JArray; - object[] parameters = null; - bool expectsRefException = false; - var metaDataParamCount = metadata.parameters.Count(x => x != null); - - var getCount = Rpc.Params as ICollection; - var loopCt = getCount.Count; - var paramCount = loopCt; - if (paramCount == metaDataParamCount - 1 && metadata.parameters[metaDataParamCount-1].ObjectType.Name.Contains(typeof(JsonRpcException).Name)) - { - paramCount++; - expectsRefException = true; - } - parameters = new object[paramCount]; - - if (isJArray) - { - var jarr = ((Newtonsoft.Json.Linq.JArray)Rpc.Params); - //var loopCt = jarr.Count; - //var pCount = loopCt; - //if (pCount == metaDataParamCount - 1 && metadata.parameters[metaDataParamCount].GetType() == typeof(JsonRpcException)) - // pCount++; - //parameters = new object[pCount]; - for (int i = 0; i < loopCt; i++) - { - parameters[i] = CleanUpParameter(jarr[i], metadata.parameters[i]); - } - } - else if (isJObject) - { - var jo = Rpc.Params as Newtonsoft.Json.Linq.JObject; - //var loopCt = jo.Count; - //var pCount = loopCt; - //if (pCount == metaDataParamCount - 1 && metadata.parameters[metaDataParamCount].GetType() == typeof(JsonRpcException)) - // pCount++; - //parameters = new object[pCount]; - var asDict = jo as IDictionary; - for (int i = 0; i < loopCt; i++) - { - if (asDict.ContainsKey(metadata.parameters[i].Name) == false) - { - return new JsonResponse() - { - Error = ProcessException(Rpc, - new JsonRpcException(-32602, - "Invalid params", - string.Format("Named parameter '{0}' was not present.", - metadata.parameters[i].Name) - )) - ,Id = Rpc.Id - }; - } - parameters[i] = CleanUpParameter(jo[metadata.parameters[i].Name], metadata.parameters[i]); - } +namespace AustinHarris.JsonRpc +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Linq; + using System.Reflection; + using Newtonsoft.Json; + using System.Threading.Tasks; + using System.Collections.Concurrent; +using Newtonsoft.Json.Linq; + + public class Handler + { + #region Members + + //private static Handler current; + private static ConcurrentDictionary _sessionHandlers; + private static string _defaultSessionId; + #endregion + + #region Constructors + + static Handler() + { + //current = new Handler(Guid.NewGuid().ToString()); + _defaultSessionId = Guid.NewGuid().ToString(); + _sessionHandlers = new ConcurrentDictionary(); + _sessionHandlers[_defaultSessionId]= new Handler(_defaultSessionId); + } + + private Handler(string sessionId) + { + SessionId = sessionId; + this.MetaData = new SMD(); + this.Handlers = new Dictionary(); + } + + #endregion + + #region Properties + + /// + /// Returns the SessionID of the default session + /// + /// + public static string DefaultSessionId() { return _defaultSessionId; } + + /// + /// Gets a specific session + /// + /// The sessionId of the handler you want to retrieve. + /// + public static Handler GetSessionHandler(string sessionId) + { + return _sessionHandlers.GetOrAdd(sessionId, new Handler(sessionId)); + } + + /// + /// gets the default session + /// + /// The default Session Handler + public static Handler GetSessionHandler() + { + return GetSessionHandler(_defaultSessionId); + } + + /// + /// Removes and clears the Handler with the specific sessionID from the registry of Handlers + /// + /// + public static void DestroySession(string sessionId) + { + Handler h; + _sessionHandlers.TryRemove(sessionId,out h); + h.Handlers.Clear(); + h.MetaData.Services.Clear(); + } + /// + /// Removes and clears the current Handler from the registry of Handlers + /// + public void Destroy() + { + DestroySession(SessionId); + } + + /// + /// Gets the default session handler + /// + public static Handler DefaultHandler { get { return GetSessionHandler(_defaultSessionId); } } + + /// + /// The sessionID of this Handler + /// + public string SessionId { get; private set; } + + private static ConcurrentDictionary RpcContexts = new ConcurrentDictionary(); + private static ConcurrentDictionary RpcExceptions = new ConcurrentDictionary(); + + /// + /// Provides access to a context specific to each JsonRpc method invocation. + /// Warning: Must be called from within the execution context of the jsonRpc Method to return the context + /// + /// + public static object RpcContext() + { + if (Task.CurrentId == null) + return null; + + if (RpcContexts.ContainsKey(Task.CurrentId.Value) == false) + return null; + + return RpcContexts[Task.CurrentId.Value]; + } + + /// + /// Allows you to set the exception used in in the JsonRpc response. + /// Warning: Must be called from within the execution context of the jsonRpc method. + /// + /// + public static void RpcSetException(JsonRpcException exception) + { + if (Task.CurrentId != null) + RpcExceptions[Task.CurrentId.Value] = exception; + else + throw new InvalidOperationException("This method is only valid when used within the context of a method marked as a JsonRpcMethod, and that method must of been invoked by the JsonRpc Handler."); + } + + private void RemoveRpcException() + { + if (Task.CurrentId != null) + { + var id = Task.CurrentId.Value; + RpcExceptions[id] = null; + JsonRpcException va; + RpcExceptions.TryRemove(id, out va); + } + } + + private AustinHarris.JsonRpc.PreProcessHandler externalPreProcessingHandler; + private Func externalErrorHandler; + private Func parseErrorHandler; + private Dictionary Handlers { get; set; } + #endregion + + /// + /// This metadata contains all the types and mappings of all the methods in this handler. Warning: Modifying this directly could cause your handler to no longer function. + /// + public SMD MetaData { get; set; } + + #region Public Methods + + /// + /// Registers a jsonRpc method name (key) to be mapped to a specific function + /// + /// The Method as it will be called from JsonRpc + /// The method that will be invoked + /// + public bool Register(string key, Delegate handle) + { + var result = false; + + if (!this.Handlers.ContainsKey(key)) + { + this.Handlers.Add(key, handle); + } + + return result; + } + + public void UnRegister(string key) + { + this.Handlers.Remove(key); + MetaData.Services.Remove(key); + } + + /// + /// Invokes a method to handle a JsonRpc request. + /// + /// JsonRpc Request to be processed + /// Optional context that will be available from within the jsonRpcMethod. + /// + public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null) + { + AddRpcContext(RpcContext); + + var preProcessingException = PreProcess(Rpc, RpcContext); + if (preProcessingException != null) + { + return new JsonResponse() { Error = preProcessingException, + Id = Rpc.Id }; + } + + SMDService metadata = null; + Delegate handle = null; + var haveDelegate = this.Handlers.TryGetValue(Rpc.Method, out handle); + var haveMetadata = this.MetaData.Services.TryGetValue(Rpc.Method, out metadata); + + if (haveDelegate == false || haveMetadata == false || metadata == null || handle == null) + { + return new JsonResponse() { Result = null, Error = new JsonRpcException(-32601, "Method not found", "The method does not exist / is not available."), Id = Rpc.Id }; + } + if (Rpc.Params is ICollection == false) + { + return new JsonResponse() + { + Result = null, + Error = new JsonRpcException(-32602, + "Invalid params", "The number of parameters could not be counted"), + Id = Rpc.Id + }; + } + + bool isJObject = Rpc.Params is Newtonsoft.Json.Linq.JObject; + bool isJArray = Rpc.Params is Newtonsoft.Json.Linq.JArray; + object[] parameters = null; + bool expectsRefException = false; + var metaDataParamCount = metadata.parameters.Count(x => x != null); + + var getCount = Rpc.Params as ICollection; + var loopCt = getCount.Count; + var paramCount = loopCt; + if (paramCount == metaDataParamCount - 1 && metadata.parameters[metaDataParamCount-1].ObjectType.Name.Contains(typeof(JsonRpcException).Name)) + { + paramCount++; + expectsRefException = true; + } + parameters = new object[paramCount]; + + if (isJArray) + { + var jarr = ((Newtonsoft.Json.Linq.JArray)Rpc.Params); + //var loopCt = jarr.Count; + //var pCount = loopCt; + //if (pCount == metaDataParamCount - 1 && metadata.parameters[metaDataParamCount].GetType() == typeof(JsonRpcException)) + // pCount++; + //parameters = new object[pCount]; + for (int i = 0; i < loopCt; i++) + { + parameters[i] = CleanUpParameter(jarr[i], metadata.parameters[i]); + } + } + else if (isJObject) + { + var jo = Rpc.Params as Newtonsoft.Json.Linq.JObject; + //var loopCt = jo.Count; + //var pCount = loopCt; + //if (pCount == metaDataParamCount - 1 && metadata.parameters[metaDataParamCount].GetType() == typeof(JsonRpcException)) + // pCount++; + //parameters = new object[pCount]; + var asDict = jo as IDictionary; + for (int i = 0; i < loopCt; i++) + { + if (asDict.ContainsKey(metadata.parameters[i].Name) == false) + { + return new JsonResponse() + { + Error = ProcessException(Rpc, + new JsonRpcException(-32602, + "Invalid params", + string.Format("Named parameter '{0}' was not present.", + metadata.parameters[i].Name) + )) + ,Id = Rpc.Id + }; + } + parameters[i] = CleanUpParameter(jo[metadata.parameters[i].Name], metadata.parameters[i]); + } } // Optional Parameter support @@ -299,139 +299,179 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null) }; } } - - if (parameters.Length != metaDataParamCount) - { - return new JsonResponse() - { - Error = ProcessException(Rpc, - new JsonRpcException(-32602, - "Invalid params", - string.Format("Expecting {0} parameters, and received {1}", - metadata.parameters.Length, - parameters.Length) - )), - Id = Rpc.Id - }; - } - - try - { + + if (parameters.Length != metaDataParamCount) + { + return new JsonResponse() + { + Error = ProcessException(Rpc, + new JsonRpcException(-32602, + "Invalid params", + string.Format("Expecting {0} parameters, and received {1}", + metadata.parameters.Length, + parameters.Length) + )), + Id = Rpc.Id + }; + } + + try + { var results = handle.DynamicInvoke(parameters); - var last = parameters.LastOrDefault(); - JsonRpcException contextException; - if (Task.CurrentId.HasValue && RpcExceptions.TryRemove(Task.CurrentId.Value, out contextException)) - { - return new JsonResponse() { Error = ProcessException(Rpc, contextException), Id = Rpc.Id }; - } - if (expectsRefException && last != null && last is JsonRpcException) - { - return new JsonResponse() { Error = ProcessException(Rpc, last as JsonRpcException), Id = Rpc.Id }; - } - - return new JsonResponse() { Result = results }; - } - catch (Exception ex) - { - if (ex is TargetParameterCountException) - { - return new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32602, "Invalid params", ex)) }; - } - - // We really dont care about the TargetInvocationException, just pass on the inner exception - if (ex is JsonRpcException) - { - return new JsonResponse() { Error = ProcessException(Rpc, ex as JsonRpcException) }; - } - if (ex.InnerException != null && ex.InnerException is JsonRpcException) - { - return new JsonResponse() { Error = ProcessException(Rpc, ex.InnerException as JsonRpcException) }; - } - else if (ex.InnerException != null) - { - return new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32603, "Internal Error", ex.InnerException)) }; - } - - return new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32603, "Internal Error", ex)) }; - } - finally - { - RemoveRpcContext(); - } - } - - private void AddRpcContext(object RpcContext) - { - if (Task.CurrentId != null) - RpcContexts[Task.CurrentId.Value] = RpcContext; - } - private void RemoveRpcContext() - { - if (Task.CurrentId != null) - { - var id = Task.CurrentId.Value; - RpcContexts[id] = null; - object va; - RpcContexts.TryRemove(id, out va); - } - } - - private JsonRpcException ProcessException(JsonRequest req,JsonRpcException ex) - { - if(externalErrorHandler!=null) - return externalErrorHandler(req,ex); - return ex; - } - internal JsonRpcException ProcessParseException(string req,JsonRpcException ex) - { - if (parseErrorHandler != null) - return parseErrorHandler(req, ex); - return ex; - } - internal void SetErrorHandler(Func handler) - { - externalErrorHandler = handler; - } - internal void SetParseErrorHandler(Func handler) - { - parseErrorHandler = handler; - } - - #endregion - private object CleanUpParameter(object p, SMDAdditionalParameters metaData) - { - var bob = p as JValue; - //if (bob != null && (bob.Value == null || bob.Value.GetType() == metaData.ObjectType)) - if (bob != null && (bob.Value == null || metaData.ObjectType.IsAssignableFrom(bob.Value.GetType()))) - { - return bob.Value; - } - - var paramI = p; - try - { - return Newtonsoft.Json.JsonConvert.DeserializeObject(paramI.ToString(), metaData.ObjectType); - } - catch (Exception ex) - { - // no need to throw here, they will - // get an invalid cast exception right after this. - } - - return paramI; - } - - private JsonRpcException PreProcess(JsonRequest request, object context) - { - if (externalPreProcessingHandler == null) - return null; - return externalPreProcessingHandler(request, context); - } - - internal void SetPreProcessHandler(AustinHarris.JsonRpc.PreProcessHandler handler) - { - externalPreProcessingHandler = handler; - } - } - -} + var last = parameters.LastOrDefault(); + JsonRpcException contextException; + if (Task.CurrentId.HasValue && RpcExceptions.TryRemove(Task.CurrentId.Value, out contextException)) + { + return new JsonResponse() { Error = ProcessException(Rpc, contextException), Id = Rpc.Id }; + } + if (expectsRefException && last != null && last is JsonRpcException) + { + return new JsonResponse() { Error = ProcessException(Rpc, last as JsonRpcException), Id = Rpc.Id }; + } + + return new JsonResponse() { Result = results }; + } + catch (Exception ex) + { + if (ex is TargetParameterCountException) + { + return new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32602, "Invalid params", ex)) }; + } + + // We really dont care about the TargetInvocationException, just pass on the inner exception + if (ex is JsonRpcException) + { + return new JsonResponse() { Error = ProcessException(Rpc, ex as JsonRpcException) }; + } + if (ex.InnerException != null && ex.InnerException is JsonRpcException) + { + return new JsonResponse() { Error = ProcessException(Rpc, ex.InnerException as JsonRpcException) }; + } + else if (ex.InnerException != null) + { + return new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32603, "Internal Error", ex.InnerException)) }; + } + + return new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32603, "Internal Error", ex)) }; + } + finally + { + RemoveRpcContext(); + } + } + + private void AddRpcContext(object RpcContext) + { + if (Task.CurrentId != null) + RpcContexts[Task.CurrentId.Value] = RpcContext; + } + private void RemoveRpcContext() + { + if (Task.CurrentId != null) + { + var id = Task.CurrentId.Value; + RpcContexts[id] = null; + object va; + RpcContexts.TryRemove(id, out va); + } + } + + private JsonRpcException ProcessException(JsonRequest req,JsonRpcException ex) + { + if(externalErrorHandler!=null) + return externalErrorHandler(req,ex); + return ex; + } + internal JsonRpcException ProcessParseException(string req,JsonRpcException ex) + { + if (parseErrorHandler != null) + return parseErrorHandler(req, ex); + return ex; + } + internal void SetErrorHandler(Func handler) + { + externalErrorHandler = handler; + } + internal void SetParseErrorHandler(Func handler) + { + parseErrorHandler = handler; + } + + #endregion + private object CleanUpParameter(object p, SMDAdditionalParameters metaData) + { + var bob = p as JValue; + //if (bob != null && (bob.Value == null || bob.Value.GetType() == metaData.ObjectType)) + if (bob != null && (bob.Value == null)) + { + return bob.Value; + } + if (bob != null) + { + + // Avoid calling DeserializeObject on types that JValue has an explicit converter for + // try to optimize for the most common types + if (metaData.ObjectType == typeof(string)) return (string)bob; + if (metaData.ObjectType == typeof(int)) return (int)bob; + if (metaData.ObjectType == typeof(double)) return (double)bob; + if (metaData.ObjectType == typeof(float)) return (float)bob; + //if (metaData.ObjectType == typeof(long)) return (long)bob; + //if (metaData.ObjectType == typeof(uint)) return (uint)bob; + //if (metaData.ObjectType == typeof(ulong)) return (ulong)bob; + //if (metaData.ObjectType == typeof(byte[])) return (byte[])bob; + //if (metaData.ObjectType == typeof(Guid)) return (Guid)bob; + if (metaData.ObjectType == typeof(decimal)) return (decimal)bob; + //if (metaData.ObjectType == typeof(TimeSpan)) return (TimeSpan)bob; + //if (metaData.ObjectType == typeof(short)) return (short)bob; + //if (metaData.ObjectType == typeof(ushort)) return (ushort)bob; + //if (metaData.ObjectType == typeof(char)) return (char)bob; + //if (metaData.ObjectType == typeof(DateTime)) return (DateTime)bob; + //if (metaData.ObjectType == typeof(bool)) return (bool)bob; + //if (metaData.ObjectType == typeof(DateTimeOffset)) return (DateTimeOffset)bob; + + if (metaData.ObjectType.IsAssignableFrom(typeof(JValue))) + return bob; + + try + { + return bob.ToObject(metaData.ObjectType); + } + catch (Exception ex) + { + // no need to throw here, they will + // get an invalid cast exception right after this. + } + } + else + { + try + { + if(p is string) + return JsonConvert.DeserializeObject((string) p, metaData.ObjectType); + return JsonConvert.DeserializeObject(p.ToString(), metaData.ObjectType); + } + catch (Exception ex) + { + // no need to throw here, they will + // get an invalid cast exception right after this. + } + } + + return p; + } + + private JsonRpcException PreProcess(JsonRequest request, object context) + { + if (externalPreProcessingHandler == null) + return null; + return externalPreProcessingHandler(request, context); + } + + internal void SetPreProcessHandler(AustinHarris.JsonRpc.PreProcessHandler handler) + { + externalPreProcessingHandler = handler; + } + } + +} + From 31ecb438cce2524637d743e248e0fc642bddaedb Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Fri, 30 Jan 2015 17:35:20 -0700 Subject: [PATCH 13/81] Add a larger varity of tests to the testServer --- TestServer_Console/Program.cs | 18 +++++++++++++++++- TestServer_Console/service.cs | 12 ++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/TestServer_Console/Program.cs b/TestServer_Console/Program.cs index 8460d12..34f76ae 100644 --- a/TestServer_Console/Program.cs +++ b/TestServer_Console/Program.cs @@ -72,11 +72,27 @@ private static void Benchmark() } }); - for (int i = 0; i < cnt; i++) + for (int i = 0; i < cnt; i+=5) { var async = new JsonRpcStateAsync(rpcResultHandler, null); async.JsonRpc = "{'method':'add','params':[1,2],'id':1}"; JsonRpcProcessor.Process(async); + + async = new JsonRpcStateAsync(rpcResultHandler, null); + async.JsonRpc = "{'method':'addInt','params':[1,7],'id':2}"; + JsonRpcProcessor.Process(async); + + async = new JsonRpcStateAsync(rpcResultHandler, null); + async.JsonRpc = "{'method':'NullableFloatToNullableFloat','params':[1.23],'id':3}"; + JsonRpcProcessor.Process(async); + + async = new JsonRpcStateAsync(rpcResultHandler, null); + async.JsonRpc = "{'method':'Test2','params':[3.456],'id':4}"; + JsonRpcProcessor.Process(async); + + async = new JsonRpcStateAsync(rpcResultHandler, null); + async.JsonRpc = "{'method':'StringMe','params':['Foo'],'id':5}"; + JsonRpcProcessor.Process(async); } are.WaitOne(); } diff --git a/TestServer_Console/service.cs b/TestServer_Console/service.cs index c0a09aa..5802453 100644 --- a/TestServer_Console/service.cs +++ b/TestServer_Console/service.cs @@ -14,6 +14,12 @@ private double add(double l, double r) return l + r; } + [JsonRpcMethod] + private int addInt(int l, int r) + { + return l + r; + } + [JsonRpcMethod] public float? NullableFloatToNullableFloat(float? a) { @@ -25,5 +31,11 @@ private double add(double l, double r) { return x; } + + [JsonRpcMethod] + public string StringMe(string x) + { + return x; + } } } From b718183622322626a4d1932fe45ecbc878d095e2 Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Fri, 30 Jan 2015 17:59:23 -0700 Subject: [PATCH 14/81] Updated nuspec for new build --- Json-Rpc/AustinHarris.JsonRpc.nuspec | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Json-Rpc/AustinHarris.JsonRpc.nuspec b/Json-Rpc/AustinHarris.JsonRpc.nuspec index 296958d..5a3c555 100644 --- a/Json-Rpc/AustinHarris.JsonRpc.nuspec +++ b/Json-Rpc/AustinHarris.JsonRpc.nuspec @@ -3,21 +3,21 @@ AustinHarris.JsonRpc $version$ - JSON-RPC.NET Core + JSON-RPC.NET Austin Harris - http://jsonrpc2.codeplex.com/license - http://jsonrpc2.codeplex.com/ + https://raw.githubusercontent.com/Astn/JSON-RPC.NET/master/LICENSE + https://github.com/Astn/JSON-RPC.NET http://download-codeplex.sec.s-msft.com/Download?ProjectName=jsonrpc2&DownloadId=487107 false - Core functionality for JsonRpc.Net - JSON-RPC.Net is a high performance Json-Rpc 2.0 server, leveraging the popular JSON.NET library. Host in ASP.NET, also supports sockets and pipes, oh my! - Added support for optional params. Improved task usage / performance. Better float handling for non en-US cultures. Can now override ParseErrors. Can now unregister handlers. Using lower-cased property names during serialization. Many thanks to raistlinthewiz. + The fastest .Net JSON RPC Server + JSON-RPC.Net is a high performance Json-Rpc 2.0 server, leveraging the popular JSON.NET library. Easily create a JSON RPC server for your Angular javascript apps, also supports sockets and pipes, oh my! + Performance improvements -Astn, Bug Fixes: Optional Parameter Ordering -artnim, Batches with superflous commans -artnim, ParamCount Exception -artnim. en-US - Json Rpc Json-Rpc.Net Json-Rpc JsonRpc Json.net + fast json rpc server socket javascript json-rpc.net json-rpc jsonrpc json.net web services webapi service angular server angularjs - + From d3974368899651d846636a94a6cc387155ab86e5 Mon Sep 17 00:00:00 2001 From: Martin Daetz Date: Mon, 2 Feb 2015 09:14:38 +0100 Subject: [PATCH 15/81] Saving files before refreshing line endings --- .gitattributes | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..bdb0cab --- /dev/null +++ b/.gitattributes @@ -0,0 +1,17 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain From 6913ee435c252d91ebb2dc2c6e4362b78b488e90 Mon Sep 17 00:00:00 2001 From: Martin Daetz Date: Mon, 2 Feb 2015 09:17:54 +0100 Subject: [PATCH 16/81] Normalize all line endings --- AustinHarris.JsonRpc.sln | 166 +-- .../AustinHarris.JsonRpcTest.csproj | 196 ++-- AustinHarris.JsonRpcTest/UnitTest1.cs | 60 +- AustinHarris.JsonRpcTest/service.cs | 24 +- Json-Rpc/AustinHarris.JsonRpc.csproj | 182 ++-- Json-Rpc/Handler.cs | 954 +++++++++--------- Json-Rpc/JsonRpcProcessor.cs | 290 +++--- TestServer_Console/TestServer_Console.csproj | 152 +-- 8 files changed, 1012 insertions(+), 1012 deletions(-) diff --git a/AustinHarris.JsonRpc.sln b/AustinHarris.JsonRpc.sln index 73ccd23..4b0e5fc 100644 --- a/AustinHarris.JsonRpc.sln +++ b/AustinHarris.JsonRpc.sln @@ -1,83 +1,83 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.30723.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BBFBBA8A-2F75-422C-ACCD-D05A6EF7244C}" - ProjectSection(SolutionItems) = preProject - AustinHarris.JsonRpc.vsmdi = AustinHarris.JsonRpc.vsmdi - Local.testsettings = Local.testsettings - TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AustinHarris.JsonRpc", "Json-Rpc\AustinHarris.JsonRpc.csproj", "{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AustinHarris.JsonRpc.AspNet", "AustinHarris.JsonRpc.AspNet\AustinHarris.JsonRpc.AspNet.csproj", "{FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AustinHarris.JsonRpcTest", "AustinHarris.JsonRpcTest\AustinHarris.JsonRpcTest.csproj", "{0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{4811B06E-0A04-4CD4-9018-FE8295E8BF08}" - ProjectSection(SolutionItems) = preProject - .nuget\NuGet.Config = .nuget\NuGet.Config - .nuget\NuGet.exe = .nuget\NuGet.exe - .nuget\NuGet.targets = .nuget\NuGet.targets - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|ARM = Debug|ARM - Debug|Mixed Platforms = Debug|Mixed Platforms - Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|ARM = Release|ARM - Release|Mixed Platforms = Release|Mixed Platforms - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|Any CPU.Build.0 = Debug|Any CPU - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|ARM.ActiveCfg = Debug|x86 - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|x86.ActiveCfg = Debug|x86 - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|x86.Build.0 = Debug|x86 - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|Any CPU.ActiveCfg = Release|Any CPU - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|Any CPU.Build.0 = Release|Any CPU - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|ARM.ActiveCfg = Release|x86 - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|Mixed Platforms.Build.0 = Release|x86 - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|x86.ActiveCfg = Release|x86 - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|x86.Build.0 = Release|x86 - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|ARM.ActiveCfg = Debug|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|x86.ActiveCfg = Debug|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Any CPU.Build.0 = Release|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|ARM.ActiveCfg = Release|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|x86.ActiveCfg = Release|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|ARM.ActiveCfg = Debug|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|x86.ActiveCfg = Debug|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|Any CPU.Build.0 = Release|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|ARM.ActiveCfg = Release|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|x86.ActiveCfg = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(TestCaseManagementSettings) = postSolution - CategoryFile = AustinHarris.JsonRpc.vsmdi - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.30723.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BBFBBA8A-2F75-422C-ACCD-D05A6EF7244C}" + ProjectSection(SolutionItems) = preProject + AustinHarris.JsonRpc.vsmdi = AustinHarris.JsonRpc.vsmdi + Local.testsettings = Local.testsettings + TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AustinHarris.JsonRpc", "Json-Rpc\AustinHarris.JsonRpc.csproj", "{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AustinHarris.JsonRpc.AspNet", "AustinHarris.JsonRpc.AspNet\AustinHarris.JsonRpc.AspNet.csproj", "{FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AustinHarris.JsonRpcTest", "AustinHarris.JsonRpcTest\AustinHarris.JsonRpcTest.csproj", "{0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{4811B06E-0A04-4CD4-9018-FE8295E8BF08}" + ProjectSection(SolutionItems) = preProject + .nuget\NuGet.Config = .nuget\NuGet.Config + .nuget\NuGet.exe = .nuget\NuGet.exe + .nuget\NuGet.targets = .nuget\NuGet.targets + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|ARM = Debug|ARM + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|ARM = Release|ARM + Release|Mixed Platforms = Release|Mixed Platforms + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|Any CPU.Build.0 = Debug|Any CPU + {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|ARM.ActiveCfg = Debug|x86 + {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|x86.ActiveCfg = Debug|x86 + {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|x86.Build.0 = Debug|x86 + {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|Any CPU.ActiveCfg = Release|Any CPU + {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|Any CPU.Build.0 = Release|Any CPU + {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|ARM.ActiveCfg = Release|x86 + {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|Mixed Platforms.Build.0 = Release|x86 + {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|x86.ActiveCfg = Release|x86 + {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|x86.Build.0 = Release|x86 + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|ARM.ActiveCfg = Debug|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|x86.ActiveCfg = Debug|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Any CPU.Build.0 = Release|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|ARM.ActiveCfg = Release|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|x86.ActiveCfg = Release|Any CPU + {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|ARM.ActiveCfg = Debug|Any CPU + {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|x86.ActiveCfg = Debug|Any CPU + {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|Any CPU.Build.0 = Release|Any CPU + {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|ARM.ActiveCfg = Release|Any CPU + {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|x86.ActiveCfg = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(TestCaseManagementSettings) = postSolution + CategoryFile = AustinHarris.JsonRpc.vsmdi + EndGlobalSection +EndGlobal diff --git a/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj b/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj index 52d431d..d502129 100644 --- a/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj +++ b/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj @@ -1,105 +1,105 @@ - - - - Debug - AnyCPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD} - Library - Properties - AustinHarris.JsonRpcTest - AustinHarris.JsonRpcTest - v4.0 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - ..\ - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - - - 3.5 - - - - - - - - - - - - - - - - - - - - - - {24fc1a2a-0bc3-43a7-9bfe-b628c2c4a307} - AustinHarris.JsonRpc - - - - - - - False - - - False - - - False - - - False - - - - - - - - - - Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Aktivieren Sie die Wiederherstellung von NuGet-Paketen, um die fehlende Datei herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". - - - + + + + Debug + AnyCPU + {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD} + Library + Properties + AustinHarris.JsonRpcTest + AustinHarris.JsonRpcTest + v4.0 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + ..\ + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + + + 3.5 + + + + + + + + + + + + + + + + + + + + + + {24fc1a2a-0bc3-43a7-9bfe-b628c2c4a307} + AustinHarris.JsonRpc + + + + + + + False + + + False + + + False + + + False + + + + + + + + + + Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Aktivieren Sie die Wiederherstellung von NuGet-Paketen, um die fehlende Datei herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". + + + + --> \ No newline at end of file diff --git a/AustinHarris.JsonRpcTest/UnitTest1.cs b/AustinHarris.JsonRpcTest/UnitTest1.cs index a1f75ab..ece70bf 100644 --- a/AustinHarris.JsonRpcTest/UnitTest1.cs +++ b/AustinHarris.JsonRpcTest/UnitTest1.cs @@ -1,7 +1,7 @@ -using System; -using AustinHarris.JsonRpc; -using Microsoft.VisualStudio.TestTools.UnitTesting; - +using System; +using AustinHarris.JsonRpc; +using Microsoft.VisualStudio.TestTools.UnitTesting; + namespace UnitTests { [TestClass] @@ -1319,31 +1319,31 @@ public void TestOptionalParametersStrings_BothExists() result.Wait(); Assert.IsFalse(result.Result.Contains("error")); Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestOptionalParametersBoolsAndStrings() - { - string request = - "{\"jsonrpc\":\"2.0\",\"method\":\"TestOptionalParametersBoolsAndStrings\",\"params\":{\"input1\":\"murkel\"},\"Id\":1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestBatchResult() - { - string request = - @"[{},{""jsonrpc"":""2.0"",""id"":4},{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}]"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - - Assert.IsFalse(result.Result.EndsWith(@",]"), "result.Result.EndsWith(@',]')"); - } + } + + [TestMethod] + public void TestOptionalParametersBoolsAndStrings() + { + string request = + "{\"jsonrpc\":\"2.0\",\"method\":\"TestOptionalParametersBoolsAndStrings\",\"params\":{\"input1\":\"murkel\"},\"Id\":1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [TestMethod] + public void TestBatchResult() + { + string request = + @"[{},{""jsonrpc"":""2.0"",""id"":4},{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}]"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + + Assert.IsFalse(result.Result.EndsWith(@",]"), "result.Result.EndsWith(@',]')"); + } } } diff --git a/AustinHarris.JsonRpcTest/service.cs b/AustinHarris.JsonRpcTest/service.cs index 2b36387..fb81e70 100644 --- a/AustinHarris.JsonRpcTest/service.cs +++ b/AustinHarris.JsonRpcTest/service.cs @@ -1,7 +1,7 @@ using AustinHarris.JsonRpc; using System; -using System.Collections.Generic; -using System.Diagnostics; +using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; @@ -292,17 +292,17 @@ private IList TestOptionalParameters_Strings(string input1 = null, strin input1, input2 }; - } - [JsonRpcMethod] - public bool TestOptionalParametersBoolsAndStrings(string input1, bool input2 = true, string input3 = "") - { - return input2; - } + } + [JsonRpcMethod] + public bool TestOptionalParametersBoolsAndStrings(string input1, bool input2 = true, string input3 = "") + { + return input2; + } - [JsonRpcMethod] - public void Notify(string message) - { - Trace.WriteLine(string.Format("Notified about: {0}", message)); + [JsonRpcMethod] + public void Notify(string message) + { + Trace.WriteLine(string.Format("Notified about: {0}", message)); } } } diff --git a/Json-Rpc/AustinHarris.JsonRpc.csproj b/Json-Rpc/AustinHarris.JsonRpc.csproj index e4531ac..cb0be46 100644 --- a/Json-Rpc/AustinHarris.JsonRpc.csproj +++ b/Json-Rpc/AustinHarris.JsonRpc.csproj @@ -1,98 +1,98 @@ - - - - Debug - x86 - 8.0.30703 - 2.0 - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307} - Library - Properties - AustinHarris.JsonRpc - AustinHarris.JsonRpc - v4.0 - - - 512 - SAK - SAK - SAK - SAK - ..\..\CoiniumServ\build\ - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - - - - AnyCPU - bin\Debug\ - TRACE;DEBUG - - - AnyCPU - bin\Release\ - - - - - - - - - - - - - - - - - - - - ..\packages\Newtonsoft.Json.6.0.5\lib\net40\Newtonsoft.Json.dll - True - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - + + + + Debug + x86 + 8.0.30703 + 2.0 + {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307} + Library + Properties + AustinHarris.JsonRpc + AustinHarris.JsonRpc + v4.0 + + + 512 + SAK + SAK + SAK + SAK + ..\..\CoiniumServ\build\ + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + + + + AnyCPU + bin\Debug\ + TRACE;DEBUG + + + AnyCPU + bin\Release\ + + + + + + + + + + + + + + + + + + + + ..\packages\Newtonsoft.Json.6.0.5\lib\net40\Newtonsoft.Json.dll + True + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + --> \ No newline at end of file diff --git a/Json-Rpc/Handler.cs b/Json-Rpc/Handler.cs index 4fa7845..af69a13 100644 --- a/Json-Rpc/Handler.cs +++ b/Json-Rpc/Handler.cs @@ -1,477 +1,477 @@ -namespace AustinHarris.JsonRpc -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Linq; - using System.Reflection; - using Newtonsoft.Json; - using System.Threading.Tasks; - using System.Collections.Concurrent; -using Newtonsoft.Json.Linq; - - public class Handler - { - #region Members - - //private static Handler current; - private static ConcurrentDictionary _sessionHandlers; - private static string _defaultSessionId; - #endregion - - #region Constructors - - static Handler() - { - //current = new Handler(Guid.NewGuid().ToString()); - _defaultSessionId = Guid.NewGuid().ToString(); - _sessionHandlers = new ConcurrentDictionary(); - _sessionHandlers[_defaultSessionId]= new Handler(_defaultSessionId); - } - - private Handler(string sessionId) - { - SessionId = sessionId; - this.MetaData = new SMD(); - this.Handlers = new Dictionary(); - } - - #endregion - - #region Properties - - /// - /// Returns the SessionID of the default session - /// - /// - public static string DefaultSessionId() { return _defaultSessionId; } - - /// - /// Gets a specific session - /// - /// The sessionId of the handler you want to retrieve. - /// - public static Handler GetSessionHandler(string sessionId) - { - return _sessionHandlers.GetOrAdd(sessionId, new Handler(sessionId)); - } - - /// - /// gets the default session - /// - /// The default Session Handler - public static Handler GetSessionHandler() - { - return GetSessionHandler(_defaultSessionId); - } - - /// - /// Removes and clears the Handler with the specific sessionID from the registry of Handlers - /// - /// - public static void DestroySession(string sessionId) - { - Handler h; - _sessionHandlers.TryRemove(sessionId,out h); - h.Handlers.Clear(); - h.MetaData.Services.Clear(); - } - /// - /// Removes and clears the current Handler from the registry of Handlers - /// - public void Destroy() - { - DestroySession(SessionId); - } - - /// - /// Gets the default session handler - /// - public static Handler DefaultHandler { get { return GetSessionHandler(_defaultSessionId); } } - - /// - /// The sessionID of this Handler - /// - public string SessionId { get; private set; } - - private static ConcurrentDictionary RpcContexts = new ConcurrentDictionary(); - private static ConcurrentDictionary RpcExceptions = new ConcurrentDictionary(); - - /// - /// Provides access to a context specific to each JsonRpc method invocation. - /// Warning: Must be called from within the execution context of the jsonRpc Method to return the context - /// - /// - public static object RpcContext() - { - if (Task.CurrentId == null) - return null; - - if (RpcContexts.ContainsKey(Task.CurrentId.Value) == false) - return null; - - return RpcContexts[Task.CurrentId.Value]; - } - - /// - /// Allows you to set the exception used in in the JsonRpc response. - /// Warning: Must be called from within the execution context of the jsonRpc method. - /// - /// - public static void RpcSetException(JsonRpcException exception) - { - if (Task.CurrentId != null) - RpcExceptions[Task.CurrentId.Value] = exception; - else - throw new InvalidOperationException("This method is only valid when used within the context of a method marked as a JsonRpcMethod, and that method must of been invoked by the JsonRpc Handler."); - } - - private void RemoveRpcException() - { - if (Task.CurrentId != null) - { - var id = Task.CurrentId.Value; - RpcExceptions[id] = null; - JsonRpcException va; - RpcExceptions.TryRemove(id, out va); - } - } - - private AustinHarris.JsonRpc.PreProcessHandler externalPreProcessingHandler; - private Func externalErrorHandler; - private Func parseErrorHandler; - private Dictionary Handlers { get; set; } - #endregion - - /// - /// This metadata contains all the types and mappings of all the methods in this handler. Warning: Modifying this directly could cause your handler to no longer function. - /// - public SMD MetaData { get; set; } - - #region Public Methods - - /// - /// Registers a jsonRpc method name (key) to be mapped to a specific function - /// - /// The Method as it will be called from JsonRpc - /// The method that will be invoked - /// - public bool Register(string key, Delegate handle) - { - var result = false; - - if (!this.Handlers.ContainsKey(key)) - { - this.Handlers.Add(key, handle); - } - - return result; - } - - public void UnRegister(string key) - { - this.Handlers.Remove(key); - MetaData.Services.Remove(key); - } - - /// - /// Invokes a method to handle a JsonRpc request. - /// - /// JsonRpc Request to be processed - /// Optional context that will be available from within the jsonRpcMethod. - /// - public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null) - { - AddRpcContext(RpcContext); - - var preProcessingException = PreProcess(Rpc, RpcContext); - if (preProcessingException != null) - { - return new JsonResponse() { Error = preProcessingException, - Id = Rpc.Id }; - } - - SMDService metadata = null; - Delegate handle = null; - var haveDelegate = this.Handlers.TryGetValue(Rpc.Method, out handle); - var haveMetadata = this.MetaData.Services.TryGetValue(Rpc.Method, out metadata); - - if (haveDelegate == false || haveMetadata == false || metadata == null || handle == null) - { - return new JsonResponse() { Result = null, Error = new JsonRpcException(-32601, "Method not found", "The method does not exist / is not available."), Id = Rpc.Id }; - } - if (Rpc.Params is ICollection == false) - { - return new JsonResponse() - { - Result = null, - Error = new JsonRpcException(-32602, - "Invalid params", "The number of parameters could not be counted"), - Id = Rpc.Id - }; - } - - bool isJObject = Rpc.Params is Newtonsoft.Json.Linq.JObject; - bool isJArray = Rpc.Params is Newtonsoft.Json.Linq.JArray; - object[] parameters = null; - bool expectsRefException = false; - var metaDataParamCount = metadata.parameters.Count(x => x != null); - - var getCount = Rpc.Params as ICollection; - var loopCt = getCount.Count; - var paramCount = loopCt; - if (paramCount == metaDataParamCount - 1 && metadata.parameters[metaDataParamCount-1].ObjectType.Name.Contains(typeof(JsonRpcException).Name)) - { - paramCount++; - expectsRefException = true; - } - parameters = new object[paramCount]; - - if (isJArray) - { - var jarr = ((Newtonsoft.Json.Linq.JArray)Rpc.Params); - //var loopCt = jarr.Count; - //var pCount = loopCt; - //if (pCount == metaDataParamCount - 1 && metadata.parameters[metaDataParamCount].GetType() == typeof(JsonRpcException)) - // pCount++; - //parameters = new object[pCount]; - for (int i = 0; i < loopCt; i++) - { - parameters[i] = CleanUpParameter(jarr[i], metadata.parameters[i]); - } - } - else if (isJObject) - { - var jo = Rpc.Params as Newtonsoft.Json.Linq.JObject; - //var loopCt = jo.Count; - //var pCount = loopCt; - //if (pCount == metaDataParamCount - 1 && metadata.parameters[metaDataParamCount].GetType() == typeof(JsonRpcException)) - // pCount++; - //parameters = new object[pCount]; - var asDict = jo as IDictionary; - for (int i = 0; i < loopCt; i++) - { - if (asDict.ContainsKey(metadata.parameters[i].Name) == false) - { - return new JsonResponse() - { - Error = ProcessException(Rpc, - new JsonRpcException(-32602, - "Invalid params", - string.Format("Named parameter '{0}' was not present.", - metadata.parameters[i].Name) - )) - ,Id = Rpc.Id - }; - } - parameters[i] = CleanUpParameter(jo[metadata.parameters[i].Name], metadata.parameters[i]); - } - } - - // Optional Parameter support - // check if we still miss parameters compared to metadata which may include optional parameters. - // if the rpc-call didn't supply a value for an optional parameter, we should be assinging the default value of it. - if (parameters.Length < metaDataParamCount && metadata.defaultValues.Length > 0) // rpc call didn't set values for all optional parameters, so we need to assign the default values for them. - { - var suppliedParamsCount = parameters.Length; // the index we should start storing default values of optional parameters. - var missingParamsCount = metaDataParamCount - parameters.Length; // the amount of optional parameters without a value set by rpc-call. - Array.Resize(ref parameters, parameters.Length + missingParamsCount); // resize the array to include all optional parameters. - - for (int paramIndex = parameters.Length - 1, defaultIndex = metadata.defaultValues.Length - 1; // fill missing parameters from the back - paramIndex >= suppliedParamsCount && defaultIndex >= 0; // to don't overwrite supplied ones. - paramIndex--, defaultIndex--) - { - parameters[paramIndex] = metadata.defaultValues[defaultIndex].Value; - } - - if (missingParamsCount > metadata.defaultValues.Length) - { - return new JsonResponse - { - Error = ProcessException(Rpc, - new JsonRpcException(-32602, - "Invalid params", - string.Format( - "Number of default parameters {0} not sufficient to fill all missing parameters {1}", - metadata.defaultValues.Length, missingParamsCount) - )), - Id = Rpc.Id - }; - } - } - - if (parameters.Length != metaDataParamCount) - { - return new JsonResponse() - { - Error = ProcessException(Rpc, - new JsonRpcException(-32602, - "Invalid params", - string.Format("Expecting {0} parameters, and received {1}", - metadata.parameters.Length, - parameters.Length) - )), - Id = Rpc.Id - }; - } - - try - { - var results = handle.DynamicInvoke(parameters); - var last = parameters.LastOrDefault(); - JsonRpcException contextException; - if (Task.CurrentId.HasValue && RpcExceptions.TryRemove(Task.CurrentId.Value, out contextException)) - { - return new JsonResponse() { Error = ProcessException(Rpc, contextException), Id = Rpc.Id }; - } - if (expectsRefException && last != null && last is JsonRpcException) - { - return new JsonResponse() { Error = ProcessException(Rpc, last as JsonRpcException), Id = Rpc.Id }; - } - - return new JsonResponse() { Result = results }; - } - catch (Exception ex) - { - if (ex is TargetParameterCountException) - { - return new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32602, "Invalid params", ex)) }; - } - - // We really dont care about the TargetInvocationException, just pass on the inner exception - if (ex is JsonRpcException) - { - return new JsonResponse() { Error = ProcessException(Rpc, ex as JsonRpcException) }; - } - if (ex.InnerException != null && ex.InnerException is JsonRpcException) - { - return new JsonResponse() { Error = ProcessException(Rpc, ex.InnerException as JsonRpcException) }; - } - else if (ex.InnerException != null) - { - return new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32603, "Internal Error", ex.InnerException)) }; - } - - return new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32603, "Internal Error", ex)) }; - } - finally - { - RemoveRpcContext(); - } - } - - private void AddRpcContext(object RpcContext) - { - if (Task.CurrentId != null) - RpcContexts[Task.CurrentId.Value] = RpcContext; - } - private void RemoveRpcContext() - { - if (Task.CurrentId != null) - { - var id = Task.CurrentId.Value; - RpcContexts[id] = null; - object va; - RpcContexts.TryRemove(id, out va); - } - } - - private JsonRpcException ProcessException(JsonRequest req,JsonRpcException ex) - { - if(externalErrorHandler!=null) - return externalErrorHandler(req,ex); - return ex; - } - internal JsonRpcException ProcessParseException(string req,JsonRpcException ex) - { - if (parseErrorHandler != null) - return parseErrorHandler(req, ex); - return ex; - } - internal void SetErrorHandler(Func handler) - { - externalErrorHandler = handler; - } - internal void SetParseErrorHandler(Func handler) - { - parseErrorHandler = handler; - } - - #endregion - private object CleanUpParameter(object p, SMDAdditionalParameters metaData) - { - var bob = p as JValue; - //if (bob != null && (bob.Value == null || bob.Value.GetType() == metaData.ObjectType)) - if (bob != null && (bob.Value == null)) - { - return bob.Value; - } - if (bob != null) - { - - // Avoid calling DeserializeObject on types that JValue has an explicit converter for - // try to optimize for the most common types - if (metaData.ObjectType == typeof(string)) return (string)bob; - if (metaData.ObjectType == typeof(int)) return (int)bob; - if (metaData.ObjectType == typeof(double)) return (double)bob; - if (metaData.ObjectType == typeof(float)) return (float)bob; - //if (metaData.ObjectType == typeof(long)) return (long)bob; - //if (metaData.ObjectType == typeof(uint)) return (uint)bob; - //if (metaData.ObjectType == typeof(ulong)) return (ulong)bob; - //if (metaData.ObjectType == typeof(byte[])) return (byte[])bob; - //if (metaData.ObjectType == typeof(Guid)) return (Guid)bob; - if (metaData.ObjectType == typeof(decimal)) return (decimal)bob; - //if (metaData.ObjectType == typeof(TimeSpan)) return (TimeSpan)bob; - //if (metaData.ObjectType == typeof(short)) return (short)bob; - //if (metaData.ObjectType == typeof(ushort)) return (ushort)bob; - //if (metaData.ObjectType == typeof(char)) return (char)bob; - //if (metaData.ObjectType == typeof(DateTime)) return (DateTime)bob; - //if (metaData.ObjectType == typeof(bool)) return (bool)bob; - //if (metaData.ObjectType == typeof(DateTimeOffset)) return (DateTimeOffset)bob; - - if (metaData.ObjectType.IsAssignableFrom(typeof(JValue))) - return bob; - - try - { - return bob.ToObject(metaData.ObjectType); - } - catch (Exception ex) - { - // no need to throw here, they will - // get an invalid cast exception right after this. - } - } - else - { - try - { - if(p is string) - return JsonConvert.DeserializeObject((string) p, metaData.ObjectType); - return JsonConvert.DeserializeObject(p.ToString(), metaData.ObjectType); - } - catch (Exception ex) - { - // no need to throw here, they will - // get an invalid cast exception right after this. - } - } - - return p; - } - - private JsonRpcException PreProcess(JsonRequest request, object context) - { - if (externalPreProcessingHandler == null) - return null; - return externalPreProcessingHandler(request, context); - } - - internal void SetPreProcessHandler(AustinHarris.JsonRpc.PreProcessHandler handler) - { - externalPreProcessingHandler = handler; - } - } - -} - +namespace AustinHarris.JsonRpc +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Linq; + using System.Reflection; + using Newtonsoft.Json; + using System.Threading.Tasks; + using System.Collections.Concurrent; +using Newtonsoft.Json.Linq; + + public class Handler + { + #region Members + + //private static Handler current; + private static ConcurrentDictionary _sessionHandlers; + private static string _defaultSessionId; + #endregion + + #region Constructors + + static Handler() + { + //current = new Handler(Guid.NewGuid().ToString()); + _defaultSessionId = Guid.NewGuid().ToString(); + _sessionHandlers = new ConcurrentDictionary(); + _sessionHandlers[_defaultSessionId]= new Handler(_defaultSessionId); + } + + private Handler(string sessionId) + { + SessionId = sessionId; + this.MetaData = new SMD(); + this.Handlers = new Dictionary(); + } + + #endregion + + #region Properties + + /// + /// Returns the SessionID of the default session + /// + /// + public static string DefaultSessionId() { return _defaultSessionId; } + + /// + /// Gets a specific session + /// + /// The sessionId of the handler you want to retrieve. + /// + public static Handler GetSessionHandler(string sessionId) + { + return _sessionHandlers.GetOrAdd(sessionId, new Handler(sessionId)); + } + + /// + /// gets the default session + /// + /// The default Session Handler + public static Handler GetSessionHandler() + { + return GetSessionHandler(_defaultSessionId); + } + + /// + /// Removes and clears the Handler with the specific sessionID from the registry of Handlers + /// + /// + public static void DestroySession(string sessionId) + { + Handler h; + _sessionHandlers.TryRemove(sessionId,out h); + h.Handlers.Clear(); + h.MetaData.Services.Clear(); + } + /// + /// Removes and clears the current Handler from the registry of Handlers + /// + public void Destroy() + { + DestroySession(SessionId); + } + + /// + /// Gets the default session handler + /// + public static Handler DefaultHandler { get { return GetSessionHandler(_defaultSessionId); } } + + /// + /// The sessionID of this Handler + /// + public string SessionId { get; private set; } + + private static ConcurrentDictionary RpcContexts = new ConcurrentDictionary(); + private static ConcurrentDictionary RpcExceptions = new ConcurrentDictionary(); + + /// + /// Provides access to a context specific to each JsonRpc method invocation. + /// Warning: Must be called from within the execution context of the jsonRpc Method to return the context + /// + /// + public static object RpcContext() + { + if (Task.CurrentId == null) + return null; + + if (RpcContexts.ContainsKey(Task.CurrentId.Value) == false) + return null; + + return RpcContexts[Task.CurrentId.Value]; + } + + /// + /// Allows you to set the exception used in in the JsonRpc response. + /// Warning: Must be called from within the execution context of the jsonRpc method. + /// + /// + public static void RpcSetException(JsonRpcException exception) + { + if (Task.CurrentId != null) + RpcExceptions[Task.CurrentId.Value] = exception; + else + throw new InvalidOperationException("This method is only valid when used within the context of a method marked as a JsonRpcMethod, and that method must of been invoked by the JsonRpc Handler."); + } + + private void RemoveRpcException() + { + if (Task.CurrentId != null) + { + var id = Task.CurrentId.Value; + RpcExceptions[id] = null; + JsonRpcException va; + RpcExceptions.TryRemove(id, out va); + } + } + + private AustinHarris.JsonRpc.PreProcessHandler externalPreProcessingHandler; + private Func externalErrorHandler; + private Func parseErrorHandler; + private Dictionary Handlers { get; set; } + #endregion + + /// + /// This metadata contains all the types and mappings of all the methods in this handler. Warning: Modifying this directly could cause your handler to no longer function. + /// + public SMD MetaData { get; set; } + + #region Public Methods + + /// + /// Registers a jsonRpc method name (key) to be mapped to a specific function + /// + /// The Method as it will be called from JsonRpc + /// The method that will be invoked + /// + public bool Register(string key, Delegate handle) + { + var result = false; + + if (!this.Handlers.ContainsKey(key)) + { + this.Handlers.Add(key, handle); + } + + return result; + } + + public void UnRegister(string key) + { + this.Handlers.Remove(key); + MetaData.Services.Remove(key); + } + + /// + /// Invokes a method to handle a JsonRpc request. + /// + /// JsonRpc Request to be processed + /// Optional context that will be available from within the jsonRpcMethod. + /// + public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null) + { + AddRpcContext(RpcContext); + + var preProcessingException = PreProcess(Rpc, RpcContext); + if (preProcessingException != null) + { + return new JsonResponse() { Error = preProcessingException, + Id = Rpc.Id }; + } + + SMDService metadata = null; + Delegate handle = null; + var haveDelegate = this.Handlers.TryGetValue(Rpc.Method, out handle); + var haveMetadata = this.MetaData.Services.TryGetValue(Rpc.Method, out metadata); + + if (haveDelegate == false || haveMetadata == false || metadata == null || handle == null) + { + return new JsonResponse() { Result = null, Error = new JsonRpcException(-32601, "Method not found", "The method does not exist / is not available."), Id = Rpc.Id }; + } + if (Rpc.Params is ICollection == false) + { + return new JsonResponse() + { + Result = null, + Error = new JsonRpcException(-32602, + "Invalid params", "The number of parameters could not be counted"), + Id = Rpc.Id + }; + } + + bool isJObject = Rpc.Params is Newtonsoft.Json.Linq.JObject; + bool isJArray = Rpc.Params is Newtonsoft.Json.Linq.JArray; + object[] parameters = null; + bool expectsRefException = false; + var metaDataParamCount = metadata.parameters.Count(x => x != null); + + var getCount = Rpc.Params as ICollection; + var loopCt = getCount.Count; + var paramCount = loopCt; + if (paramCount == metaDataParamCount - 1 && metadata.parameters[metaDataParamCount-1].ObjectType.Name.Contains(typeof(JsonRpcException).Name)) + { + paramCount++; + expectsRefException = true; + } + parameters = new object[paramCount]; + + if (isJArray) + { + var jarr = ((Newtonsoft.Json.Linq.JArray)Rpc.Params); + //var loopCt = jarr.Count; + //var pCount = loopCt; + //if (pCount == metaDataParamCount - 1 && metadata.parameters[metaDataParamCount].GetType() == typeof(JsonRpcException)) + // pCount++; + //parameters = new object[pCount]; + for (int i = 0; i < loopCt; i++) + { + parameters[i] = CleanUpParameter(jarr[i], metadata.parameters[i]); + } + } + else if (isJObject) + { + var jo = Rpc.Params as Newtonsoft.Json.Linq.JObject; + //var loopCt = jo.Count; + //var pCount = loopCt; + //if (pCount == metaDataParamCount - 1 && metadata.parameters[metaDataParamCount].GetType() == typeof(JsonRpcException)) + // pCount++; + //parameters = new object[pCount]; + var asDict = jo as IDictionary; + for (int i = 0; i < loopCt; i++) + { + if (asDict.ContainsKey(metadata.parameters[i].Name) == false) + { + return new JsonResponse() + { + Error = ProcessException(Rpc, + new JsonRpcException(-32602, + "Invalid params", + string.Format("Named parameter '{0}' was not present.", + metadata.parameters[i].Name) + )) + ,Id = Rpc.Id + }; + } + parameters[i] = CleanUpParameter(jo[metadata.parameters[i].Name], metadata.parameters[i]); + } + } + + // Optional Parameter support + // check if we still miss parameters compared to metadata which may include optional parameters. + // if the rpc-call didn't supply a value for an optional parameter, we should be assinging the default value of it. + if (parameters.Length < metaDataParamCount && metadata.defaultValues.Length > 0) // rpc call didn't set values for all optional parameters, so we need to assign the default values for them. + { + var suppliedParamsCount = parameters.Length; // the index we should start storing default values of optional parameters. + var missingParamsCount = metaDataParamCount - parameters.Length; // the amount of optional parameters without a value set by rpc-call. + Array.Resize(ref parameters, parameters.Length + missingParamsCount); // resize the array to include all optional parameters. + + for (int paramIndex = parameters.Length - 1, defaultIndex = metadata.defaultValues.Length - 1; // fill missing parameters from the back + paramIndex >= suppliedParamsCount && defaultIndex >= 0; // to don't overwrite supplied ones. + paramIndex--, defaultIndex--) + { + parameters[paramIndex] = metadata.defaultValues[defaultIndex].Value; + } + + if (missingParamsCount > metadata.defaultValues.Length) + { + return new JsonResponse + { + Error = ProcessException(Rpc, + new JsonRpcException(-32602, + "Invalid params", + string.Format( + "Number of default parameters {0} not sufficient to fill all missing parameters {1}", + metadata.defaultValues.Length, missingParamsCount) + )), + Id = Rpc.Id + }; + } + } + + if (parameters.Length != metaDataParamCount) + { + return new JsonResponse() + { + Error = ProcessException(Rpc, + new JsonRpcException(-32602, + "Invalid params", + string.Format("Expecting {0} parameters, and received {1}", + metadata.parameters.Length, + parameters.Length) + )), + Id = Rpc.Id + }; + } + + try + { + var results = handle.DynamicInvoke(parameters); + var last = parameters.LastOrDefault(); + JsonRpcException contextException; + if (Task.CurrentId.HasValue && RpcExceptions.TryRemove(Task.CurrentId.Value, out contextException)) + { + return new JsonResponse() { Error = ProcessException(Rpc, contextException), Id = Rpc.Id }; + } + if (expectsRefException && last != null && last is JsonRpcException) + { + return new JsonResponse() { Error = ProcessException(Rpc, last as JsonRpcException), Id = Rpc.Id }; + } + + return new JsonResponse() { Result = results }; + } + catch (Exception ex) + { + if (ex is TargetParameterCountException) + { + return new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32602, "Invalid params", ex)) }; + } + + // We really dont care about the TargetInvocationException, just pass on the inner exception + if (ex is JsonRpcException) + { + return new JsonResponse() { Error = ProcessException(Rpc, ex as JsonRpcException) }; + } + if (ex.InnerException != null && ex.InnerException is JsonRpcException) + { + return new JsonResponse() { Error = ProcessException(Rpc, ex.InnerException as JsonRpcException) }; + } + else if (ex.InnerException != null) + { + return new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32603, "Internal Error", ex.InnerException)) }; + } + + return new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32603, "Internal Error", ex)) }; + } + finally + { + RemoveRpcContext(); + } + } + + private void AddRpcContext(object RpcContext) + { + if (Task.CurrentId != null) + RpcContexts[Task.CurrentId.Value] = RpcContext; + } + private void RemoveRpcContext() + { + if (Task.CurrentId != null) + { + var id = Task.CurrentId.Value; + RpcContexts[id] = null; + object va; + RpcContexts.TryRemove(id, out va); + } + } + + private JsonRpcException ProcessException(JsonRequest req,JsonRpcException ex) + { + if(externalErrorHandler!=null) + return externalErrorHandler(req,ex); + return ex; + } + internal JsonRpcException ProcessParseException(string req,JsonRpcException ex) + { + if (parseErrorHandler != null) + return parseErrorHandler(req, ex); + return ex; + } + internal void SetErrorHandler(Func handler) + { + externalErrorHandler = handler; + } + internal void SetParseErrorHandler(Func handler) + { + parseErrorHandler = handler; + } + + #endregion + private object CleanUpParameter(object p, SMDAdditionalParameters metaData) + { + var bob = p as JValue; + //if (bob != null && (bob.Value == null || bob.Value.GetType() == metaData.ObjectType)) + if (bob != null && (bob.Value == null)) + { + return bob.Value; + } + if (bob != null) + { + + // Avoid calling DeserializeObject on types that JValue has an explicit converter for + // try to optimize for the most common types + if (metaData.ObjectType == typeof(string)) return (string)bob; + if (metaData.ObjectType == typeof(int)) return (int)bob; + if (metaData.ObjectType == typeof(double)) return (double)bob; + if (metaData.ObjectType == typeof(float)) return (float)bob; + //if (metaData.ObjectType == typeof(long)) return (long)bob; + //if (metaData.ObjectType == typeof(uint)) return (uint)bob; + //if (metaData.ObjectType == typeof(ulong)) return (ulong)bob; + //if (metaData.ObjectType == typeof(byte[])) return (byte[])bob; + //if (metaData.ObjectType == typeof(Guid)) return (Guid)bob; + if (metaData.ObjectType == typeof(decimal)) return (decimal)bob; + //if (metaData.ObjectType == typeof(TimeSpan)) return (TimeSpan)bob; + //if (metaData.ObjectType == typeof(short)) return (short)bob; + //if (metaData.ObjectType == typeof(ushort)) return (ushort)bob; + //if (metaData.ObjectType == typeof(char)) return (char)bob; + //if (metaData.ObjectType == typeof(DateTime)) return (DateTime)bob; + //if (metaData.ObjectType == typeof(bool)) return (bool)bob; + //if (metaData.ObjectType == typeof(DateTimeOffset)) return (DateTimeOffset)bob; + + if (metaData.ObjectType.IsAssignableFrom(typeof(JValue))) + return bob; + + try + { + return bob.ToObject(metaData.ObjectType); + } + catch (Exception ex) + { + // no need to throw here, they will + // get an invalid cast exception right after this. + } + } + else + { + try + { + if(p is string) + return JsonConvert.DeserializeObject((string) p, metaData.ObjectType); + return JsonConvert.DeserializeObject(p.ToString(), metaData.ObjectType); + } + catch (Exception ex) + { + // no need to throw here, they will + // get an invalid cast exception right after this. + } + } + + return p; + } + + private JsonRpcException PreProcess(JsonRequest request, object context) + { + if (externalPreProcessingHandler == null) + return null; + return externalPreProcessingHandler(request, context); + } + + internal void SetPreProcessHandler(AustinHarris.JsonRpc.PreProcessHandler handler) + { + externalPreProcessingHandler = handler; + } + } + +} + diff --git a/Json-Rpc/JsonRpcProcessor.cs b/Json-Rpc/JsonRpcProcessor.cs index f8c4e01..515e364 100644 --- a/Json-Rpc/JsonRpcProcessor.cs +++ b/Json-Rpc/JsonRpcProcessor.cs @@ -1,145 +1,145 @@ -using System; -using System.Globalization; -using System.Threading; -using System.Threading.Tasks; -using System.Reflection; -using System.IO; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Newtonsoft.Json; - -namespace AustinHarris.JsonRpc -{ - public static class JsonRpcProcessor - { - public static void Process(JsonRpcStateAsync async, object context = null) - { - Task.Factory.StartNew((_async) => - { - var tuple = (Tuple)_async; - ProcessJsonRpcState(tuple.Item1, tuple.Item2); - }, new Tuple(async,context)); - - } - - public static void Process(string sessionId, JsonRpcStateAsync async, object context = null) - { - var t = Task.Factory.StartNew((_async) => - { - var i = (Tuple)_async; - ProcessJsonRpcState(i.Item1, i.Item2, i.Item3); - }, new Tuple(sessionId, async, context)); - - } - internal static void ProcessJsonRpcState(JsonRpcStateAsync async, object jsonRpcContext = null) - { - ProcessJsonRpcState(Handler.DefaultSessionId(), async, jsonRpcContext); - } - internal static void ProcessJsonRpcState(string sessionId, JsonRpcStateAsync async, object jsonRpcContext = null) - { - async.Result = ProcessInternal(sessionId, async.JsonRpc, jsonRpcContext); - async.SetCompleted(); - } - - public static Task Process(string jsonRpc, object context = null) - { - return Process(Handler.DefaultSessionId(), jsonRpc, context); - } - public static Task Process(string sessionId, string jsonRpc, object context = null) - { - return Task.Factory.StartNew((_) => - { - var tuple = (Tuple) _; - return ProcessInternal(tuple.Item1, tuple.Item2, tuple.Item3); - }, new Tuple(sessionId, jsonRpc, context)); - } - - private static string ProcessInternal(string sessionId, string jsonRpc, object jsonRpcContext) - { - var handler = Handler.GetSessionHandler(sessionId); - - try - { - Tuple[] batch = null; - if (isSingleRpc(jsonRpc)) - { - batch = new [] { Tuple.Create(JsonConvert.DeserializeObject(jsonRpc), new JsonResponse()) }; - } - else - { - batch = JsonConvert.DeserializeObject(jsonRpc) - .Select(request => new Tuple(request, new JsonResponse())) - .ToArray(); - } - - if (batch.Length == 0) - { - return Newtonsoft.Json.JsonConvert.SerializeObject(new JsonResponse - { - Error = handler.ProcessParseException(jsonRpc, - new JsonRpcException(3200, "Invalid Request", "Batch of calls was empty.")) - }); - } - - foreach (var tuple in batch) - { - var jsonRequest = tuple.Item1; - var jsonResponse = tuple.Item2; - - if (jsonRequest == null) - { - jsonResponse.Error = handler.ProcessParseException(jsonRpc, - new JsonRpcException(-32700, "Parse error", - "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.")); - } - else - { - jsonResponse.Id = jsonRequest.Id; - - if (jsonRequest.Method == null) - { - jsonResponse.Error = handler.ProcessParseException(jsonRpc, - new JsonRpcException(-32600, "Invalid Request", "Missing property 'method'")); - } - else - { - var data = handler.Handle(jsonRequest, jsonRpcContext); - - if (data == null) continue; - - jsonResponse.Error = data.Error; - jsonResponse.Result = data.Result; - } - } - } - - var responses = new string[batch.Count(x=>x.Item2.Id!=null || x.Item2.Error != null)]; - var idx = 0; - foreach (var resp in batch.Where(x => x.Item2.Id != null || x.Item2.Error != null)) - { - responses[idx++] = JsonConvert.SerializeObject(resp.Item2); - } - - return responses.Length == 1 ? responses[0] : string.Format("[{0}]", string.Join(",", responses)); - } - catch (Exception ex) - { - return Newtonsoft.Json.JsonConvert.SerializeObject(new JsonResponse - { - Error = handler.ProcessParseException(jsonRpc, new JsonRpcException(-32700, "Parse error", ex)) - }); - } - } - - private static bool isSingleRpc(string json) - { - for (int i = 0; i < json.Length; i++) - { - if (json[i] == '{') return true; - else if (json[i] == '[') return false; - } - return true; - } - } -} +using System; +using System.Globalization; +using System.Threading; +using System.Threading.Tasks; +using System.Reflection; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Newtonsoft.Json; + +namespace AustinHarris.JsonRpc +{ + public static class JsonRpcProcessor + { + public static void Process(JsonRpcStateAsync async, object context = null) + { + Task.Factory.StartNew((_async) => + { + var tuple = (Tuple)_async; + ProcessJsonRpcState(tuple.Item1, tuple.Item2); + }, new Tuple(async,context)); + + } + + public static void Process(string sessionId, JsonRpcStateAsync async, object context = null) + { + var t = Task.Factory.StartNew((_async) => + { + var i = (Tuple)_async; + ProcessJsonRpcState(i.Item1, i.Item2, i.Item3); + }, new Tuple(sessionId, async, context)); + + } + internal static void ProcessJsonRpcState(JsonRpcStateAsync async, object jsonRpcContext = null) + { + ProcessJsonRpcState(Handler.DefaultSessionId(), async, jsonRpcContext); + } + internal static void ProcessJsonRpcState(string sessionId, JsonRpcStateAsync async, object jsonRpcContext = null) + { + async.Result = ProcessInternal(sessionId, async.JsonRpc, jsonRpcContext); + async.SetCompleted(); + } + + public static Task Process(string jsonRpc, object context = null) + { + return Process(Handler.DefaultSessionId(), jsonRpc, context); + } + public static Task Process(string sessionId, string jsonRpc, object context = null) + { + return Task.Factory.StartNew((_) => + { + var tuple = (Tuple) _; + return ProcessInternal(tuple.Item1, tuple.Item2, tuple.Item3); + }, new Tuple(sessionId, jsonRpc, context)); + } + + private static string ProcessInternal(string sessionId, string jsonRpc, object jsonRpcContext) + { + var handler = Handler.GetSessionHandler(sessionId); + + try + { + Tuple[] batch = null; + if (isSingleRpc(jsonRpc)) + { + batch = new [] { Tuple.Create(JsonConvert.DeserializeObject(jsonRpc), new JsonResponse()) }; + } + else + { + batch = JsonConvert.DeserializeObject(jsonRpc) + .Select(request => new Tuple(request, new JsonResponse())) + .ToArray(); + } + + if (batch.Length == 0) + { + return Newtonsoft.Json.JsonConvert.SerializeObject(new JsonResponse + { + Error = handler.ProcessParseException(jsonRpc, + new JsonRpcException(3200, "Invalid Request", "Batch of calls was empty.")) + }); + } + + foreach (var tuple in batch) + { + var jsonRequest = tuple.Item1; + var jsonResponse = tuple.Item2; + + if (jsonRequest == null) + { + jsonResponse.Error = handler.ProcessParseException(jsonRpc, + new JsonRpcException(-32700, "Parse error", + "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.")); + } + else + { + jsonResponse.Id = jsonRequest.Id; + + if (jsonRequest.Method == null) + { + jsonResponse.Error = handler.ProcessParseException(jsonRpc, + new JsonRpcException(-32600, "Invalid Request", "Missing property 'method'")); + } + else + { + var data = handler.Handle(jsonRequest, jsonRpcContext); + + if (data == null) continue; + + jsonResponse.Error = data.Error; + jsonResponse.Result = data.Result; + } + } + } + + var responses = new string[batch.Count(x=>x.Item2.Id!=null || x.Item2.Error != null)]; + var idx = 0; + foreach (var resp in batch.Where(x => x.Item2.Id != null || x.Item2.Error != null)) + { + responses[idx++] = JsonConvert.SerializeObject(resp.Item2); + } + + return responses.Length == 1 ? responses[0] : string.Format("[{0}]", string.Join(",", responses)); + } + catch (Exception ex) + { + return Newtonsoft.Json.JsonConvert.SerializeObject(new JsonResponse + { + Error = handler.ProcessParseException(jsonRpc, new JsonRpcException(-32700, "Parse error", ex)) + }); + } + } + + private static bool isSingleRpc(string json) + { + for (int i = 0; i < json.Length; i++) + { + if (json[i] == '{') return true; + else if (json[i] == '[') return false; + } + return true; + } + } +} diff --git a/TestServer_Console/TestServer_Console.csproj b/TestServer_Console/TestServer_Console.csproj index 91ea00d..903dd05 100644 --- a/TestServer_Console/TestServer_Console.csproj +++ b/TestServer_Console/TestServer_Console.csproj @@ -1,83 +1,83 @@ - - - - Debug - x86 - 8.0.30703 - 2.0 - {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B} - Exe - Properties - TestServer_Console - TestServer_Console - v4.0 - Client - 512 - SAK - SAK - SAK - SAK - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - x86 - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - AnyCPU - bin\Debug\ - - - AnyCPU - bin\Release\ - - - - False - ..\packages\Newtonsoft.Json.6.0.3\lib\net40\Newtonsoft.Json.dll - - - - - - - - - - - - - - - - - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307} - AustinHarris.JsonRpc - - - - - - + + + + Debug + x86 + 8.0.30703 + 2.0 + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B} + Exe + Properties + TestServer_Console + TestServer_Console + v4.0 + Client + 512 + SAK + SAK + SAK + SAK + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + AnyCPU + bin\Debug\ + + + AnyCPU + bin\Release\ + + + + False + ..\packages\Newtonsoft.Json.6.0.3\lib\net40\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307} + AustinHarris.JsonRpc + + + + + + + --> \ No newline at end of file From b71f56afe92d1d31604d4d061d14b6fabbdffba1 Mon Sep 17 00:00:00 2001 From: Martin Daetz Date: Thu, 5 Feb 2015 17:14:57 +0100 Subject: [PATCH 17/81] fix [] response on single notification --- AustinHarris.JsonRpcTest/UnitTest1.cs | 6 ++++++ Json-Rpc/JsonRpcProcessor.cs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/AustinHarris.JsonRpcTest/UnitTest1.cs b/AustinHarris.JsonRpcTest/UnitTest1.cs index a1f75ab..2ea70d5 100644 --- a/AustinHarris.JsonRpcTest/UnitTest1.cs +++ b/AustinHarris.JsonRpcTest/UnitTest1.cs @@ -1340,10 +1340,16 @@ public void TestBatchResult() string request = @"[{},{""jsonrpc"":""2.0"",""id"":4},{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}]"; + var secondRequest = @"{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}"; var result = JsonRpcProcessor.Process(request); result.Wait(); Assert.IsFalse(result.Result.EndsWith(@",]"), "result.Result.EndsWith(@',]')"); + + result = JsonRpcProcessor.Process(secondRequest); + result.Wait(); + + Assert.IsTrue(string.IsNullOrEmpty(result.Result)); } } } diff --git a/Json-Rpc/JsonRpcProcessor.cs b/Json-Rpc/JsonRpcProcessor.cs index f8c4e01..00fad9a 100644 --- a/Json-Rpc/JsonRpcProcessor.cs +++ b/Json-Rpc/JsonRpcProcessor.cs @@ -121,7 +121,7 @@ private static string ProcessInternal(string sessionId, string jsonRpc, object j responses[idx++] = JsonConvert.SerializeObject(resp.Item2); } - return responses.Length == 1 ? responses[0] : string.Format("[{0}]", string.Join(",", responses)); + return responses.Length == 0 ? string.Empty : responses.Length == 1 ? responses[0] : string.Format("[{0}]", string.Join(",", responses)); } catch (Exception ex) { From a4e89915a37d51e7daec1388214f76472b28b93b Mon Sep 17 00:00:00 2001 From: Martin Daetz Date: Thu, 5 Feb 2015 18:15:40 +0100 Subject: [PATCH 18/81] fix omitted parms issue --- AustinHarris.JsonRpcTest/UnitTest1.cs | 12 ++++++++++++ Json-Rpc/Handler.cs | 18 +++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/AustinHarris.JsonRpcTest/UnitTest1.cs b/AustinHarris.JsonRpcTest/UnitTest1.cs index a1f75ab..c98b057 100644 --- a/AustinHarris.JsonRpcTest/UnitTest1.cs +++ b/AustinHarris.JsonRpcTest/UnitTest1.cs @@ -1345,5 +1345,17 @@ public void TestBatchResult() Assert.IsFalse(result.Result.EndsWith(@",]"), "result.Result.EndsWith(@',]')"); } + + [TestMethod] + public void TestLeftOutParams() + { + var request = + @"{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""id"":1}"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + + Assert.IsFalse(result.Result.Contains(@"error"":{""code"":-32602"), @"According to JSON-RPC 2.0 the ""params"" member MAY be omitted."); + } } } diff --git a/Json-Rpc/Handler.cs b/Json-Rpc/Handler.cs index 4fa7845..95a6046 100644 --- a/Json-Rpc/Handler.cs +++ b/Json-Rpc/Handler.cs @@ -200,16 +200,6 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null) { return new JsonResponse() { Result = null, Error = new JsonRpcException(-32601, "Method not found", "The method does not exist / is not available."), Id = Rpc.Id }; } - if (Rpc.Params is ICollection == false) - { - return new JsonResponse() - { - Result = null, - Error = new JsonRpcException(-32602, - "Invalid params", "The number of parameters could not be counted"), - Id = Rpc.Id - }; - } bool isJObject = Rpc.Params is Newtonsoft.Json.Linq.JObject; bool isJArray = Rpc.Params is Newtonsoft.Json.Linq.JArray; @@ -218,7 +208,13 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null) var metaDataParamCount = metadata.parameters.Count(x => x != null); var getCount = Rpc.Params as ICollection; - var loopCt = getCount.Count; + var loopCt = 0; + + if (getCount != null) + { + loopCt = getCount.Count; + } + var paramCount = loopCt; if (paramCount == metaDataParamCount - 1 && metadata.parameters[metaDataParamCount-1].ObjectType.Name.Contains(typeof(JsonRpcException).Name)) { From 8429b7e72e8ff1ed1e0317ef1789d0426c7348a5 Mon Sep 17 00:00:00 2001 From: Martin Daetz Date: Thu, 5 Feb 2015 23:05:40 +0100 Subject: [PATCH 19/81] some more Assertions --- AustinHarris.JsonRpcTest/UnitTest1.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/AustinHarris.JsonRpcTest/UnitTest1.cs b/AustinHarris.JsonRpcTest/UnitTest1.cs index 2ea70d5..dfc6cfe 100644 --- a/AustinHarris.JsonRpcTest/UnitTest1.cs +++ b/AustinHarris.JsonRpcTest/UnitTest1.cs @@ -1350,6 +1350,17 @@ public void TestBatchResult() result.Wait(); Assert.IsTrue(string.IsNullOrEmpty(result.Result)); + + result = JsonRpcProcessor.Process(@"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]"); + result.Wait(); + + Assert.IsTrue(result.Result.EndsWith("]")); + + result = + JsonRpcProcessor.Process(@"{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]"); + result.Wait(); + Assert.IsFalse(result.Result.EndsWith("]")); } } } + From 993d6e73af40483d90314ec9056778506aa94bb4 Mon Sep 17 00:00:00 2001 From: Martin Daetz Date: Tue, 10 Feb 2015 22:14:10 +0100 Subject: [PATCH 20/81] split the tests --- AustinHarris.JsonRpcTest/UnitTest1.cs | 41 +++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/AustinHarris.JsonRpcTest/UnitTest1.cs b/AustinHarris.JsonRpcTest/UnitTest1.cs index dfc6cfe..93250e1 100644 --- a/AustinHarris.JsonRpcTest/UnitTest1.cs +++ b/AustinHarris.JsonRpcTest/UnitTest1.cs @@ -1,4 +1,7 @@ using System; +using System.Security.Cryptography.X509Certificates; +using System.Text.RegularExpressions; +using System.Threading.Tasks; using AustinHarris.JsonRpc; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -1335,28 +1338,54 @@ public void TestOptionalParametersBoolsAndStrings() } [TestMethod] - public void TestBatchResult() + public void TestBatchResultWrongRequests() + { + string request = @"[{},{""jsonrpc"":""2.0"",""id"":4}]"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + + Assert.IsTrue(Regex.IsMatch(result.Result, @"\[(\{.*""error"":.*?,""id"":.*?\}),(\{.*""error"":.*?,""id"":.*?\})\]"), "Should have two errors."); + } + + [TestMethod] + public void TestBatchResultMultipleMethodCallsNotificationAtLast() { string request = - @"[{},{""jsonrpc"":""2.0"",""id"":4},{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}]"; + @"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}]"; - var secondRequest = @"{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}"; var result = JsonRpcProcessor.Process(request); result.Wait(); Assert.IsFalse(result.Result.EndsWith(@",]"), "result.Result.EndsWith(@',]')"); - result = JsonRpcProcessor.Process(secondRequest); + } + + [TestMethod] + public void TestEmptyBatchResult() + { + var secondRequest = @"{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}"; + var result = JsonRpcProcessor.Process(secondRequest); result.Wait(); Assert.IsTrue(string.IsNullOrEmpty(result.Result)); + } - result = JsonRpcProcessor.Process(@"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]"); + [TestMethod] + public void TestMultipleResults() + { + var result = + JsonRpcProcessor.Process( + @"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]"); result.Wait(); Assert.IsTrue(result.Result.EndsWith("]")); + } - result = + [TestMethod] + public void TestSingleResultBatch() + { + var result = JsonRpcProcessor.Process(@"{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]"); result.Wait(); Assert.IsFalse(result.Result.EndsWith("]")); From 09c18de0f1ceb7430e7ae1dc105dc9a3bad73945 Mon Sep 17 00:00:00 2001 From: Astn Date: Wed, 11 Feb 2015 22:38:34 -0700 Subject: [PATCH 21/81] test was missing the opening '[' in the request to make it take the batch processing path. --- AustinHarris.JsonRpcTest/UnitTest1.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AustinHarris.JsonRpcTest/UnitTest1.cs b/AustinHarris.JsonRpcTest/UnitTest1.cs index b8ced97..6190f1c 100644 --- a/AustinHarris.JsonRpcTest/UnitTest1.cs +++ b/AustinHarris.JsonRpcTest/UnitTest1.cs @@ -1398,7 +1398,7 @@ public void TestMultipleResults() public void TestSingleResultBatch() { var result = - JsonRpcProcessor.Process(@"{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]"); + JsonRpcProcessor.Process(@"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]"); result.Wait(); Assert.IsFalse(result.Result.EndsWith("]")); } From 2f2b56223777c577c3f6e1458c8e6bbd43c84319 Mon Sep 17 00:00:00 2001 From: danoczim Date: Fri, 19 Jun 2015 16:00:58 +0200 Subject: [PATCH 22/81] Async process fully compatitible (+1 squashed commits) Squashed commits: [e473cce] asynchronous process on JsonProcessor class --- .gitignore | 1 + Json-Rpc/Handler.cs | 119 ++++++++++++++++++++++++----------- Json-Rpc/JsonRpcProcessor.cs | 89 ++++++++++++++++++++++++-- 3 files changed, 166 insertions(+), 43 deletions(-) diff --git a/.gitignore b/.gitignore index bdc3535..11908c9 100644 --- a/.gitignore +++ b/.gitignore @@ -106,3 +106,4 @@ Generated_Code #added for RIA/Silverlight projects _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML +.nuget/NuGet.exe diff --git a/Json-Rpc/Handler.cs b/Json-Rpc/Handler.cs index ff81a78..b2ca79d 100644 --- a/Json-Rpc/Handler.cs +++ b/Json-Rpc/Handler.cs @@ -8,7 +8,8 @@ using Newtonsoft.Json; using System.Threading.Tasks; using System.Collections.Concurrent; -using Newtonsoft.Json.Linq; + using Newtonsoft.Json.Linq; + using System.Threading; public class Handler { @@ -26,7 +27,7 @@ static Handler() //current = new Handler(Guid.NewGuid().ToString()); _defaultSessionId = Guid.NewGuid().ToString(); _sessionHandlers = new ConcurrentDictionary(); - _sessionHandlers[_defaultSessionId]= new Handler(_defaultSessionId); + _sessionHandlers[_defaultSessionId] = new Handler(_defaultSessionId); } private Handler(string sessionId) @@ -55,7 +56,7 @@ public static Handler GetSessionHandler(string sessionId) { return _sessionHandlers.GetOrAdd(sessionId, new Handler(sessionId)); } - + /// /// gets the default session /// @@ -72,7 +73,7 @@ public static Handler GetSessionHandler() public static void DestroySession(string sessionId) { Handler h; - _sessionHandlers.TryRemove(sessionId,out h); + _sessionHandlers.TryRemove(sessionId, out h); h.Handlers.Clear(); h.MetaData.Services.Clear(); } @@ -92,7 +93,7 @@ public void Destroy() /// /// The sessionID of this Handler /// - public string SessionId { get; private set; } + public string SessionId { get; private set; } private static ConcurrentDictionary RpcContexts = new ConcurrentDictionary(); private static ConcurrentDictionary RpcExceptions = new ConcurrentDictionary(); @@ -104,7 +105,7 @@ public void Destroy() /// public static object RpcContext() { - if (Task.CurrentId == null) + if (Task.CurrentId == null) return null; if (RpcContexts.ContainsKey(Task.CurrentId.Value) == false) @@ -140,7 +141,7 @@ private void RemoveRpcException() private AustinHarris.JsonRpc.PreProcessHandler externalPreProcessingHandler; private Func externalErrorHandler; private Func parseErrorHandler; - private Dictionary Handlers { get; set; } + private Dictionary Handlers { get; set; } #endregion /// @@ -180,15 +181,26 @@ public void UnRegister(string key) /// JsonRpc Request to be processed /// Optional context that will be available from within the jsonRpcMethod. /// - public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null) + public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null, Action callback = null) { + //empty delegate declaration if callback is not provided + if (null == callback) + { + callback = delegate(JsonResponse a) { }; + } + AddRpcContext(RpcContext); var preProcessingException = PreProcess(Rpc, RpcContext); if (preProcessingException != null) { - return new JsonResponse() { Error = preProcessingException, - Id = Rpc.Id }; + JsonResponse response = new JsonResponse() + { + Error = preProcessingException, + Id = Rpc.Id + }; + callback.Invoke(response); + return response; } SMDService metadata = null; @@ -198,7 +210,14 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null) if (haveDelegate == false || haveMetadata == false || metadata == null || handle == null) { - return new JsonResponse() { Result = null, Error = new JsonRpcException(-32601, "Method not found", "The method does not exist / is not available."), Id = Rpc.Id }; + JsonResponse response = new JsonResponse() + { + Result = null, + Error = new JsonRpcException(-32601, "Method not found", "The method does not exist / is not available."), + Id = Rpc.Id + }; + callback.Invoke(response); + return response; } bool isJObject = Rpc.Params is Newtonsoft.Json.Linq.JObject; @@ -206,17 +225,17 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null) object[] parameters = null; bool expectsRefException = false; var metaDataParamCount = metadata.parameters.Count(x => x != null); - + var getCount = Rpc.Params as ICollection; var loopCt = 0; - + if (getCount != null) { loopCt = getCount.Count; } var paramCount = loopCt; - if (paramCount == metaDataParamCount - 1 && metadata.parameters[metaDataParamCount-1].ObjectType.Name.Contains(typeof(JsonRpcException).Name)) + if (paramCount == metaDataParamCount - 1 && metadata.parameters[metaDataParamCount - 1].ObjectType.Name.Contains(typeof(JsonRpcException).Name)) { paramCount++; expectsRefException = true; @@ -234,7 +253,7 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null) for (int i = 0; i < loopCt; i++) { parameters[i] = CleanUpParameter(jarr[i], metadata.parameters[i]); - } + } } else if (isJObject) { @@ -249,16 +268,18 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null) { if (asDict.ContainsKey(metadata.parameters[i].Name) == false) { - return new JsonResponse() + JsonResponse response = new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32602, "Invalid params", string.Format("Named parameter '{0}' was not present.", metadata.parameters[i].Name) - )) - ,Id = Rpc.Id + )), + Id = Rpc.Id }; + callback.Invoke(response); + return response; } parameters[i] = CleanUpParameter(jo[metadata.parameters[i].Name], metadata.parameters[i]); } @@ -282,7 +303,7 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null) if (missingParamsCount > metadata.defaultValues.Length) { - return new JsonResponse + JsonResponse response = new JsonResponse { Error = ProcessException(Rpc, new JsonRpcException(-32602, @@ -293,12 +314,14 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null) )), Id = Rpc.Id }; + callback.Invoke(response); + return response; } } - + if (parameters.Length != metaDataParamCount) { - return new JsonResponse() + JsonResponse response = new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32602, @@ -309,46 +332,68 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null) )), Id = Rpc.Id }; + callback.Invoke(response); + return response; } try { + //callback is stored to thread's local storage in order to get it directly from concrete JsonRpcService method implementation + if (null != callback) + { + Thread.SetData(Thread.GetNamedDataSlot("Callback"), callback); + } var results = handle.DynamicInvoke(parameters); var last = parameters.LastOrDefault(); JsonRpcException contextException; if (Task.CurrentId.HasValue && RpcExceptions.TryRemove(Task.CurrentId.Value, out contextException)) { - return new JsonResponse() { Error = ProcessException(Rpc, contextException), Id = Rpc.Id }; + JsonResponse response = new JsonResponse() { Error = ProcessException(Rpc, contextException), Id = Rpc.Id }; + callback.Invoke(response); + return response; } if (expectsRefException && last != null && last is JsonRpcException) { - return new JsonResponse() { Error = ProcessException(Rpc, last as JsonRpcException), Id = Rpc.Id }; + JsonResponse response = new JsonResponse() { Error = ProcessException(Rpc, last as JsonRpcException), Id = Rpc.Id }; + callback.Invoke(response); + return response; } return new JsonResponse() { Result = results }; } catch (Exception ex) { + JsonResponse response; if (ex is TargetParameterCountException) { - return new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32602, "Invalid params", ex)) }; + response = new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32602, "Invalid params", ex)) }; + callback.Invoke(response); + return response; } // We really dont care about the TargetInvocationException, just pass on the inner exception if (ex is JsonRpcException) { - return new JsonResponse() { Error = ProcessException(Rpc, ex as JsonRpcException) }; + response = new JsonResponse() { Error = ProcessException(Rpc, ex as JsonRpcException) }; + callback.Invoke(response); + return response; } if (ex.InnerException != null && ex.InnerException is JsonRpcException) { - return new JsonResponse() { Error = ProcessException(Rpc, ex.InnerException as JsonRpcException) }; + response = new JsonResponse() { Error = ProcessException(Rpc, ex.InnerException as JsonRpcException) }; + callback.Invoke(response); + return response; } else if (ex.InnerException != null) { - return new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32603, "Internal Error", ex.InnerException)) }; + response = new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32603, "Internal Error", ex.InnerException)) }; + callback.Invoke(response); + return response; } - return new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32603, "Internal Error", ex)) }; + response = new JsonResponse() { Error = ProcessException(Rpc, new JsonRpcException(-32603, "Internal Error", ex)) }; + callback.Invoke(response); + return response; } finally { @@ -371,14 +416,14 @@ private void RemoveRpcContext() RpcContexts.TryRemove(id, out va); } } - - private JsonRpcException ProcessException(JsonRequest req,JsonRpcException ex) + + private JsonRpcException ProcessException(JsonRequest req, JsonRpcException ex) { - if(externalErrorHandler!=null) - return externalErrorHandler(req,ex); + if (externalErrorHandler != null) + return externalErrorHandler(req, ex); return ex; } - internal JsonRpcException ProcessParseException(string req,JsonRpcException ex) + internal JsonRpcException ProcessParseException(string req, JsonRpcException ex) { if (parseErrorHandler != null) return parseErrorHandler(req, ex); @@ -392,7 +437,7 @@ internal void SetParseErrorHandler(Func callback, object context = null) + { + Task.Factory.StartNew(() => AsyncProcessInternal(Handler.DefaultSessionId(), jsonRpc, context, callback)); + } + + private static void AsyncProcessInternal(string sessionId, string jsonRpc, object jsonRpcContext, Action callback) + { + Handler handler = Handler.GetSessionHandler(sessionId); + + try + { + Tuple[] batch = null; + if (isSingleRpc(jsonRpc)) + { + batch = new[] { Tuple.Create(JsonConvert.DeserializeObject(jsonRpc)) }; + } + else + { + batch = JsonConvert.DeserializeObject(jsonRpc) + .Select(request => new Tuple(request)) + .ToArray(); + } + + if (batch.Length == 0) + { + callback.Invoke(Newtonsoft.Json.JsonConvert.SerializeObject(new JsonResponse + { + Error = handler.ProcessParseException(jsonRpc, + new JsonRpcException(3200, "Invalid Request", "Batch of calls was empty.")) + })); + } + + foreach (var tuple in batch) + { + JsonRequest jsonRequest = tuple.Item1; + JsonResponse jsonResponse = new JsonResponse(); + + if (jsonRequest == null) + { + jsonResponse.Error = handler.ProcessParseException(jsonRpc, + new JsonRpcException(-32700, "Parse error", + "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.")); + } + else + { + jsonResponse.Id = jsonRequest.Id; + + if (jsonRequest.Method == null) + { + jsonResponse.Error = handler.ProcessParseException(jsonRpc, + new JsonRpcException(-32600, "Invalid Request", "Missing property 'method'")); + } + else + { + handler.Handle(jsonRequest, jsonRpcContext, + delegate(JsonResponse a) + { + a.Id = jsonRequest.Id; + if (a.Id != null || a.Error != null) + { + callback.Invoke(JsonConvert.SerializeObject(a)); + } + } + ); + } + } + } + } + catch (Exception ex) + { + callback.Invoke(Newtonsoft.Json.JsonConvert.SerializeObject(new JsonResponse + { + Error = handler.ProcessParseException(jsonRpc, new JsonRpcException(-32700, "Parse error", ex)) + })); + } + } + public static void Process(JsonRpcStateAsync async, object context = null) { Task.Factory.StartNew((_async) => { var tuple = (Tuple)_async; ProcessJsonRpcState(tuple.Item1, tuple.Item2); - }, new Tuple(async,context)); - + }, new Tuple(async, context)); + } public static void Process(string sessionId, JsonRpcStateAsync async, object context = null) @@ -50,7 +127,7 @@ public static Task Process(string sessionId, string jsonRpc, object cont { return Task.Factory.StartNew((_) => { - var tuple = (Tuple) _; + var tuple = (Tuple)_; return ProcessInternal(tuple.Item1, tuple.Item2, tuple.Item3); }, new Tuple(sessionId, jsonRpc, context)); } @@ -64,7 +141,7 @@ private static string ProcessInternal(string sessionId, string jsonRpc, object j Tuple[] batch = null; if (isSingleRpc(jsonRpc)) { - batch = new [] { Tuple.Create(JsonConvert.DeserializeObject(jsonRpc), new JsonResponse()) }; + batch = new[] { Tuple.Create(JsonConvert.DeserializeObject(jsonRpc), new JsonResponse()) }; } else { @@ -72,7 +149,7 @@ private static string ProcessInternal(string sessionId, string jsonRpc, object j .Select(request => new Tuple(request, new JsonResponse())) .ToArray(); } - + if (batch.Length == 0) { return Newtonsoft.Json.JsonConvert.SerializeObject(new JsonResponse @@ -114,7 +191,7 @@ private static string ProcessInternal(string sessionId, string jsonRpc, object j } } - var responses = new string[batch.Count(x=>x.Item2.Id!=null || x.Item2.Error != null)]; + var responses = new string[batch.Count(x => x.Item2.Id != null || x.Item2.Error != null)]; var idx = 0; foreach (var resp in batch.Where(x => x.Item2.Id != null || x.Item2.Error != null)) { From 49837d0b695b2ea7a651e6bd80b9d472bfb113c4 Mon Sep 17 00:00:00 2001 From: danoczim Date: Tue, 7 Jul 2015 15:41:59 +0200 Subject: [PATCH 23/81] real async workflow --- Json-Rpc/Handler.cs | 36 +++++++++++++++++++++++++++++++----- Json-Rpc/JsonRpcProcessor.cs | 27 +++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/Json-Rpc/Handler.cs b/Json-Rpc/Handler.cs index b2ca79d..db2dadc 100644 --- a/Json-Rpc/Handler.cs +++ b/Json-Rpc/Handler.cs @@ -149,6 +149,8 @@ private void RemoveRpcException() /// public SMD MetaData { get; set; } + private const string THREAD_CALLBACK_SLOT_NAME ="Callback"; + #region Public Methods /// @@ -199,7 +201,9 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null, Action + /// Method returns the actual callback set to this thread in Handle() method. + /// If callback is not set, then empty callback is returned. + /// + /// + internal Action GetAsyncCallback() + { + object o = Thread.GetData(Thread.GetNamedDataSlot(THREAD_CALLBACK_SLOT_NAME)); + Action callback; + if(o is Action) + { + callback = o as Action; + } + else + { + callback = delegate(JsonResponse a) { }; + } + return callback; + } + private void AddRpcContext(object RpcContext) { if (Task.CurrentId != null) diff --git a/Json-Rpc/JsonRpcProcessor.cs b/Json-Rpc/JsonRpcProcessor.cs index 44187d5..31bc872 100644 --- a/Json-Rpc/JsonRpcProcessor.cs +++ b/Json-Rpc/JsonRpcProcessor.cs @@ -18,6 +18,33 @@ public static void AsyncProcess(string jsonRpc, Action callback, object Task.Factory.StartNew(() => AsyncProcessInternal(Handler.DefaultSessionId(), jsonRpc, context, callback)); } + public static void AsyncProcess(string sessionId,string jsonRpc, Action callback, object context = null) + { + Task.Factory.StartNew(() => AsyncProcessInternal(sessionId, jsonRpc, context, callback)); + } + + /// + /// The callback will be returned to the user, who needs to invoke it in concrete + /// service implementation. Call should be made directly from same thread as + /// service method is executed. + /// + /// Handler session id + /// + public static Action GetAsyncProcessCallback(string sessionId = "") + { + Handler handler; + if ("" == sessionId) + { + handler = Handler.GetSessionHandler(Handler.DefaultSessionId()); + } + else + { + handler = Handler.GetSessionHandler(sessionId); + } + + return handler.GetAsyncCallback(); + } + private static void AsyncProcessInternal(string sessionId, string jsonRpc, object jsonRpcContext, Action callback) { Handler handler = Handler.GetSessionHandler(sessionId); From a54682a9090db6ffd228d9a0be77b7f093eb6db2 Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Sat, 12 Sep 2015 01:49:06 -0600 Subject: [PATCH 24/81] switched to nunit for xamarin support. Updated to latest Json.Net. Added a unit test around removing a handler --- AustinHarris.JsonRpc.sln | 57 +- .../AustinHarris.JsonRpcTest.csproj | 105 -- .../Properties/AssemblyInfo.cs | 36 - AustinHarris.JsonRpcTest/UnitTest1.cs | 1407 ---------------- .../AustinHarris.JsonRpcTestN.csproj | 50 + AustinHarris.JsonRpcTestN/Test.cs | 1439 +++++++++++++++++ AustinHarris.JsonRpcTestN/packages.config | 4 + .../service.cs | 3 +- TestServer_Console/TestServer_Console.csproj | 19 +- TestServer_Console/packages.config | 2 +- 10 files changed, 1542 insertions(+), 1580 deletions(-) delete mode 100644 AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj delete mode 100644 AustinHarris.JsonRpcTest/Properties/AssemblyInfo.cs delete mode 100644 AustinHarris.JsonRpcTest/UnitTest1.cs create mode 100644 AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj create mode 100644 AustinHarris.JsonRpcTestN/Test.cs create mode 100644 AustinHarris.JsonRpcTestN/packages.config rename {AustinHarris.JsonRpcTest => AustinHarris.JsonRpcTestN}/service.cs (98%) diff --git a/AustinHarris.JsonRpc.sln b/AustinHarris.JsonRpc.sln index 4b0e5fc..3fa6f16 100644 --- a/AustinHarris.JsonRpc.sln +++ b/AustinHarris.JsonRpc.sln @@ -1,6 +1,6 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 +# Visual Studio 2012 VisualStudioVersion = 12.0.30723.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BBFBBA8A-2F75-422C-ACCD-D05A6EF7244C}" @@ -14,14 +14,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AustinHarris.JsonRpc", "Jso EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AustinHarris.JsonRpc.AspNet", "AustinHarris.JsonRpc.AspNet\AustinHarris.JsonRpc.AspNet.csproj", "{FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AustinHarris.JsonRpcTest", "AustinHarris.JsonRpcTest\AustinHarris.JsonRpcTest.csproj", "{0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AustinHarris.JsonRpcTestN", "AustinHarris.JsonRpcTestN\AustinHarris.JsonRpcTestN.csproj", "{8569B076-5A8B-4D6A-B75D-EF75A390AA5F}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{4811B06E-0A04-4CD4-9018-FE8295E8BF08}" - ProjectSection(SolutionItems) = preProject - .nuget\NuGet.Config = .nuget\NuGet.Config - .nuget\NuGet.exe = .nuget\NuGet.exe - .nuget\NuGet.targets = .nuget\NuGet.targets - EndProjectSection +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestServer_Console", "TestServer_Console\TestServer_Console.csproj", "{31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -49,6 +44,38 @@ Global {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|Mixed Platforms.Build.0 = Release|x86 {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|x86.ActiveCfg = Release|x86 {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|x86.Build.0 = Release|x86 + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|ARM.ActiveCfg = Debug|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|ARM.Build.0 = Debug|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|x86.ActiveCfg = Debug|x86 + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|x86.Build.0 = Debug|x86 + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|Any CPU.Build.0 = Release|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|ARM.ActiveCfg = Release|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|ARM.Build.0 = Release|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|x86.ActiveCfg = Release|x86 + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|x86.Build.0 = Release|x86 + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Debug|ARM.ActiveCfg = Debug|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Debug|ARM.Build.0 = Debug|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Debug|x86.ActiveCfg = Debug|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Debug|x86.Build.0 = Debug|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Release|Any CPU.Build.0 = Release|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Release|ARM.ActiveCfg = Release|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Release|ARM.Build.0 = Release|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Release|x86.ActiveCfg = Release|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Release|x86.Build.0 = Release|Any CPU {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Any CPU.Build.0 = Debug|Any CPU {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|ARM.ActiveCfg = Debug|Any CPU @@ -61,18 +88,8 @@ Global {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Mixed Platforms.Build.0 = Release|Any CPU {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|x86.ActiveCfg = Release|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|ARM.ActiveCfg = Debug|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|x86.ActiveCfg = Debug|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|Any CPU.Build.0 = Release|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|ARM.ActiveCfg = Release|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|x86.ActiveCfg = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj b/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj deleted file mode 100644 index d502129..0000000 --- a/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj +++ /dev/null @@ -1,105 +0,0 @@ - - - - Debug - AnyCPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD} - Library - Properties - AustinHarris.JsonRpcTest - AustinHarris.JsonRpcTest - v4.0 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - ..\ - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - - - 3.5 - - - - - - - - - - - - - - - - - - - - - - {24fc1a2a-0bc3-43a7-9bfe-b628c2c4a307} - AustinHarris.JsonRpc - - - - - - - False - - - False - - - False - - - False - - - - - - - - - - Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Aktivieren Sie die Wiederherstellung von NuGet-Paketen, um die fehlende Datei herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". - - - - - \ No newline at end of file diff --git a/AustinHarris.JsonRpcTest/Properties/AssemblyInfo.cs b/AustinHarris.JsonRpcTest/Properties/AssemblyInfo.cs deleted file mode 100644 index 8fe95b7..0000000 --- a/AustinHarris.JsonRpcTest/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("AustinHarris.JsonRpcTest")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("AustinHarris.JsonRpcTest")] -[assembly: AssemblyCopyright("Copyright © 2014")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("45d95cf9-ddf4-4eda-add0-80f5222a2a38")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/AustinHarris.JsonRpcTest/UnitTest1.cs b/AustinHarris.JsonRpcTest/UnitTest1.cs deleted file mode 100644 index 6190f1c..0000000 --- a/AustinHarris.JsonRpcTest/UnitTest1.cs +++ /dev/null @@ -1,1407 +0,0 @@ -using System; -using System.Security.Cryptography.X509Certificates; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using AustinHarris.JsonRpc; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace UnitTests -{ - [TestClass] - public class UnitTest1 - { - static object[] services ; - - static UnitTest1() - { - services = new object[] { - new CalculatorService()}; - - } - - [TestMethod] - public void TestInProcessClient() - { - string request = @"{method:'NullableFloatToNullableFloat',params:[0.0],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":0.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void NullableDateTimeToNullableDateTime() - { - string request = @"{method:'NullableDateTimeToNullableDateTime',params:['2014-06-30T14:50:38.5208399+09:00'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"2014-06-30T14:50:38.5208399+09:00\",\"id\":1}"; - var expectedDate = DateTime.Parse("2014-06-30T14:50:38.5208399+09:00"); - var result = JsonRpcProcessor.Process(request); - result.Wait(); - var acutalDate = DateTime.Parse(result.Result.Substring(27, 33)); - Assert.AreEqual(expectedDate, acutalDate); - } - - [TestMethod] - public void NullableFloatToNullableFloat() - { - string request = @"{method:'NullableFloatToNullableFloat',params:[1.2345],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.2345,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void NullableFloatToNullableFloat3() - { - string request = @"{method:'NullableFloatToNullableFloat',params:[3.14159],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":3.14159,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - - [TestMethod] - public void NullableFloatToNullableFloat2() - { - string request = @"{method:'NullableFloatToNullableFloat',params:[null],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void DecimalToNullableDecimal() - { - string request = @"{method:'DecimalToNullableDecimal',params:[0.0],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":0.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void StringToListOfString() - { - string request = @"{method:'StringToListOfString',params:['some string'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"one\",\"two\",\"three\",\"some string\"],\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void CustomStringToListOfString() - { - string request = @"{method:'CustomStringToListOfString',params:[{str:'some string'}],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"one\",\"two\",\"three\",\"some string\"],\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void StringToThrowingException() - { - string request = @"{method:'StringToThrowingException',params:['some string'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32603,\"message\":\"Internal Error\",\"data\":"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsTrue(result.Result.StartsWith(expectedResult)); - } - - [TestMethod] - public void StringToRefException() - { - string request = @"{method:'StringToRefException',params:['some string'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-1,\"message\":\"refException worked\",\"data\":null},\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsTrue(result.Result.StartsWith(expectedResult)); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void StringToThrowJsonRpcException() - { - string request = @"{method:'StringToThrowJsonRpcException',params:['some string'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-27000,\"message\":\"Just some testing\""; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsTrue(result.Result.StartsWith(expectedResult)); - - } - - [TestMethod] - public void ReturnsDateTime() - { - string request = @"{method:'ReturnsDateTime',params:[],id:1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - } - - [TestMethod] - public void ReturnsCustomRecursiveClass() - { - string request = @"{method:'ReturnsCustomRecursiveClass',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":{\"Nested1\":{\"Nested1\":null,\"Value1\":5},\"Value1\":10},\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - - [TestMethod] - public void FloatToFloat() - { - string request = @"{method:'FloatToFloat',params:[0.123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":0.123,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - - [TestMethod] - public void IntToInt() - { - string request = @"{method:'IntToInt',params:[789],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void OptionalParamInt16() - { - string request = @"{method:'TestOptionalParamInt16',params:[789],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void OptionalParamInt16NoParam() - { - string request = @"{method:'TestOptionalParamInt16',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void Int16ToInt16() - { - string request = @"{method:'Int16ToInt16',params:[789],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void Int32ToInt32() - { - string request = @"{method:'Int32ToInt32',params:[789],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void Int64ToInt64() - { - string request = @"{method:'Int64ToInt64',params:[78915984515564],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":78915984515564,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - - [TestMethod] - public void TestOptionalParamByteMissing() - { - string request = @"{method:'TestOptionalParambyte',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamSbyteMissing() - { - string request = @"{method:'TestOptionalParamsbyte',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamShortMissing() - { - string request = @"{method:'TestOptionalParamshort',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamintMissing() - { - string request = @"{method:'TestOptionalParamint',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamLongMissing() - { - string request = @"{method:'TestOptionalParamlong',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUshortMissing() - { - string request = @"{method:'TestOptionalParamushort',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUintMissing() - { - string request = @"{method:'TestOptionalParamuint',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUlongMissing() - { - string request = @"{method:'TestOptionalParamulong',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamFloatMissing() - { - string request = @"{method:'TestOptionalParamfloat',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDoubleMissing() - { - string request = @"{method:'TestOptionalParamdouble',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamBoolMissing() - { - string request = @"{method:'TestOptionalParambool',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamCharMissing() - { - string request = @"{method:'TestOptionalParamchar',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"a\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDecimalMissing() - { - string request = @"{method:'TestOptionalParamdecimal',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestOptionalParamBytePresent() - { - string request = @"{method:'TestOptionalParambyte',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamSbytePresent() - { - string request = @"{method:'TestOptionalParamsbyte',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamShortPresent() - { - string request = @"{method:'TestOptionalParamshort',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamintPresent() - { - string request = @"{method:'TestOptionalParamint',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamLongPresent() - { - string request = @"{method:'TestOptionalParamlong',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUshortPresent() - { - string request = @"{method:'TestOptionalParamushort',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUintPresent() - { - string request = @"{method:'TestOptionalParamuint',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUlongPresent() - { - string request = @"{method:'TestOptionalParamulong',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamFloatPresent() - { - string request = @"{method:'TestOptionalParamfloat',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDoublePresent() - { - string request = @"{method:'TestOptionalParamdouble',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamBoolPresent() - { - string request = @"{method:'TestOptionalParambool',params:[false],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":false,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamCharPresent() - { - string request = @"{method:'TestOptionalParamchar',params:["+(int)'b'+"],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"b\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDecimalPresent() - { - string request = @"{method:'TestOptionalParamdecimal',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestOptionalParamBytePresentObjectSyntax() - { - string request = @"{method:'TestOptionalParambyte',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamSbytePresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamsbyte',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamShortPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamshort',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamintPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamint',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamLongPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamlong',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUshortPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamushort',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUintPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamuint',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUlongPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamulong',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamFloatPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamfloat',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDoublePresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamdouble',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamBoolPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParambool',params:{'input':false},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":false,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamCharPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamchar',params:{'input':"+(int)'c'+"},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"c\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDecimalPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamdecimal',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestOptionalParamByteMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParambyte',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamSbyteMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamsbyte',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamShortMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamshort',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamintMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamint',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamLongMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamlong',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUshortMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamushort',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUintMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamuint',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUlongMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamulong',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamFloatMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamfloat',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDoubleMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamdouble',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamBoolMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParambool',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamCharMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamchar',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"a\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDecimalMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamdecimal',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestOptionalParamByte_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParambyte_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":98,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamSbyte_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamsbyte_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":126,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamShort_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamshort_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamint_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamint_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamLong_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamlong_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUshort_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamushort_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUint_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamuint_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUlong_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamulong_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamFloat_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamfloat_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDouble_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamdouble_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamBool_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParambool_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamChar_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamchar_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDecimal_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamdecimal_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestOptionalParamByte_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParambyte_2x',params:{input1:123, input2: 67},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":67,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamByte_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParambyte_2x',params:[123, 67],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":67,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamByte_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParambyte_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":98,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamSbyte_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamsbyte_2x',params:{input1:123, input2: 97},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":97,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamSbyte_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamsbyte_2x',params:[123, 98],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":98,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamSbyte_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamsbyte_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":126,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamShort_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamshort_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamShort_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamshort_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamShort_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamshort_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamint_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamint_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamint_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamint_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamint_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamint_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamLong_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamlong_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamLong_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamlong_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamLong_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamlong_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUshort_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamushort_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUshort_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamushort_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUshort_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamushort_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUint_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamuint_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUint_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamuint_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUint_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamuint_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUlong_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamulong_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUlong_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamulong_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUlong_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamulong_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamFloat_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamfloat_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamFloat_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamfloat_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamFloat_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamfloat_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDouble_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamdouble_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDouble_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamdouble_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDouble_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamdouble_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamBool_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParambool_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamBool_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParambool_2x',params:[true, false],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":false,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamBool_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParambool_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamChar_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamchar_2x',params:{'input1':" + (int)'c' + ", 'input2':" + (int)'d' + "},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamChar_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamchar_2x',params:[" + (int)'c' + ", " + (int)'d' + "],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamChar_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamchar_2x',params:["+(int)'c'+"],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDecimal_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamdecimal_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDecimal_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamdecimal_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDecimal_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamdecimal_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestOptionalParametersStrings_BothMissing() - { - string request = @"{method:'TestOptionalParameters_Strings',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[null,null],\"id\":1}"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestOptionalParametersStrings_SecondMissing() - { - string request = @"{method:'TestOptionalParameters_Strings',params:['first'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"first\",null],\"id\":1}"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestOptionalParametersStrings_BothExists() - { - string request = @"{method:'TestOptionalParameters_Strings',params:['first','second'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"first\",\"second\"],\"id\":1}"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestOptionalParametersBoolsAndStrings() - { - string request = - "{\"jsonrpc\":\"2.0\",\"method\":\"TestOptionalParametersBoolsAndStrings\",\"params\":{\"input1\":\"murkel\"},\"Id\":1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestBatchResultWrongRequests() - { - string request = @"[{},{""jsonrpc"":""2.0"",""id"":4}]"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - - Assert.IsTrue(Regex.IsMatch(result.Result, @"\[(\{.*""error"":.*?,""id"":.*?\}),(\{.*""error"":.*?,""id"":.*?\})\]"), "Should have two errors."); - } - - [TestMethod] - public void TestBatchResultMultipleMethodCallsNotificationAtLast() - { - string request = - @"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}]"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - - Assert.IsFalse(result.Result.EndsWith(@",]"), "result.Result.EndsWith(@',]')"); - - } - - [TestMethod] - public void TestEmptyBatchResult() - { - var secondRequest = @"{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}"; - var result = JsonRpcProcessor.Process(secondRequest); - result.Wait(); - - Assert.IsTrue(string.IsNullOrEmpty(result.Result)); - } - - [TestMethod] - public void TestLeftOutParams() - { - var request = - @"{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""id"":1}"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - - Assert.IsFalse(result.Result.Contains(@"error"":{""code"":-32602"), @"According to JSON-RPC 2.0 the ""params"" member MAY be omitted."); - } - - [TestMethod] - public void TestMultipleResults() - { - var result = - JsonRpcProcessor.Process( - @"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]"); - result.Wait(); - - Assert.IsTrue(result.Result.EndsWith("]")); - } - - [TestMethod] - public void TestSingleResultBatch() - { - var result = - JsonRpcProcessor.Process(@"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]"); - result.Wait(); - Assert.IsFalse(result.Result.EndsWith("]")); - } - } -} - diff --git a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj new file mode 100644 index 0000000..ced277d --- /dev/null +++ b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj @@ -0,0 +1,50 @@ + + + + Debug + AnyCPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F} + Library + AustinHarris.JsonRpcTestN + AustinHarris.JsonRpcTestN + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + full + true + bin\Release + prompt + 4 + false + + + + + ..\packages\NUnit.2.6.3\lib\nunit.framework.dll + + + + + + + + + + + + + {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307} + AustinHarris.JsonRpc + + + \ No newline at end of file diff --git a/AustinHarris.JsonRpcTestN/Test.cs b/AustinHarris.JsonRpcTestN/Test.cs new file mode 100644 index 0000000..df5251c --- /dev/null +++ b/AustinHarris.JsonRpcTestN/Test.cs @@ -0,0 +1,1439 @@ +using NUnit.Framework; +using System; +using System.Linq; +using AustinHarris.JsonRpc; +using System.Text.RegularExpressions; + +namespace AustinHarris.JsonRpcTestN +{ + [TestFixture ()] + public class Test + { + [Test ()] + public void TestCase () + { + } + static object[] services; + + static Test() + { + services = new object[] { + new CalculatorService()}; + } + + [Test ()] + public void TestCanCreateAndRemoveSession() + { + var h = JsonRpc.Handler.GetSessionHandler ("this one"); + + h.Register ("workie", new Func(x => "workie ... " + x)); + + var metadata = new System.Collections.Generic.List> { + Tuple.Create ("sooper", typeof(string)), + Tuple.Create ("returns", typeof(string)) + }.ToDictionary(x=> x.Item1, x=> x.Item2); + h.MetaData.AddService("workie", metadata, new System.Collections.Generic.Dictionary()); + + string request = @"{method:'workie',params:{'sooper':'good'},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"workie ... good\",\"id\":1}"; + string expectedResultAfterDestroy = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"Method not found\",\"code\":-32601,\"data\":\"The method does not exist / is not available.\"},\"id\":1}"; + var result = JsonRpcProcessor.Process("this one", request); + result.Wait(); + + StringAssert.StartsWith(expectedResult, result.Result); + Assert.AreEqual(expectedResult, result.Result); + + h.Destroy (); + + var result2 = JsonRpcProcessor.Process("this one", request); + result2.Wait(); + + StringAssert.StartsWith(expectedResultAfterDestroy, result2.Result); + Assert.AreEqual(expectedResultAfterDestroy, result2.Result); + } + + [Test ()] + public void TestInProcessClient() + { + string request = @"{method:'NullableFloatToNullableFloat',params:[0.0],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":0.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void NullableDateTimeToNullableDateTime() + { + string request = @"{method:'NullableDateTimeToNullableDateTime',params:['2014-06-30T14:50:38.5208399+09:00'],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"2014-06-30T14:50:38.5208399+09:00\",\"id\":1}"; + var expectedDate = DateTime.Parse("2014-06-30T14:50:38.5208399+09:00"); + var result = JsonRpcProcessor.Process(request); + result.Wait(); + var acutalDate = DateTime.Parse(result.Result.Substring(27, 33)); + Assert.AreEqual(expectedDate, acutalDate); + } + + [Test ()] + public void NullableFloatToNullableFloat() + { + string request = @"{method:'NullableFloatToNullableFloat',params:[1.2345],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.2345,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void NullableFloatToNullableFloat3() + { + string request = @"{method:'NullableFloatToNullableFloat',params:[3.14159],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":3.14159,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + + [Test ()] + public void NullableFloatToNullableFloat2() + { + string request = @"{method:'NullableFloatToNullableFloat',params:[null],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void DecimalToNullableDecimal() + { + string request = @"{method:'DecimalToNullableDecimal',params:[0.0],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":0.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void StringToListOfString() + { + string request = @"{method:'StringToListOfString',params:['some string'],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"one\",\"two\",\"three\",\"some string\"],\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void CustomStringToListOfString() + { + string request = @"{method:'CustomStringToListOfString',params:[{str:'some string'}],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"one\",\"two\",\"three\",\"some string\"],\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void StringToThrowingException() + { + string request = @"{method:'StringToThrowingException',params:['some string'],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"Internal Error\",\"code\":-32603,\"data\":"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + StringAssert.StartsWith (expectedResult, result.Result); + } + + [Test ()] + public void StringToRefException() + { + string request = @"{method:'StringToRefException',params:['some string'],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"refException worked\",\"code\":-1,\"data\":null},\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + StringAssert.StartsWith (expectedResult, result.Result); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void StringToThrowJsonRpcException() + { + string request = @"{method:'StringToThrowJsonRpcException',params:['some string'],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"Just some testing\",\"code\":-27000,"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + StringAssert.StartsWith (expectedResult, result.Result); + } + + [Test ()] + public void ReturnsDateTime() + { + string request = @"{method:'ReturnsDateTime',params:[],id:1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + } + + [Test ()] + public void ReturnsCustomRecursiveClass() + { + string request = @"{method:'ReturnsCustomRecursiveClass',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":{\"Nested1\":{\"Nested1\":null,\"Value1\":5},\"Value1\":10},\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + + [Test ()] + public void FloatToFloat() + { + string request = @"{method:'FloatToFloat',params:[0.123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":0.123,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + + [Test ()] + public void IntToInt() + { + string request = @"{method:'IntToInt',params:[789],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void OptionalParamInt16() + { + string request = @"{method:'TestOptionalParamInt16',params:[789],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void OptionalParamInt16NoParam() + { + string request = @"{method:'TestOptionalParamInt16',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void Int16ToInt16() + { + string request = @"{method:'Int16ToInt16',params:[789],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void Int32ToInt32() + { + string request = @"{method:'Int32ToInt32',params:[789],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void Int64ToInt64() + { + string request = @"{method:'Int64ToInt64',params:[78915984515564],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":78915984515564,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + + [Test ()] + public void TestOptionalParamByteMissing() + { + string request = @"{method:'TestOptionalParambyte',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamSbyteMissing() + { + string request = @"{method:'TestOptionalParamsbyte',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamShortMissing() + { + string request = @"{method:'TestOptionalParamshort',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamintMissing() + { + string request = @"{method:'TestOptionalParamint',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamLongMissing() + { + string request = @"{method:'TestOptionalParamlong',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUshortMissing() + { + string request = @"{method:'TestOptionalParamushort',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUintMissing() + { + string request = @"{method:'TestOptionalParamuint',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUlongMissing() + { + string request = @"{method:'TestOptionalParamulong',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamFloatMissing() + { + string request = @"{method:'TestOptionalParamfloat',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDoubleMissing() + { + string request = @"{method:'TestOptionalParamdouble',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamBoolMissing() + { + string request = @"{method:'TestOptionalParambool',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamCharMissing() + { + string request = @"{method:'TestOptionalParamchar',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"a\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDecimalMissing() + { + string request = @"{method:'TestOptionalParamdecimal',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestOptionalParamBytePresent() + { + string request = @"{method:'TestOptionalParambyte',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamSbytePresent() + { + string request = @"{method:'TestOptionalParamsbyte',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamShortPresent() + { + string request = @"{method:'TestOptionalParamshort',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamintPresent() + { + string request = @"{method:'TestOptionalParamint',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamLongPresent() + { + string request = @"{method:'TestOptionalParamlong',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUshortPresent() + { + string request = @"{method:'TestOptionalParamushort',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUintPresent() + { + string request = @"{method:'TestOptionalParamuint',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUlongPresent() + { + string request = @"{method:'TestOptionalParamulong',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamFloatPresent() + { + string request = @"{method:'TestOptionalParamfloat',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDoublePresent() + { + string request = @"{method:'TestOptionalParamdouble',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamBoolPresent() + { + string request = @"{method:'TestOptionalParambool',params:[false],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":false,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamCharPresent() + { + string request = @"{method:'TestOptionalParamchar',params:["+(int)'b'+"],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"b\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDecimalPresent() + { + string request = @"{method:'TestOptionalParamdecimal',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestOptionalParamBytePresentObjectSyntax() + { + string request = @"{method:'TestOptionalParambyte',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamSbytePresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamsbyte',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamShortPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamshort',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamintPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamint',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamLongPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamlong',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUshortPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamushort',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUintPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamuint',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUlongPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamulong',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamFloatPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamfloat',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDoublePresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamdouble',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamBoolPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParambool',params:{'input':false},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":false,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamCharPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamchar',params:{'input':"+(int)'c'+"},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"c\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDecimalPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamdecimal',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestOptionalParamByteMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParambyte',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamSbyteMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamsbyte',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamShortMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamshort',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamintMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamint',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamLongMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamlong',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUshortMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamushort',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUintMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamuint',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUlongMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamulong',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamFloatMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamfloat',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDoubleMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamdouble',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamBoolMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParambool',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamCharMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamchar',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"a\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDecimalMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamdecimal',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestOptionalParamByte_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParambyte_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":98,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamSbyte_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamsbyte_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":126,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamShort_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamshort_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamint_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamint_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamLong_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamlong_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUshort_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamushort_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUint_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamuint_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUlong_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamulong_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamFloat_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamfloat_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDouble_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamdouble_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamBool_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParambool_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamChar_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamchar_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDecimal_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamdecimal_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestOptionalParamByte_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParambyte_2x',params:{input1:123, input2: 67},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":67,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamByte_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParambyte_2x',params:[123, 67],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":67,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamByte_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParambyte_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":98,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamSbyte_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamsbyte_2x',params:{input1:123, input2: 97},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":97,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamSbyte_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamsbyte_2x',params:[123, 98],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":98,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamSbyte_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamsbyte_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":126,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamShort_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamshort_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamShort_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamshort_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamShort_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamshort_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamint_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamint_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamint_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamint_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamint_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamint_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamLong_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamlong_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamLong_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamlong_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamLong_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamlong_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUshort_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamushort_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUshort_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamushort_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUshort_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamushort_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUint_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamuint_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUint_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamuint_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUint_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamuint_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUlong_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamulong_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUlong_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamulong_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUlong_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamulong_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamFloat_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamfloat_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamFloat_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamfloat_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamFloat_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamfloat_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDouble_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamdouble_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDouble_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamdouble_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDouble_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamdouble_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamBool_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParambool_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamBool_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParambool_2x',params:[true, false],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":false,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamBool_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParambool_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamChar_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamchar_2x',params:{'input1':" + (int)'c' + ", 'input2':" + (int)'d' + "},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamChar_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamchar_2x',params:[" + (int)'c' + ", " + (int)'d' + "],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamChar_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamchar_2x',params:["+(int)'c'+"],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDecimal_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamdecimal_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDecimal_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamdecimal_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDecimal_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamdecimal_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestOptionalParametersStrings_BothMissing() + { + string request = @"{method:'TestOptionalParameters_Strings',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[null,null],\"id\":1}"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestOptionalParametersStrings_SecondMissing() + { + string request = @"{method:'TestOptionalParameters_Strings',params:['first'],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"first\",null],\"id\":1}"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestOptionalParametersStrings_BothExists() + { + string request = @"{method:'TestOptionalParameters_Strings',params:['first','second'],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"first\",\"second\"],\"id\":1}"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestOptionalParametersBoolsAndStrings() + { + string request = + "{\"jsonrpc\":\"2.0\",\"method\":\"TestOptionalParametersBoolsAndStrings\",\"params\":{\"input1\":\"murkel\"},\"Id\":1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestBatchResultWrongRequests() + { + string request = @"[{},{""jsonrpc"":""2.0"",""id"":4}]"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + + Assert.IsTrue(Regex.IsMatch(result.Result, @"\[(\{.*""error"":.*?,""id"":.*?\}),(\{.*""error"":.*?,""id"":.*?\})\]"), "Should have two errors."); + } + + [Test ()] + public void TestBatchResultMultipleMethodCallsNotificationAtLast() + { + string request = + @"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}]"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + + Assert.IsFalse(result.Result.EndsWith(@",]"), "result.Result.EndsWith(@',]')"); + + } + + [Test ()] + public void TestEmptyBatchResult() + { + var secondRequest = @"{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}"; + var result = JsonRpcProcessor.Process(secondRequest); + result.Wait(); + + Assert.IsTrue(string.IsNullOrEmpty(result.Result)); + } + + [Test ()] + public void TestLeftOutParams() + { + var request = + @"{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""id"":1}"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + + Assert.IsFalse(result.Result.Contains(@"error"":{""code"":-32602"), @"According to JSON-RPC 2.0 the ""params"" member MAY be omitted."); + } + + [Test ()] + public void TestMultipleResults() + { + var result = + JsonRpcProcessor.Process( + @"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]"); + result.Wait(); + + Assert.IsTrue(result.Result.EndsWith("]")); + } + + [Test ()] + public void TestSingleResultBatch() + { + var result = + JsonRpcProcessor.Process(@"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]"); + result.Wait(); + Assert.IsFalse(result.Result.EndsWith("]")); + } + } +} + diff --git a/AustinHarris.JsonRpcTestN/packages.config b/AustinHarris.JsonRpcTestN/packages.config new file mode 100644 index 0000000..ad37a52 --- /dev/null +++ b/AustinHarris.JsonRpcTestN/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/AustinHarris.JsonRpcTest/service.cs b/AustinHarris.JsonRpcTestN/service.cs similarity index 98% rename from AustinHarris.JsonRpcTest/service.cs rename to AustinHarris.JsonRpcTestN/service.cs index fb81e70..ddbad98 100644 --- a/AustinHarris.JsonRpcTest/service.cs +++ b/AustinHarris.JsonRpcTestN/service.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; -namespace UnitTests +namespace AustinHarris.JsonRpcTestN { public class CalculatorService : JsonRpcService { @@ -43,7 +43,6 @@ private List StringToListOfString(string input) private List StringToThrowingException(string input) { throw new Exception("Throwing Exception"); - return new List() { "one", "two", "three", input }; } public class CustomString diff --git a/TestServer_Console/TestServer_Console.csproj b/TestServer_Console/TestServer_Console.csproj index 903dd05..32f9ca8 100644 --- a/TestServer_Console/TestServer_Console.csproj +++ b/TestServer_Console/TestServer_Console.csproj @@ -3,8 +3,6 @@ Debug x86 - 8.0.30703 - 2.0 {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B} Exe Properties @@ -40,16 +38,16 @@ AnyCPU bin\Debug\ + 4 + false AnyCPU bin\Release\ + 4 + false - - False - ..\packages\Newtonsoft.Json.6.0.3\lib\net40\Newtonsoft.Json.dll - @@ -57,6 +55,9 @@ + + ..\packages\Newtonsoft.Json.7.0.1\lib\net40\Newtonsoft.Json.dll + @@ -69,9 +70,6 @@ AustinHarris.JsonRpc - - - + + + \ No newline at end of file diff --git a/TestServer_Console/packages.config b/TestServer_Console/packages.config index 7106c62..4af203d 100644 --- a/TestServer_Console/packages.config +++ b/TestServer_Console/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file From 5f100e2b1f1daff66897f16231d62aff25956b79 Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Sat, 12 Sep 2015 01:49:06 -0600 Subject: [PATCH 25/81] switched to nunit for xamarin support. Updated to latest Json.Net. Added a unit test around removing a handler --- AustinHarris.JsonRpc.sln | 57 +- .../AustinHarris.JsonRpcTest.csproj | 105 -- .../Properties/AssemblyInfo.cs | 36 - AustinHarris.JsonRpcTest/UnitTest1.cs | 1407 ---------------- .../AustinHarris.JsonRpcTestN.csproj | 50 + AustinHarris.JsonRpcTestN/Test.cs | 1439 +++++++++++++++++ AustinHarris.JsonRpcTestN/packages.config | 4 + .../service.cs | 3 +- TestServer_Console/TestServer_Console.csproj | 19 +- TestServer_Console/packages.config | 2 +- 10 files changed, 1542 insertions(+), 1580 deletions(-) delete mode 100644 AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj delete mode 100644 AustinHarris.JsonRpcTest/Properties/AssemblyInfo.cs delete mode 100644 AustinHarris.JsonRpcTest/UnitTest1.cs create mode 100644 AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj create mode 100644 AustinHarris.JsonRpcTestN/Test.cs create mode 100644 AustinHarris.JsonRpcTestN/packages.config rename {AustinHarris.JsonRpcTest => AustinHarris.JsonRpcTestN}/service.cs (98%) diff --git a/AustinHarris.JsonRpc.sln b/AustinHarris.JsonRpc.sln index 4b0e5fc..3fa6f16 100644 --- a/AustinHarris.JsonRpc.sln +++ b/AustinHarris.JsonRpc.sln @@ -1,6 +1,6 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 +# Visual Studio 2012 VisualStudioVersion = 12.0.30723.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BBFBBA8A-2F75-422C-ACCD-D05A6EF7244C}" @@ -14,14 +14,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AustinHarris.JsonRpc", "Jso EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AustinHarris.JsonRpc.AspNet", "AustinHarris.JsonRpc.AspNet\AustinHarris.JsonRpc.AspNet.csproj", "{FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AustinHarris.JsonRpcTest", "AustinHarris.JsonRpcTest\AustinHarris.JsonRpcTest.csproj", "{0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AustinHarris.JsonRpcTestN", "AustinHarris.JsonRpcTestN\AustinHarris.JsonRpcTestN.csproj", "{8569B076-5A8B-4D6A-B75D-EF75A390AA5F}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{4811B06E-0A04-4CD4-9018-FE8295E8BF08}" - ProjectSection(SolutionItems) = preProject - .nuget\NuGet.Config = .nuget\NuGet.Config - .nuget\NuGet.exe = .nuget\NuGet.exe - .nuget\NuGet.targets = .nuget\NuGet.targets - EndProjectSection +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestServer_Console", "TestServer_Console\TestServer_Console.csproj", "{31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -49,6 +44,38 @@ Global {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|Mixed Platforms.Build.0 = Release|x86 {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|x86.ActiveCfg = Release|x86 {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|x86.Build.0 = Release|x86 + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|ARM.ActiveCfg = Debug|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|ARM.Build.0 = Debug|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|x86.ActiveCfg = Debug|x86 + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|x86.Build.0 = Debug|x86 + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|Any CPU.Build.0 = Release|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|ARM.ActiveCfg = Release|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|ARM.Build.0 = Release|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|x86.ActiveCfg = Release|x86 + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|x86.Build.0 = Release|x86 + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Debug|ARM.ActiveCfg = Debug|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Debug|ARM.Build.0 = Debug|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Debug|x86.ActiveCfg = Debug|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Debug|x86.Build.0 = Debug|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Release|Any CPU.Build.0 = Release|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Release|ARM.ActiveCfg = Release|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Release|ARM.Build.0 = Release|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Release|x86.ActiveCfg = Release|Any CPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Release|x86.Build.0 = Release|Any CPU {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Any CPU.Build.0 = Debug|Any CPU {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|ARM.ActiveCfg = Debug|Any CPU @@ -61,18 +88,8 @@ Global {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Mixed Platforms.Build.0 = Release|Any CPU {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|x86.ActiveCfg = Release|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|ARM.ActiveCfg = Debug|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Debug|x86.ActiveCfg = Debug|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|Any CPU.Build.0 = Release|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|ARM.ActiveCfg = Release|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD}.Release|x86.ActiveCfg = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj b/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj deleted file mode 100644 index d502129..0000000 --- a/AustinHarris.JsonRpcTest/AustinHarris.JsonRpcTest.csproj +++ /dev/null @@ -1,105 +0,0 @@ - - - - Debug - AnyCPU - {0A11B164-EA4A-41E7-BBE8-2CD19DB4C1AD} - Library - Properties - AustinHarris.JsonRpcTest - AustinHarris.JsonRpcTest - v4.0 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - ..\ - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - - - 3.5 - - - - - - - - - - - - - - - - - - - - - - {24fc1a2a-0bc3-43a7-9bfe-b628c2c4a307} - AustinHarris.JsonRpc - - - - - - - False - - - False - - - False - - - False - - - - - - - - - - Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Aktivieren Sie die Wiederherstellung von NuGet-Paketen, um die fehlende Datei herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". - - - - - \ No newline at end of file diff --git a/AustinHarris.JsonRpcTest/Properties/AssemblyInfo.cs b/AustinHarris.JsonRpcTest/Properties/AssemblyInfo.cs deleted file mode 100644 index 8fe95b7..0000000 --- a/AustinHarris.JsonRpcTest/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("AustinHarris.JsonRpcTest")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("AustinHarris.JsonRpcTest")] -[assembly: AssemblyCopyright("Copyright © 2014")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("45d95cf9-ddf4-4eda-add0-80f5222a2a38")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/AustinHarris.JsonRpcTest/UnitTest1.cs b/AustinHarris.JsonRpcTest/UnitTest1.cs deleted file mode 100644 index 6190f1c..0000000 --- a/AustinHarris.JsonRpcTest/UnitTest1.cs +++ /dev/null @@ -1,1407 +0,0 @@ -using System; -using System.Security.Cryptography.X509Certificates; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using AustinHarris.JsonRpc; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace UnitTests -{ - [TestClass] - public class UnitTest1 - { - static object[] services ; - - static UnitTest1() - { - services = new object[] { - new CalculatorService()}; - - } - - [TestMethod] - public void TestInProcessClient() - { - string request = @"{method:'NullableFloatToNullableFloat',params:[0.0],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":0.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void NullableDateTimeToNullableDateTime() - { - string request = @"{method:'NullableDateTimeToNullableDateTime',params:['2014-06-30T14:50:38.5208399+09:00'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"2014-06-30T14:50:38.5208399+09:00\",\"id\":1}"; - var expectedDate = DateTime.Parse("2014-06-30T14:50:38.5208399+09:00"); - var result = JsonRpcProcessor.Process(request); - result.Wait(); - var acutalDate = DateTime.Parse(result.Result.Substring(27, 33)); - Assert.AreEqual(expectedDate, acutalDate); - } - - [TestMethod] - public void NullableFloatToNullableFloat() - { - string request = @"{method:'NullableFloatToNullableFloat',params:[1.2345],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.2345,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void NullableFloatToNullableFloat3() - { - string request = @"{method:'NullableFloatToNullableFloat',params:[3.14159],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":3.14159,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - - [TestMethod] - public void NullableFloatToNullableFloat2() - { - string request = @"{method:'NullableFloatToNullableFloat',params:[null],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void DecimalToNullableDecimal() - { - string request = @"{method:'DecimalToNullableDecimal',params:[0.0],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":0.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void StringToListOfString() - { - string request = @"{method:'StringToListOfString',params:['some string'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"one\",\"two\",\"three\",\"some string\"],\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void CustomStringToListOfString() - { - string request = @"{method:'CustomStringToListOfString',params:[{str:'some string'}],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"one\",\"two\",\"three\",\"some string\"],\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void StringToThrowingException() - { - string request = @"{method:'StringToThrowingException',params:['some string'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32603,\"message\":\"Internal Error\",\"data\":"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsTrue(result.Result.StartsWith(expectedResult)); - } - - [TestMethod] - public void StringToRefException() - { - string request = @"{method:'StringToRefException',params:['some string'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-1,\"message\":\"refException worked\",\"data\":null},\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsTrue(result.Result.StartsWith(expectedResult)); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void StringToThrowJsonRpcException() - { - string request = @"{method:'StringToThrowJsonRpcException',params:['some string'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-27000,\"message\":\"Just some testing\""; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsTrue(result.Result.StartsWith(expectedResult)); - - } - - [TestMethod] - public void ReturnsDateTime() - { - string request = @"{method:'ReturnsDateTime',params:[],id:1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - } - - [TestMethod] - public void ReturnsCustomRecursiveClass() - { - string request = @"{method:'ReturnsCustomRecursiveClass',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":{\"Nested1\":{\"Nested1\":null,\"Value1\":5},\"Value1\":10},\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - - [TestMethod] - public void FloatToFloat() - { - string request = @"{method:'FloatToFloat',params:[0.123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":0.123,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - - [TestMethod] - public void IntToInt() - { - string request = @"{method:'IntToInt',params:[789],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void OptionalParamInt16() - { - string request = @"{method:'TestOptionalParamInt16',params:[789],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void OptionalParamInt16NoParam() - { - string request = @"{method:'TestOptionalParamInt16',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void Int16ToInt16() - { - string request = @"{method:'Int16ToInt16',params:[789],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void Int32ToInt32() - { - string request = @"{method:'Int32ToInt32',params:[789],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void Int64ToInt64() - { - string request = @"{method:'Int64ToInt64',params:[78915984515564],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":78915984515564,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - - [TestMethod] - public void TestOptionalParamByteMissing() - { - string request = @"{method:'TestOptionalParambyte',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamSbyteMissing() - { - string request = @"{method:'TestOptionalParamsbyte',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamShortMissing() - { - string request = @"{method:'TestOptionalParamshort',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamintMissing() - { - string request = @"{method:'TestOptionalParamint',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamLongMissing() - { - string request = @"{method:'TestOptionalParamlong',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUshortMissing() - { - string request = @"{method:'TestOptionalParamushort',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUintMissing() - { - string request = @"{method:'TestOptionalParamuint',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUlongMissing() - { - string request = @"{method:'TestOptionalParamulong',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamFloatMissing() - { - string request = @"{method:'TestOptionalParamfloat',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDoubleMissing() - { - string request = @"{method:'TestOptionalParamdouble',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamBoolMissing() - { - string request = @"{method:'TestOptionalParambool',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamCharMissing() - { - string request = @"{method:'TestOptionalParamchar',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"a\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDecimalMissing() - { - string request = @"{method:'TestOptionalParamdecimal',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestOptionalParamBytePresent() - { - string request = @"{method:'TestOptionalParambyte',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamSbytePresent() - { - string request = @"{method:'TestOptionalParamsbyte',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamShortPresent() - { - string request = @"{method:'TestOptionalParamshort',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamintPresent() - { - string request = @"{method:'TestOptionalParamint',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamLongPresent() - { - string request = @"{method:'TestOptionalParamlong',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUshortPresent() - { - string request = @"{method:'TestOptionalParamushort',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUintPresent() - { - string request = @"{method:'TestOptionalParamuint',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUlongPresent() - { - string request = @"{method:'TestOptionalParamulong',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamFloatPresent() - { - string request = @"{method:'TestOptionalParamfloat',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDoublePresent() - { - string request = @"{method:'TestOptionalParamdouble',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamBoolPresent() - { - string request = @"{method:'TestOptionalParambool',params:[false],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":false,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamCharPresent() - { - string request = @"{method:'TestOptionalParamchar',params:["+(int)'b'+"],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"b\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDecimalPresent() - { - string request = @"{method:'TestOptionalParamdecimal',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestOptionalParamBytePresentObjectSyntax() - { - string request = @"{method:'TestOptionalParambyte',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamSbytePresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamsbyte',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamShortPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamshort',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamintPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamint',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamLongPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamlong',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUshortPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamushort',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUintPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamuint',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUlongPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamulong',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamFloatPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamfloat',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDoublePresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamdouble',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamBoolPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParambool',params:{'input':false},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":false,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamCharPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamchar',params:{'input':"+(int)'c'+"},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"c\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDecimalPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamdecimal',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestOptionalParamByteMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParambyte',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamSbyteMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamsbyte',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamShortMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamshort',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamintMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamint',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamLongMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamlong',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUshortMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamushort',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUintMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamuint',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUlongMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamulong',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamFloatMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamfloat',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDoubleMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamdouble',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamBoolMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParambool',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamCharMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamchar',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"a\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDecimalMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamdecimal',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestOptionalParamByte_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParambyte_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":98,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamSbyte_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamsbyte_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":126,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamShort_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamshort_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamint_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamint_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamLong_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamlong_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUshort_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamushort_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUint_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamuint_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUlong_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamulong_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamFloat_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamfloat_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDouble_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamdouble_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamBool_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParambool_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamChar_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamchar_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDecimal_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamdecimal_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestOptionalParamByte_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParambyte_2x',params:{input1:123, input2: 67},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":67,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamByte_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParambyte_2x',params:[123, 67],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":67,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamByte_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParambyte_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":98,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamSbyte_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamsbyte_2x',params:{input1:123, input2: 97},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":97,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamSbyte_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamsbyte_2x',params:[123, 98],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":98,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamSbyte_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamsbyte_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":126,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamShort_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamshort_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamShort_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamshort_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamShort_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamshort_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamint_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamint_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamint_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamint_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamint_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamint_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamLong_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamlong_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamLong_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamlong_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamLong_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamlong_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUshort_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamushort_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUshort_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamushort_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUshort_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamushort_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUint_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamuint_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUint_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamuint_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUint_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamuint_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUlong_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamulong_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUlong_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamulong_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamUlong_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamulong_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamFloat_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamfloat_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamFloat_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamfloat_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamFloat_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamfloat_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDouble_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamdouble_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDouble_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamdouble_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDouble_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamdouble_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamBool_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParambool_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamBool_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParambool_2x',params:[true, false],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":false,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamBool_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParambool_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamChar_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamchar_2x',params:{'input1':" + (int)'c' + ", 'input2':" + (int)'d' + "},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamChar_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamchar_2x',params:[" + (int)'c' + ", " + (int)'d' + "],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamChar_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamchar_2x',params:["+(int)'c'+"],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDecimal_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamdecimal_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDecimal_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamdecimal_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [TestMethod] - public void TestOptionalParamDecimal_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamdecimal_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestOptionalParametersStrings_BothMissing() - { - string request = @"{method:'TestOptionalParameters_Strings',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[null,null],\"id\":1}"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestOptionalParametersStrings_SecondMissing() - { - string request = @"{method:'TestOptionalParameters_Strings',params:['first'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"first\",null],\"id\":1}"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestOptionalParametersStrings_BothExists() - { - string request = @"{method:'TestOptionalParameters_Strings',params:['first','second'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"first\",\"second\"],\"id\":1}"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestOptionalParametersBoolsAndStrings() - { - string request = - "{\"jsonrpc\":\"2.0\",\"method\":\"TestOptionalParametersBoolsAndStrings\",\"params\":{\"input1\":\"murkel\"},\"Id\":1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [TestMethod] - public void TestBatchResultWrongRequests() - { - string request = @"[{},{""jsonrpc"":""2.0"",""id"":4}]"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - - Assert.IsTrue(Regex.IsMatch(result.Result, @"\[(\{.*""error"":.*?,""id"":.*?\}),(\{.*""error"":.*?,""id"":.*?\})\]"), "Should have two errors."); - } - - [TestMethod] - public void TestBatchResultMultipleMethodCallsNotificationAtLast() - { - string request = - @"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}]"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - - Assert.IsFalse(result.Result.EndsWith(@",]"), "result.Result.EndsWith(@',]')"); - - } - - [TestMethod] - public void TestEmptyBatchResult() - { - var secondRequest = @"{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}"; - var result = JsonRpcProcessor.Process(secondRequest); - result.Wait(); - - Assert.IsTrue(string.IsNullOrEmpty(result.Result)); - } - - [TestMethod] - public void TestLeftOutParams() - { - var request = - @"{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""id"":1}"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - - Assert.IsFalse(result.Result.Contains(@"error"":{""code"":-32602"), @"According to JSON-RPC 2.0 the ""params"" member MAY be omitted."); - } - - [TestMethod] - public void TestMultipleResults() - { - var result = - JsonRpcProcessor.Process( - @"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]"); - result.Wait(); - - Assert.IsTrue(result.Result.EndsWith("]")); - } - - [TestMethod] - public void TestSingleResultBatch() - { - var result = - JsonRpcProcessor.Process(@"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]"); - result.Wait(); - Assert.IsFalse(result.Result.EndsWith("]")); - } - } -} - diff --git a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj new file mode 100644 index 0000000..ced277d --- /dev/null +++ b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj @@ -0,0 +1,50 @@ + + + + Debug + AnyCPU + {8569B076-5A8B-4D6A-B75D-EF75A390AA5F} + Library + AustinHarris.JsonRpcTestN + AustinHarris.JsonRpcTestN + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + full + true + bin\Release + prompt + 4 + false + + + + + ..\packages\NUnit.2.6.3\lib\nunit.framework.dll + + + + + + + + + + + + + {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307} + AustinHarris.JsonRpc + + + \ No newline at end of file diff --git a/AustinHarris.JsonRpcTestN/Test.cs b/AustinHarris.JsonRpcTestN/Test.cs new file mode 100644 index 0000000..df5251c --- /dev/null +++ b/AustinHarris.JsonRpcTestN/Test.cs @@ -0,0 +1,1439 @@ +using NUnit.Framework; +using System; +using System.Linq; +using AustinHarris.JsonRpc; +using System.Text.RegularExpressions; + +namespace AustinHarris.JsonRpcTestN +{ + [TestFixture ()] + public class Test + { + [Test ()] + public void TestCase () + { + } + static object[] services; + + static Test() + { + services = new object[] { + new CalculatorService()}; + } + + [Test ()] + public void TestCanCreateAndRemoveSession() + { + var h = JsonRpc.Handler.GetSessionHandler ("this one"); + + h.Register ("workie", new Func(x => "workie ... " + x)); + + var metadata = new System.Collections.Generic.List> { + Tuple.Create ("sooper", typeof(string)), + Tuple.Create ("returns", typeof(string)) + }.ToDictionary(x=> x.Item1, x=> x.Item2); + h.MetaData.AddService("workie", metadata, new System.Collections.Generic.Dictionary()); + + string request = @"{method:'workie',params:{'sooper':'good'},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"workie ... good\",\"id\":1}"; + string expectedResultAfterDestroy = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"Method not found\",\"code\":-32601,\"data\":\"The method does not exist / is not available.\"},\"id\":1}"; + var result = JsonRpcProcessor.Process("this one", request); + result.Wait(); + + StringAssert.StartsWith(expectedResult, result.Result); + Assert.AreEqual(expectedResult, result.Result); + + h.Destroy (); + + var result2 = JsonRpcProcessor.Process("this one", request); + result2.Wait(); + + StringAssert.StartsWith(expectedResultAfterDestroy, result2.Result); + Assert.AreEqual(expectedResultAfterDestroy, result2.Result); + } + + [Test ()] + public void TestInProcessClient() + { + string request = @"{method:'NullableFloatToNullableFloat',params:[0.0],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":0.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void NullableDateTimeToNullableDateTime() + { + string request = @"{method:'NullableDateTimeToNullableDateTime',params:['2014-06-30T14:50:38.5208399+09:00'],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"2014-06-30T14:50:38.5208399+09:00\",\"id\":1}"; + var expectedDate = DateTime.Parse("2014-06-30T14:50:38.5208399+09:00"); + var result = JsonRpcProcessor.Process(request); + result.Wait(); + var acutalDate = DateTime.Parse(result.Result.Substring(27, 33)); + Assert.AreEqual(expectedDate, acutalDate); + } + + [Test ()] + public void NullableFloatToNullableFloat() + { + string request = @"{method:'NullableFloatToNullableFloat',params:[1.2345],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.2345,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void NullableFloatToNullableFloat3() + { + string request = @"{method:'NullableFloatToNullableFloat',params:[3.14159],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":3.14159,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + + [Test ()] + public void NullableFloatToNullableFloat2() + { + string request = @"{method:'NullableFloatToNullableFloat',params:[null],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void DecimalToNullableDecimal() + { + string request = @"{method:'DecimalToNullableDecimal',params:[0.0],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":0.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void StringToListOfString() + { + string request = @"{method:'StringToListOfString',params:['some string'],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"one\",\"two\",\"three\",\"some string\"],\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void CustomStringToListOfString() + { + string request = @"{method:'CustomStringToListOfString',params:[{str:'some string'}],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"one\",\"two\",\"three\",\"some string\"],\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void StringToThrowingException() + { + string request = @"{method:'StringToThrowingException',params:['some string'],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"Internal Error\",\"code\":-32603,\"data\":"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + StringAssert.StartsWith (expectedResult, result.Result); + } + + [Test ()] + public void StringToRefException() + { + string request = @"{method:'StringToRefException',params:['some string'],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"refException worked\",\"code\":-1,\"data\":null},\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + StringAssert.StartsWith (expectedResult, result.Result); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void StringToThrowJsonRpcException() + { + string request = @"{method:'StringToThrowJsonRpcException',params:['some string'],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"Just some testing\",\"code\":-27000,"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + StringAssert.StartsWith (expectedResult, result.Result); + } + + [Test ()] + public void ReturnsDateTime() + { + string request = @"{method:'ReturnsDateTime',params:[],id:1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + } + + [Test ()] + public void ReturnsCustomRecursiveClass() + { + string request = @"{method:'ReturnsCustomRecursiveClass',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":{\"Nested1\":{\"Nested1\":null,\"Value1\":5},\"Value1\":10},\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + + [Test ()] + public void FloatToFloat() + { + string request = @"{method:'FloatToFloat',params:[0.123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":0.123,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + + [Test ()] + public void IntToInt() + { + string request = @"{method:'IntToInt',params:[789],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void OptionalParamInt16() + { + string request = @"{method:'TestOptionalParamInt16',params:[789],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void OptionalParamInt16NoParam() + { + string request = @"{method:'TestOptionalParamInt16',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void Int16ToInt16() + { + string request = @"{method:'Int16ToInt16',params:[789],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void Int32ToInt32() + { + string request = @"{method:'Int32ToInt32',params:[789],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void Int64ToInt64() + { + string request = @"{method:'Int64ToInt64',params:[78915984515564],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":78915984515564,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + + [Test ()] + public void TestOptionalParamByteMissing() + { + string request = @"{method:'TestOptionalParambyte',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamSbyteMissing() + { + string request = @"{method:'TestOptionalParamsbyte',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamShortMissing() + { + string request = @"{method:'TestOptionalParamshort',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamintMissing() + { + string request = @"{method:'TestOptionalParamint',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamLongMissing() + { + string request = @"{method:'TestOptionalParamlong',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUshortMissing() + { + string request = @"{method:'TestOptionalParamushort',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUintMissing() + { + string request = @"{method:'TestOptionalParamuint',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUlongMissing() + { + string request = @"{method:'TestOptionalParamulong',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamFloatMissing() + { + string request = @"{method:'TestOptionalParamfloat',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDoubleMissing() + { + string request = @"{method:'TestOptionalParamdouble',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamBoolMissing() + { + string request = @"{method:'TestOptionalParambool',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamCharMissing() + { + string request = @"{method:'TestOptionalParamchar',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"a\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDecimalMissing() + { + string request = @"{method:'TestOptionalParamdecimal',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestOptionalParamBytePresent() + { + string request = @"{method:'TestOptionalParambyte',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamSbytePresent() + { + string request = @"{method:'TestOptionalParamsbyte',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamShortPresent() + { + string request = @"{method:'TestOptionalParamshort',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamintPresent() + { + string request = @"{method:'TestOptionalParamint',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamLongPresent() + { + string request = @"{method:'TestOptionalParamlong',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUshortPresent() + { + string request = @"{method:'TestOptionalParamushort',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUintPresent() + { + string request = @"{method:'TestOptionalParamuint',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUlongPresent() + { + string request = @"{method:'TestOptionalParamulong',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamFloatPresent() + { + string request = @"{method:'TestOptionalParamfloat',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDoublePresent() + { + string request = @"{method:'TestOptionalParamdouble',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamBoolPresent() + { + string request = @"{method:'TestOptionalParambool',params:[false],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":false,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamCharPresent() + { + string request = @"{method:'TestOptionalParamchar',params:["+(int)'b'+"],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"b\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDecimalPresent() + { + string request = @"{method:'TestOptionalParamdecimal',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestOptionalParamBytePresentObjectSyntax() + { + string request = @"{method:'TestOptionalParambyte',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamSbytePresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamsbyte',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamShortPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamshort',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamintPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamint',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamLongPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamlong',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUshortPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamushort',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUintPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamuint',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUlongPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamulong',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamFloatPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamfloat',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDoublePresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamdouble',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamBoolPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParambool',params:{'input':false},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":false,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamCharPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamchar',params:{'input':"+(int)'c'+"},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"c\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDecimalPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamdecimal',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestOptionalParamByteMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParambyte',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamSbyteMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamsbyte',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamShortMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamshort',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamintMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamint',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamLongMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamlong',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUshortMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamushort',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUintMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamuint',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUlongMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamulong',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamFloatMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamfloat',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDoubleMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamdouble',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamBoolMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParambool',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamCharMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamchar',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"a\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDecimalMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamdecimal',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestOptionalParamByte_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParambyte_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":98,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamSbyte_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamsbyte_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":126,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamShort_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamshort_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamint_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamint_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamLong_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamlong_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUshort_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamushort_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUint_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamuint_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUlong_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamulong_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamFloat_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamfloat_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDouble_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamdouble_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamBool_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParambool_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamChar_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamchar_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDecimal_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamdecimal_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestOptionalParamByte_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParambyte_2x',params:{input1:123, input2: 67},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":67,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamByte_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParambyte_2x',params:[123, 67],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":67,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamByte_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParambyte_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":98,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamSbyte_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamsbyte_2x',params:{input1:123, input2: 97},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":97,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamSbyte_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamsbyte_2x',params:[123, 98],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":98,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamSbyte_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamsbyte_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":126,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamShort_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamshort_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamShort_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamshort_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamShort_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamshort_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamint_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamint_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamint_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamint_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamint_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamint_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamLong_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamlong_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamLong_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamlong_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamLong_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamlong_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUshort_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamushort_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUshort_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamushort_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUshort_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamushort_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUint_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamuint_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUint_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamuint_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUint_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamuint_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUlong_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamulong_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUlong_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamulong_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamUlong_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamulong_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamFloat_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamfloat_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamFloat_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamfloat_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamFloat_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamfloat_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDouble_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamdouble_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDouble_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamdouble_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDouble_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamdouble_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamBool_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParambool_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamBool_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParambool_2x',params:[true, false],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":false,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamBool_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParambool_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamChar_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamchar_2x',params:{'input1':" + (int)'c' + ", 'input2':" + (int)'d' + "},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamChar_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamchar_2x',params:[" + (int)'c' + ", " + (int)'d' + "],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamChar_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamchar_2x',params:["+(int)'c'+"],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDecimal_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamdecimal_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDecimal_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamdecimal_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test ()] + public void TestOptionalParamDecimal_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamdecimal_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestOptionalParametersStrings_BothMissing() + { + string request = @"{method:'TestOptionalParameters_Strings',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[null,null],\"id\":1}"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestOptionalParametersStrings_SecondMissing() + { + string request = @"{method:'TestOptionalParameters_Strings',params:['first'],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"first\",null],\"id\":1}"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestOptionalParametersStrings_BothExists() + { + string request = @"{method:'TestOptionalParameters_Strings',params:['first','second'],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"first\",\"second\"],\"id\":1}"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestOptionalParametersBoolsAndStrings() + { + string request = + "{\"jsonrpc\":\"2.0\",\"method\":\"TestOptionalParametersBoolsAndStrings\",\"params\":{\"input1\":\"murkel\"},\"Id\":1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test ()] + public void TestBatchResultWrongRequests() + { + string request = @"[{},{""jsonrpc"":""2.0"",""id"":4}]"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + + Assert.IsTrue(Regex.IsMatch(result.Result, @"\[(\{.*""error"":.*?,""id"":.*?\}),(\{.*""error"":.*?,""id"":.*?\})\]"), "Should have two errors."); + } + + [Test ()] + public void TestBatchResultMultipleMethodCallsNotificationAtLast() + { + string request = + @"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}]"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + + Assert.IsFalse(result.Result.EndsWith(@",]"), "result.Result.EndsWith(@',]')"); + + } + + [Test ()] + public void TestEmptyBatchResult() + { + var secondRequest = @"{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}"; + var result = JsonRpcProcessor.Process(secondRequest); + result.Wait(); + + Assert.IsTrue(string.IsNullOrEmpty(result.Result)); + } + + [Test ()] + public void TestLeftOutParams() + { + var request = + @"{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""id"":1}"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + + Assert.IsFalse(result.Result.Contains(@"error"":{""code"":-32602"), @"According to JSON-RPC 2.0 the ""params"" member MAY be omitted."); + } + + [Test ()] + public void TestMultipleResults() + { + var result = + JsonRpcProcessor.Process( + @"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]"); + result.Wait(); + + Assert.IsTrue(result.Result.EndsWith("]")); + } + + [Test ()] + public void TestSingleResultBatch() + { + var result = + JsonRpcProcessor.Process(@"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]"); + result.Wait(); + Assert.IsFalse(result.Result.EndsWith("]")); + } + } +} + diff --git a/AustinHarris.JsonRpcTestN/packages.config b/AustinHarris.JsonRpcTestN/packages.config new file mode 100644 index 0000000..ad37a52 --- /dev/null +++ b/AustinHarris.JsonRpcTestN/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/AustinHarris.JsonRpcTest/service.cs b/AustinHarris.JsonRpcTestN/service.cs similarity index 98% rename from AustinHarris.JsonRpcTest/service.cs rename to AustinHarris.JsonRpcTestN/service.cs index fb81e70..ddbad98 100644 --- a/AustinHarris.JsonRpcTest/service.cs +++ b/AustinHarris.JsonRpcTestN/service.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; -namespace UnitTests +namespace AustinHarris.JsonRpcTestN { public class CalculatorService : JsonRpcService { @@ -43,7 +43,6 @@ private List StringToListOfString(string input) private List StringToThrowingException(string input) { throw new Exception("Throwing Exception"); - return new List() { "one", "two", "three", input }; } public class CustomString diff --git a/TestServer_Console/TestServer_Console.csproj b/TestServer_Console/TestServer_Console.csproj index 903dd05..32f9ca8 100644 --- a/TestServer_Console/TestServer_Console.csproj +++ b/TestServer_Console/TestServer_Console.csproj @@ -3,8 +3,6 @@ Debug x86 - 8.0.30703 - 2.0 {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B} Exe Properties @@ -40,16 +38,16 @@ AnyCPU bin\Debug\ + 4 + false AnyCPU bin\Release\ + 4 + false - - False - ..\packages\Newtonsoft.Json.6.0.3\lib\net40\Newtonsoft.Json.dll - @@ -57,6 +55,9 @@ + + ..\packages\Newtonsoft.Json.7.0.1\lib\net40\Newtonsoft.Json.dll + @@ -69,9 +70,6 @@ AustinHarris.JsonRpc - - - + + + \ No newline at end of file diff --git a/TestServer_Console/packages.config b/TestServer_Console/packages.config index 7106c62..4af203d 100644 --- a/TestServer_Console/packages.config +++ b/TestServer_Console/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file From eddc17105286c010cf040b64642084b47499b7ef Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Sat, 12 Sep 2015 02:17:57 -0600 Subject: [PATCH 26/81] attempt to get more consistant test results on multiple platforms ie: myget --- .../AustinHarris.JsonRpcTestN.csproj | 3 +++ AustinHarris.JsonRpcTestN/Test.cs | 16 ++++++++-------- AustinHarris.JsonRpcTestN/packages.config | 1 + 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj index ced277d..799174b 100644 --- a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj +++ b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj @@ -32,6 +32,9 @@ ..\packages\NUnit.2.6.3\lib\nunit.framework.dll + + ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + diff --git a/AustinHarris.JsonRpcTestN/Test.cs b/AustinHarris.JsonRpcTestN/Test.cs index df5251c..12989f1 100644 --- a/AustinHarris.JsonRpcTestN/Test.cs +++ b/AustinHarris.JsonRpcTestN/Test.cs @@ -3,6 +3,7 @@ using System.Linq; using AustinHarris.JsonRpc; using System.Text.RegularExpressions; +using Newtonsoft.Json.Linq; namespace AustinHarris.JsonRpcTestN { @@ -40,16 +41,17 @@ public void TestCanCreateAndRemoveSession() var result = JsonRpcProcessor.Process("this one", request); result.Wait(); - StringAssert.StartsWith(expectedResult, result.Result); - Assert.AreEqual(expectedResult, result.Result); + + var actual1 = JObject.Parse (result.Result); + var expected1 = JObject.Parse (expectedResult); + Assert.AreEqual(expected1, actual1); h.Destroy (); var result2 = JsonRpcProcessor.Process("this one", request); result2.Wait(); - StringAssert.StartsWith(expectedResultAfterDestroy, result2.Result); - Assert.AreEqual(expectedResultAfterDestroy, result2.Result); + Assert.AreEqual(JObject.Parse(expectedResultAfterDestroy), JObject.Parse(result2.Result)); } [Test ()] @@ -147,10 +149,9 @@ public void CustomStringToListOfString() public void StringToThrowingException() { string request = @"{method:'StringToThrowingException',params:['some string'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"Internal Error\",\"code\":-32603,\"data\":"; var result = JsonRpcProcessor.Process(request); result.Wait(); - StringAssert.StartsWith (expectedResult, result.Result); + StringAssert.Contains ("-32603", result.Result); } [Test ()] @@ -160,8 +161,7 @@ public void StringToRefException() string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"refException worked\",\"code\":-1,\"data\":null},\"id\":1}"; var result = JsonRpcProcessor.Process(request); result.Wait(); - StringAssert.StartsWith (expectedResult, result.Result); - Assert.AreEqual(expectedResult, result.Result); + Assert.AreEqual(JObject.Parse(expectedResult),JObject.Parse( result.Result)); } [Test ()] diff --git a/AustinHarris.JsonRpcTestN/packages.config b/AustinHarris.JsonRpcTestN/packages.config index ad37a52..ef51508 100644 --- a/AustinHarris.JsonRpcTestN/packages.config +++ b/AustinHarris.JsonRpcTestN/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file From c31e073e442865a02f6cc40d7eb83eb4bf2facd3 Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Sat, 12 Sep 2015 02:17:57 -0600 Subject: [PATCH 27/81] attempt to get more consistant test results on multiple platforms ie: myget --- .../AustinHarris.JsonRpcTestN.csproj | 3 +++ AustinHarris.JsonRpcTestN/Test.cs | 16 ++++++++-------- AustinHarris.JsonRpcTestN/packages.config | 1 + 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj index ced277d..799174b 100644 --- a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj +++ b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj @@ -32,6 +32,9 @@ ..\packages\NUnit.2.6.3\lib\nunit.framework.dll + + ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + diff --git a/AustinHarris.JsonRpcTestN/Test.cs b/AustinHarris.JsonRpcTestN/Test.cs index df5251c..12989f1 100644 --- a/AustinHarris.JsonRpcTestN/Test.cs +++ b/AustinHarris.JsonRpcTestN/Test.cs @@ -3,6 +3,7 @@ using System.Linq; using AustinHarris.JsonRpc; using System.Text.RegularExpressions; +using Newtonsoft.Json.Linq; namespace AustinHarris.JsonRpcTestN { @@ -40,16 +41,17 @@ public void TestCanCreateAndRemoveSession() var result = JsonRpcProcessor.Process("this one", request); result.Wait(); - StringAssert.StartsWith(expectedResult, result.Result); - Assert.AreEqual(expectedResult, result.Result); + + var actual1 = JObject.Parse (result.Result); + var expected1 = JObject.Parse (expectedResult); + Assert.AreEqual(expected1, actual1); h.Destroy (); var result2 = JsonRpcProcessor.Process("this one", request); result2.Wait(); - StringAssert.StartsWith(expectedResultAfterDestroy, result2.Result); - Assert.AreEqual(expectedResultAfterDestroy, result2.Result); + Assert.AreEqual(JObject.Parse(expectedResultAfterDestroy), JObject.Parse(result2.Result)); } [Test ()] @@ -147,10 +149,9 @@ public void CustomStringToListOfString() public void StringToThrowingException() { string request = @"{method:'StringToThrowingException',params:['some string'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"Internal Error\",\"code\":-32603,\"data\":"; var result = JsonRpcProcessor.Process(request); result.Wait(); - StringAssert.StartsWith (expectedResult, result.Result); + StringAssert.Contains ("-32603", result.Result); } [Test ()] @@ -160,8 +161,7 @@ public void StringToRefException() string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"refException worked\",\"code\":-1,\"data\":null},\"id\":1}"; var result = JsonRpcProcessor.Process(request); result.Wait(); - StringAssert.StartsWith (expectedResult, result.Result); - Assert.AreEqual(expectedResult, result.Result); + Assert.AreEqual(JObject.Parse(expectedResult),JObject.Parse( result.Result)); } [Test ()] diff --git a/AustinHarris.JsonRpcTestN/packages.config b/AustinHarris.JsonRpcTestN/packages.config index ad37a52..ef51508 100644 --- a/AustinHarris.JsonRpcTestN/packages.config +++ b/AustinHarris.JsonRpcTestN/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file From 4ad9d1eb03bf07f61e7e8f8b521129c3983f93a4 Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Sat, 12 Sep 2015 02:21:50 -0600 Subject: [PATCH 28/81] nuget targets --- .nuget/NuGet.targets | 62 +++----------------------------------------- 1 file changed, 4 insertions(+), 58 deletions(-) diff --git a/.nuget/NuGet.targets b/.nuget/NuGet.targets index 3f8c37b..a6dbdfb 100644 --- a/.nuget/NuGet.targets +++ b/.nuget/NuGet.targets @@ -13,7 +13,7 @@ true - false + true @@ -66,10 +66,7 @@ $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols - - RestorePackages; - $(BuildDependsOn); - + @@ -78,31 +75,9 @@ - - - - - - - - - - - - - - - - + @@ -111,34 +86,5 @@ Condition=" '$(OS)' == 'Windows_NT' " /> - - - - - - - - - - - - - - - - + From b3e5c1234995a88771a8224743333e36f7c89391 Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Sat, 12 Sep 2015 02:21:50 -0600 Subject: [PATCH 29/81] nuget targets --- .nuget/NuGet.targets | 62 +++----------------------------------------- 1 file changed, 4 insertions(+), 58 deletions(-) diff --git a/.nuget/NuGet.targets b/.nuget/NuGet.targets index 3f8c37b..a6dbdfb 100644 --- a/.nuget/NuGet.targets +++ b/.nuget/NuGet.targets @@ -13,7 +13,7 @@ true - false + true @@ -66,10 +66,7 @@ $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols - - RestorePackages; - $(BuildDependsOn); - + @@ -78,31 +75,9 @@ - - - - - - - - - - - - - - - - + @@ -111,34 +86,5 @@ Condition=" '$(OS)' == 'Windows_NT' " /> - - - - - - - - - - - - - - - - + From ea8e2c0ac6b32a4e2669a367eeb59c33aad23fbd Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Sat, 12 Sep 2015 02:40:58 -0600 Subject: [PATCH 30/81] fixing package refs --- .../AustinHarris.JsonRpcTestN.csproj | 6 ++--- AustinHarris.JsonRpcTestN/packages.config | 2 +- Json-Rpc/AustinHarris.JsonRpc.csproj | 22 +++++++++---------- Json-Rpc/packages.config | 2 +- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj index 799174b..ce03e94 100644 --- a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj +++ b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj @@ -29,12 +29,12 @@ - - ..\packages\NUnit.2.6.3\lib\nunit.framework.dll - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + + ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + diff --git a/AustinHarris.JsonRpcTestN/packages.config b/AustinHarris.JsonRpcTestN/packages.config index ef51508..3b829b9 100644 --- a/AustinHarris.JsonRpcTestN/packages.config +++ b/AustinHarris.JsonRpcTestN/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/Json-Rpc/AustinHarris.JsonRpc.csproj b/Json-Rpc/AustinHarris.JsonRpc.csproj index cb0be46..81e929d 100644 --- a/Json-Rpc/AustinHarris.JsonRpc.csproj +++ b/Json-Rpc/AustinHarris.JsonRpc.csproj @@ -3,14 +3,12 @@ Debug x86 - 8.0.30703 - 2.0 {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307} Library Properties AustinHarris.JsonRpc AustinHarris.JsonRpc - v4.0 + v4.5 512 @@ -42,17 +40,18 @@ 4 false - - - AnyCPU bin\Debug\ TRACE;DEBUG + 4 + false AnyCPU bin\Release\ + 4 + false @@ -71,14 +70,10 @@ + - ..\packages\Newtonsoft.Json.6.0.5\lib\net40\Newtonsoft.Json.dll - True + ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll - - - - @@ -95,4 +90,7 @@ --> + + + \ No newline at end of file diff --git a/Json-Rpc/packages.config b/Json-Rpc/packages.config index 3d97f00..505e588 100644 --- a/Json-Rpc/packages.config +++ b/Json-Rpc/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file From 05052457b41ee5f11ae8f47eb6e6acc2fef0398f Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Sat, 12 Sep 2015 02:40:58 -0600 Subject: [PATCH 31/81] fixing package refs --- .../AustinHarris.JsonRpcTestN.csproj | 6 ++--- AustinHarris.JsonRpcTestN/packages.config | 2 +- Json-Rpc/AustinHarris.JsonRpc.csproj | 22 +++++++++---------- Json-Rpc/packages.config | 2 +- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj index 799174b..ce03e94 100644 --- a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj +++ b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj @@ -29,12 +29,12 @@ - - ..\packages\NUnit.2.6.3\lib\nunit.framework.dll - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + + ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + diff --git a/AustinHarris.JsonRpcTestN/packages.config b/AustinHarris.JsonRpcTestN/packages.config index ef51508..3b829b9 100644 --- a/AustinHarris.JsonRpcTestN/packages.config +++ b/AustinHarris.JsonRpcTestN/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/Json-Rpc/AustinHarris.JsonRpc.csproj b/Json-Rpc/AustinHarris.JsonRpc.csproj index cb0be46..81e929d 100644 --- a/Json-Rpc/AustinHarris.JsonRpc.csproj +++ b/Json-Rpc/AustinHarris.JsonRpc.csproj @@ -3,14 +3,12 @@ Debug x86 - 8.0.30703 - 2.0 {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307} Library Properties AustinHarris.JsonRpc AustinHarris.JsonRpc - v4.0 + v4.5 512 @@ -42,17 +40,18 @@ 4 false - - - AnyCPU bin\Debug\ TRACE;DEBUG + 4 + false AnyCPU bin\Release\ + 4 + false @@ -71,14 +70,10 @@ + - ..\packages\Newtonsoft.Json.6.0.5\lib\net40\Newtonsoft.Json.dll - True + ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll - - - - @@ -95,4 +90,7 @@ --> + + + \ No newline at end of file diff --git a/Json-Rpc/packages.config b/Json-Rpc/packages.config index 3d97f00..505e588 100644 --- a/Json-Rpc/packages.config +++ b/Json-Rpc/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file From 784c160e836ee22610d40fd54e4160106589782c Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Sat, 12 Sep 2015 02:47:50 -0600 Subject: [PATCH 32/81] package targeting --- Json-Rpc/AustinHarris.JsonRpc.csproj | 4 ++-- Json-Rpc/packages.config | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Json-Rpc/AustinHarris.JsonRpc.csproj b/Json-Rpc/AustinHarris.JsonRpc.csproj index 81e929d..2a3fecb 100644 --- a/Json-Rpc/AustinHarris.JsonRpc.csproj +++ b/Json-Rpc/AustinHarris.JsonRpc.csproj @@ -8,7 +8,6 @@ Properties AustinHarris.JsonRpc AustinHarris.JsonRpc - v4.5 512 @@ -18,6 +17,7 @@ SAK ..\..\CoiniumServ\build\ true + v4.0 AnyCPU @@ -72,7 +72,7 @@ - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.7.0.1\lib\net40\Newtonsoft.Json.dll diff --git a/Json-Rpc/packages.config b/Json-Rpc/packages.config index 505e588..1b9f231 100644 --- a/Json-Rpc/packages.config +++ b/Json-Rpc/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file From 754d905ec8c3f524f6eef35600f9053413078cdf Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Sat, 12 Sep 2015 02:47:50 -0600 Subject: [PATCH 33/81] package targeting --- Json-Rpc/AustinHarris.JsonRpc.csproj | 4 ++-- Json-Rpc/packages.config | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Json-Rpc/AustinHarris.JsonRpc.csproj b/Json-Rpc/AustinHarris.JsonRpc.csproj index 81e929d..2a3fecb 100644 --- a/Json-Rpc/AustinHarris.JsonRpc.csproj +++ b/Json-Rpc/AustinHarris.JsonRpc.csproj @@ -8,7 +8,6 @@ Properties AustinHarris.JsonRpc AustinHarris.JsonRpc - v4.5 512 @@ -18,6 +17,7 @@ SAK ..\..\CoiniumServ\build\ true + v4.0 AnyCPU @@ -72,7 +72,7 @@ - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.7.0.1\lib\net40\Newtonsoft.Json.dll diff --git a/Json-Rpc/packages.config b/Json-Rpc/packages.config index 505e588..1b9f231 100644 --- a/Json-Rpc/packages.config +++ b/Json-Rpc/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file From 3cab7017f7f475886148646657eff7f34b74c9bb Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Sat, 12 Sep 2015 03:00:46 -0600 Subject: [PATCH 34/81] make test more reliable --- AustinHarris.JsonRpcTestN/Test.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/AustinHarris.JsonRpcTestN/Test.cs b/AustinHarris.JsonRpcTestN/Test.cs index 12989f1..722cd5b 100644 --- a/AustinHarris.JsonRpcTestN/Test.cs +++ b/AustinHarris.JsonRpcTestN/Test.cs @@ -168,10 +168,9 @@ public void StringToRefException() public void StringToThrowJsonRpcException() { string request = @"{method:'StringToThrowJsonRpcException',params:['some string'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"Just some testing\",\"code\":-27000,"; var result = JsonRpcProcessor.Process(request); result.Wait(); - StringAssert.StartsWith (expectedResult, result.Result); + StringAssert.Contains ("-2700", result.Result); } [Test ()] From c0a6d05741c6197a3ffaccbe2ee414b049d7d7d1 Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Sat, 12 Sep 2015 03:00:46 -0600 Subject: [PATCH 35/81] make test more reliable --- AustinHarris.JsonRpcTestN/Test.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/AustinHarris.JsonRpcTestN/Test.cs b/AustinHarris.JsonRpcTestN/Test.cs index 12989f1..722cd5b 100644 --- a/AustinHarris.JsonRpcTestN/Test.cs +++ b/AustinHarris.JsonRpcTestN/Test.cs @@ -168,10 +168,9 @@ public void StringToRefException() public void StringToThrowJsonRpcException() { string request = @"{method:'StringToThrowJsonRpcException',params:['some string'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"Just some testing\",\"code\":-27000,"; var result = JsonRpcProcessor.Process(request); result.Wait(); - StringAssert.StartsWith (expectedResult, result.Result); + StringAssert.Contains ("-2700", result.Result); } [Test ()] From e58f5d6eb8e6a0ce1bfce5c082c8b9a29f65d96b Mon Sep 17 00:00:00 2001 From: rommar Date: Sun, 31 Jan 2016 01:58:34 +0300 Subject: [PATCH 36/81] Possibility to specify a method parameter name as it will be referred to by JsonRpc --- Json-Rpc/Attributes.cs | 23 +++++++++++++++++++++++ Json-Rpc/JsonRpcService.cs | 17 ++++++++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Json-Rpc/Attributes.cs b/Json-Rpc/Attributes.cs index dd78282..1592511 100644 --- a/Json-Rpc/Attributes.cs +++ b/Json-Rpc/Attributes.cs @@ -24,4 +24,27 @@ public string JsonMethodName get { return jsonMethodName; } } } + + /// + /// Used to assign JsonRpc parameter name to method argument. + /// + [AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = false)] + public sealed class JsonRpcParamAttribute : Attribute + { + readonly string jsonParamName; + + /// + /// Used to assign JsonRpc parameter name to method argument. + /// + /// Lets you specify the parameter name as it will be referred to by JsonRpc. + public JsonRpcParamAttribute(string jsonParamName = "") + { + this.jsonParamName = jsonParamName; + } + + public string JsonParamName + { + get { return jsonParamName; } + } + } } diff --git a/Json-Rpc/JsonRpcService.cs b/Json-Rpc/JsonRpcService.cs index c5a3569..4850725 100644 --- a/Json-Rpc/JsonRpcService.cs +++ b/Json-Rpc/JsonRpcService.cs @@ -37,14 +37,25 @@ private void buildService(string sessionID) var paramzs = meth.GetParameters(); List parameterTypeArray = new List(); - for (int i = 0; i < paramzs.Length; i++) + for (int i = 0; i < paramzs.Length; i++) { + string paramName; + var paramAttrs = paramzs[i].GetCustomAttributes(typeof(JsonRpcParamAttribute), false); + if (paramAttrs.Length > 0) + { + paramName = ((JsonRpcParamAttribute)paramAttrs[0]).JsonParamName; + } + else + { + paramName = paramzs[i].Name; + } + // reflection attribute information for optional parameters //http://stackoverflow.com/questions/2421994/invoking-methods-with-optional-parameters-through-reflection - paras.Add(paramzs[i].Name, paramzs[i].ParameterType); + paras.Add(paramName, paramzs[i].ParameterType); if (paramzs[i].IsOptional) // if the parameter is an optional, add the default value to our default values dictionary. - defaultValues.Add(paramzs[i].Name, paramzs[i].DefaultValue); + defaultValues.Add(paramName, paramzs[i].DefaultValue); } var resType = meth.ReturnType; From 4d1700d60e11f2d1809de870ca21025a3707f8b9 Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Tue, 1 Mar 2016 21:28:57 -0700 Subject: [PATCH 37/81] Added ability to register attributed classes that do not inherit from JsonRpcService via Servicebinder.bindService --- .../AustinHarris.JsonRpc.AspNet.csproj | 6 +- AustinHarris.JsonRpc.AspNet/packages.config | 2 +- .../AustinHarris.JsonRpcTestN.csproj | 26 ++++++-- AustinHarris.JsonRpcTestN/Test.cs | 38 ++++++++++++ AustinHarris.JsonRpcTestN/packages.config | 4 +- Json-Rpc/AustinHarris.JsonRpc.csproj | 14 +++-- Json-Rpc/JsonRpcService.cs | 48 +-------------- Json-Rpc/ServiceBinder.cs | 59 +++++++++++++++++++ Json-Rpc/packages.config | 2 +- TestServer_Console/TestServer_Console.csproj | 22 +++++-- TestServer_Console/packages.config | 2 +- 11 files changed, 151 insertions(+), 72 deletions(-) create mode 100644 Json-Rpc/ServiceBinder.cs diff --git a/AustinHarris.JsonRpc.AspNet/AustinHarris.JsonRpc.AspNet.csproj b/AustinHarris.JsonRpc.AspNet/AustinHarris.JsonRpc.AspNet.csproj index 7515913..bf84656 100644 --- a/AustinHarris.JsonRpc.AspNet/AustinHarris.JsonRpc.AspNet.csproj +++ b/AustinHarris.JsonRpc.AspNet/AustinHarris.JsonRpc.AspNet.csproj @@ -36,9 +36,9 @@ 4 - - False - ..\packages\Newtonsoft.Json.6.0.5\lib\net40\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.8.0.2\lib\net40\Newtonsoft.Json.dll + True diff --git a/AustinHarris.JsonRpc.AspNet/packages.config b/AustinHarris.JsonRpc.AspNet/packages.config index 3d97f00..28e5e44 100644 --- a/AustinHarris.JsonRpc.AspNet/packages.config +++ b/AustinHarris.JsonRpc.AspNet/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj index ce03e94..285e74c 100644 --- a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj +++ b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj @@ -1,4 +1,4 @@ - + Debug @@ -8,6 +8,8 @@ AustinHarris.JsonRpcTestN AustinHarris.JsonRpcTestN v4.5 + ..\ + true true @@ -28,13 +30,15 @@ false - - - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll + True - - ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + + ..\packages\NUnit.3.0.1\lib\net45\nunit.framework.dll + True + @@ -50,4 +54,14 @@ AustinHarris.JsonRpc + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file diff --git a/AustinHarris.JsonRpcTestN/Test.cs b/AustinHarris.JsonRpcTestN/Test.cs index 722cd5b..059d2b6 100644 --- a/AustinHarris.JsonRpcTestN/Test.cs +++ b/AustinHarris.JsonRpcTestN/Test.cs @@ -7,6 +7,23 @@ namespace AustinHarris.JsonRpcTestN { + public class Poco + { + public static Poco WithOffset(int offset) + { + return new Poco(offset); + } + + readonly int _offset; + public Poco(int offset) + { + _offset = offset; + } + + [JsonRpcMethod("add")] + public int Add(int input) { return input + _offset; } + } + [TestFixture ()] public class Test { @@ -22,6 +39,27 @@ static Test() new CalculatorService()}; } + [Test()] + public void TestCanCreateMultipleServicesOfSameTypeInTheirOwnSessions() + { + Func request = (int param) => String.Format("{{method:'add',params:[{0}],id:1}}", param); + Func expectedResult = (int param) => String.Format("{{\"jsonrpc\":\"2.0\",\"result\":{0},\"id\":1}}", param); + + for (int i = 0; i < 100; i++) + { + ServiceBinder.bindService(i.ToString(), () => Poco.WithOffset(i)); + } + + for (int i = 0; i < 100; i++) + { + var result = JsonRpcProcessor.Process(i.ToString(), request(10)); + result.Wait(); + var actual1 = JObject.Parse(result.Result); + var expected1 = JObject.Parse(expectedResult(10 + i)); + Assert.AreEqual(expected1, actual1); + } + } + [Test ()] public void TestCanCreateAndRemoveSession() { diff --git a/AustinHarris.JsonRpcTestN/packages.config b/AustinHarris.JsonRpcTestN/packages.config index 3b829b9..0d4da84 100644 --- a/AustinHarris.JsonRpcTestN/packages.config +++ b/AustinHarris.JsonRpcTestN/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file diff --git a/Json-Rpc/AustinHarris.JsonRpc.csproj b/Json-Rpc/AustinHarris.JsonRpc.csproj index 2a3fecb..ac01ecf 100644 --- a/Json-Rpc/AustinHarris.JsonRpc.csproj +++ b/Json-Rpc/AustinHarris.JsonRpc.csproj @@ -67,13 +67,18 @@ + - - - ..\packages\Newtonsoft.Json.7.0.1\lib\net40\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.8.0.2\lib\net40\Newtonsoft.Json.dll + True + + + + @@ -90,7 +95,4 @@ --> - - - \ No newline at end of file diff --git a/Json-Rpc/JsonRpcService.cs b/Json-Rpc/JsonRpcService.cs index c5a3569..46bfb63 100644 --- a/Json-Rpc/JsonRpcService.cs +++ b/Json-Rpc/JsonRpcService.cs @@ -10,56 +10,12 @@ public abstract class JsonRpcService { protected JsonRpcService() { - buildService(Handler.DefaultSessionId()); + ServiceBinder.bindService(Handler.DefaultSessionId(), () => this); } protected JsonRpcService(string sessionID) { - buildService(sessionID); - } - - private void buildService(string sessionID) - { - // get the registerMethod. - // Method that matches Func - var regMethod = typeof(Handler).GetMethod("Register"); - - // var assem = Assembly.GetExecutingAssembly(); - // var TypesWithHandlers = assem.GetTypes().Where(f => f.GetCustomAttributes(typeof(JsonRpcAttribute), false).Length > 0); - var item = this.GetType(); - - var methods = item.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(m => m.GetCustomAttributes(typeof(JsonRpcMethodAttribute), false).Length > 0); - foreach (var meth in methods) - { - Dictionary paras = new Dictionary(); - Dictionary defaultValues = new Dictionary(); // dictionary that holds default values for optional params. - - var paramzs = meth.GetParameters(); - - List parameterTypeArray = new List(); - for (int i = 0; i < paramzs.Length; i++) - { - // reflection attribute information for optional parameters - //http://stackoverflow.com/questions/2421994/invoking-methods-with-optional-parameters-through-reflection - paras.Add(paramzs[i].Name, paramzs[i].ParameterType); - - if (paramzs[i].IsOptional) // if the parameter is an optional, add the default value to our default values dictionary. - defaultValues.Add(paramzs[i].Name, paramzs[i].DefaultValue); - } - - var resType = meth.ReturnType; - paras.Add("returns", resType); // add the return type to the generic parameters list. - - var atdata = meth.GetCustomAttributes(typeof(JsonRpcMethodAttribute), false); - foreach (JsonRpcMethodAttribute handlerAttribute in atdata) - { - var methodName = handlerAttribute.JsonMethodName == string.Empty ? meth.Name : handlerAttribute.JsonMethodName; - var newDel = Delegate.CreateDelegate(System.Linq.Expressions.Expression.GetDelegateType(paras.Values.ToArray()), this /*Need to add support for other methods outside of this instance*/, meth); - var handlerSession = Handler.GetSessionHandler(sessionID); - regMethod.Invoke(handlerSession, new object[] { methodName, newDel }); - handlerSession.MetaData.AddService(methodName, paras, defaultValues); - } - } + ServiceBinder.bindService(sessionID, () => this); } } } diff --git a/Json-Rpc/ServiceBinder.cs b/Json-Rpc/ServiceBinder.cs new file mode 100644 index 0000000..d6b8451 --- /dev/null +++ b/Json-Rpc/ServiceBinder.cs @@ -0,0 +1,59 @@ +namespace AustinHarris.JsonRpc +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Reflection; + using AustinHarris.JsonRpc; + + public static class ServiceBinder + { + public static void bindService(string sessionID, Func serviceFactory) + { + var instance = serviceFactory(); + var item = instance.GetType(); // var item = typeof(T); + var regMethod = typeof(Handler).GetMethod("Register"); + + var methods = item.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(m => m.GetCustomAttributes(typeof(JsonRpcMethodAttribute), false).Length > 0); + foreach (var meth in methods) + { + Dictionary paras = new Dictionary(); + Dictionary defaultValues = new Dictionary(); // dictionary that holds default values for optional params. + + var paramzs = meth.GetParameters(); + + List parameterTypeArray = new List(); + for (int i = 0; i < paramzs.Length; i++) + { + // reflection attribute information for optional parameters + //http://stackoverflow.com/questions/2421994/invoking-methods-with-optional-parameters-through-reflection + paras.Add(paramzs[i].Name, paramzs[i].ParameterType); + + if (paramzs[i].IsOptional) // if the parameter is an optional, add the default value to our default values dictionary. + defaultValues.Add(paramzs[i].Name, paramzs[i].DefaultValue); + } + + var resType = meth.ReturnType; + paras.Add("returns", resType); // add the return type to the generic parameters list. + + var atdata = meth.GetCustomAttributes(typeof(JsonRpcMethodAttribute), false); + foreach (JsonRpcMethodAttribute handlerAttribute in atdata) + { + var methodName = handlerAttribute.JsonMethodName == string.Empty ? meth.Name : handlerAttribute.JsonMethodName; + var newDel = Delegate.CreateDelegate(System.Linq.Expressions.Expression.GetDelegateType(paras.Values.ToArray()), instance /*Need to add support for other methods outside of this instance*/, meth); + var handlerSession = Handler.GetSessionHandler(sessionID); + regMethod.Invoke(handlerSession, new object[] { methodName, newDel }); + handlerSession.MetaData.AddService(methodName, paras, defaultValues); + } + } + } + public static void bindService(string sessionID) where T : new() + { + bindService(sessionID, () => new T()); + } + public static void bindService() where T : new() + { + bindService(Handler.DefaultSessionId()); + } + } +} \ No newline at end of file diff --git a/Json-Rpc/packages.config b/Json-Rpc/packages.config index 1b9f231..28e5e44 100644 --- a/Json-Rpc/packages.config +++ b/Json-Rpc/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/TestServer_Console/TestServer_Console.csproj b/TestServer_Console/TestServer_Console.csproj index 32f9ca8..c4db47c 100644 --- a/TestServer_Console/TestServer_Console.csproj +++ b/TestServer_Console/TestServer_Console.csproj @@ -15,6 +15,8 @@ SAK SAK SAK + ..\ + true AnyCPU @@ -48,6 +50,10 @@ false + + ..\packages\Newtonsoft.Json.8.0.2\lib\net40\Newtonsoft.Json.dll + True + @@ -55,9 +61,6 @@ - - ..\packages\Newtonsoft.Json.7.0.1\lib\net40\Newtonsoft.Json.dll - @@ -70,6 +73,9 @@ AustinHarris.JsonRpc + + + - - - + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file diff --git a/TestServer_Console/packages.config b/TestServer_Console/packages.config index 4af203d..d4d9e6f 100644 --- a/TestServer_Console/packages.config +++ b/TestServer_Console/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file From 9b1d30b9a7628a94281e83bc9526ca457c45fe80 Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Tue, 1 Mar 2016 22:09:32 -0700 Subject: [PATCH 38/81] fixed some problems with the merge --- .../AustinHarris.JsonRpcTestN.csproj | 20 ------------------- AustinHarris.JsonRpcTestN/Test.cs | 6 ------ Json-Rpc/AustinHarris.JsonRpc.csproj | 3 ++- TestServer_Console/TestServer_Console.csproj | 6 ------ 4 files changed, 2 insertions(+), 33 deletions(-) diff --git a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj index df7e0a5..b63ba8c 100644 --- a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj +++ b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj @@ -1,8 +1,4 @@ -<<<<<<< HEAD - -======= ->>>>>>> c0a6d05741c6197a3ffaccbe2ee414b049d7d7d1 Debug @@ -12,11 +8,8 @@ AustinHarris.JsonRpcTestN AustinHarris.JsonRpcTestN v4.5 -<<<<<<< HEAD ..\ true -======= ->>>>>>> c0a6d05741c6197a3ffaccbe2ee414b049d7d7d1 true @@ -37,7 +30,6 @@ false -<<<<<<< HEAD ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll True @@ -47,15 +39,6 @@ True -======= - - - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll - - - ..\packages\NUnit.2.6.4\lib\nunit.framework.dll - ->>>>>>> c0a6d05741c6197a3ffaccbe2ee414b049d7d7d1 @@ -71,7 +54,6 @@ AustinHarris.JsonRpc -<<<<<<< HEAD @@ -82,6 +64,4 @@ -======= ->>>>>>> c0a6d05741c6197a3ffaccbe2ee414b049d7d7d1 \ No newline at end of file diff --git a/AustinHarris.JsonRpcTestN/Test.cs b/AustinHarris.JsonRpcTestN/Test.cs index adbd315..059d2b6 100644 --- a/AustinHarris.JsonRpcTestN/Test.cs +++ b/AustinHarris.JsonRpcTestN/Test.cs @@ -7,7 +7,6 @@ namespace AustinHarris.JsonRpcTestN { -<<<<<<< HEAD public class Poco { public static Poco WithOffset(int offset) @@ -25,8 +24,6 @@ public Poco(int offset) public int Add(int input) { return input + _offset; } } -======= ->>>>>>> c0a6d05741c6197a3ffaccbe2ee414b049d7d7d1 [TestFixture ()] public class Test { @@ -42,7 +39,6 @@ static Test() new CalculatorService()}; } -<<<<<<< HEAD [Test()] public void TestCanCreateMultipleServicesOfSameTypeInTheirOwnSessions() { @@ -64,8 +60,6 @@ public void TestCanCreateMultipleServicesOfSameTypeInTheirOwnSessions() } } -======= ->>>>>>> c0a6d05741c6197a3ffaccbe2ee414b049d7d7d1 [Test ()] public void TestCanCreateAndRemoveSession() { diff --git a/Json-Rpc/AustinHarris.JsonRpc.csproj b/Json-Rpc/AustinHarris.JsonRpc.csproj index cfdd181..9d67f72 100644 --- a/Json-Rpc/AustinHarris.JsonRpc.csproj +++ b/Json-Rpc/AustinHarris.JsonRpc.csproj @@ -75,6 +75,7 @@ ..\packages\Newtonsoft.Json.8.0.2\lib\net40\Newtonsoft.Json.dll True + @@ -94,4 +95,4 @@ - + \ No newline at end of file diff --git a/TestServer_Console/TestServer_Console.csproj b/TestServer_Console/TestServer_Console.csproj index 6dfd69f..5e276d2 100644 --- a/TestServer_Console/TestServer_Console.csproj +++ b/TestServer_Console/TestServer_Console.csproj @@ -84,7 +84,6 @@ --> -<<<<<<< HEAD @@ -92,9 +91,4 @@ -======= - - - ->>>>>>> c0a6d05741c6197a3ffaccbe2ee414b049d7d7d1 From 33a7200cc0d634a211d102e0f9ce03f9cb974a78 Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Tue, 1 Mar 2016 22:30:37 -0700 Subject: [PATCH 39/81] still finding merge issues. --- AustinHarris.JsonRpcTestN/packages.config | 5 ----- 1 file changed, 5 deletions(-) diff --git a/AustinHarris.JsonRpcTestN/packages.config b/AustinHarris.JsonRpcTestN/packages.config index 673d765..0d4da84 100644 --- a/AustinHarris.JsonRpcTestN/packages.config +++ b/AustinHarris.JsonRpcTestN/packages.config @@ -1,10 +1,5 @@  -<<<<<<< HEAD -======= - - ->>>>>>> c0a6d05741c6197a3ffaccbe2ee414b049d7d7d1 \ No newline at end of file From 0dc00392d55230349cf706164781efffc461dc62 Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Tue, 1 Mar 2016 23:54:29 -0700 Subject: [PATCH 40/81] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 629457b..3665866 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![Screenshot](http://i.imgur.com/rxHaXLb.png) -json-rpc.net +json-rpc.net [![astn-jsonrpc MyGet Build Status](https://www.myget.org/BuildSource/Badge/astn-jsonrpc?identifier=e8ccb637-ccd4-4940-b62c-bc1283cd9ddc)](https://www.myget.org/feed/Activity/astn-jsonrpc) ============ JSON-RPC.Net is a high performance Json-Rpc 2.0 server, leveraging the popular JSON.NET library. Host in ASP.NET, also supports sockets and pipes, oh my! From 444f3d4d237debea4e6eca3ee9ba87086ee5ad50 Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Wed, 2 Mar 2016 00:12:16 -0700 Subject: [PATCH 41/81] added travis --- .travis.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..93080db --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: csharp +solution: AustinHarris.JsonRpc.sln +mono: + - latest + - 3.12.0 + - 3.10.0 + - 3.8.0 + - 3.2.8 +install: + - nuget restore AustinHarris.JsonRpc.sln + - nuget install NUnit.Runners -Version 2.6.4 -OutputDirectory testrunner +script: + - xbuild /p:Configuration=Release AustinHarris.JsonRpc.sln + - mono ./testrunner/NUnit.Runners.2.6.4/tools/nunit-console.exe ./AustinHarris.JsonRpcTestN/bin/Release/AustinHarris.JsonRpcTestN.dll \ No newline at end of file From 7d86aafab73bf5a3b73a9ee5c1159f6ab0dc1233 Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Wed, 2 Mar 2016 00:40:06 -0700 Subject: [PATCH 42/81] downgrade nUnit to 2.6.4 for travis --- .../AustinHarris.JsonRpcTestN.csproj | 10 ++++++---- AustinHarris.JsonRpcTestN/packages.config | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj index b63ba8c..0c4bd29 100644 --- a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj +++ b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj @@ -1,4 +1,4 @@ - + Debug @@ -34,8 +34,8 @@ ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NUnit.3.0.1\lib\net45\nunit.framework.dll + + ..\packages\NUnit.2.6.4\lib\nunit.framework.dll True @@ -46,7 +46,9 @@ - + + Designer + diff --git a/AustinHarris.JsonRpcTestN/packages.config b/AustinHarris.JsonRpcTestN/packages.config index 0d4da84..d274cb4 100644 --- a/AustinHarris.JsonRpcTestN/packages.config +++ b/AustinHarris.JsonRpcTestN/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file From 5ee716ef0d2445d0d95a5a09732682aa3628f933 Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Wed, 2 Mar 2016 00:45:26 -0700 Subject: [PATCH 43/81] remove mono 3.2.8 from travis --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 93080db..f6ab2fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ mono: - 3.12.0 - 3.10.0 - 3.8.0 - - 3.2.8 install: - nuget restore AustinHarris.JsonRpc.sln - nuget install NUnit.Runners -Version 2.6.4 -OutputDirectory testrunner From 66c32ac9ad3f263341de49808f29ae52055cbbbb Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Wed, 2 Mar 2016 00:51:13 -0700 Subject: [PATCH 44/81] added badges --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3665866..5ac873c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ ![Screenshot](http://i.imgur.com/rxHaXLb.png) -json-rpc.net [![astn-jsonrpc MyGet Build Status](https://www.myget.org/BuildSource/Badge/astn-jsonrpc?identifier=e8ccb637-ccd4-4940-b62c-bc1283cd9ddc)](https://www.myget.org/feed/Activity/astn-jsonrpc) +json-rpc.net ============ +.Net [![astn-jsonrpc MyGet Build Status](https://www.myget.org/BuildSource/Badge/astn-jsonrpc?identifier=e8ccb637-ccd4-4940-b62c-bc1283cd9ddc)](https://www.myget.org/feed/Activity/astn-jsonrpc) Mono [![Build Status](https://travis-ci.org/Astn/JSON-RPC.NET.svg?branch=master)](https://travis-ci.org/Astn/JSON-RPC.NET) JSON-RPC.Net is a high performance Json-Rpc 2.0 server, leveraging the popular JSON.NET library. Host in ASP.NET, also supports sockets and pipes, oh my! From f85830a8121b42ecd9396f3c1dda34a99bf08b5c Mon Sep 17 00:00:00 2001 From: dawesc Date: Fri, 4 Mar 2016 21:32:53 +0000 Subject: [PATCH 45/81] Support for PostProcessor added Add support for handling a post process event Add support for testing the post process event Missing code to handle if the user wants to change the result in the PostProcess Missing the code to test the response handling in postprocess Error making it so that we have extra debug code Changes to make it so that when we are testing json it's done in a parsed manner, only minimal implementation used Support for additional tests for the pre and post processor where set exception is used instead Support the Pre/Post processor setting on just the handler Support for testing the handler for sessions --- AustinHarris.JsonRpcTestN/Test.cs | 3303 +++++++++++++++----------- AustinHarris.JsonRpcTestN/service.cs | 51 + Json-Rpc/Config.cs | 19 + Json-Rpc/Handler.cs | 76 +- 4 files changed, 1989 insertions(+), 1460 deletions(-) diff --git a/AustinHarris.JsonRpcTestN/Test.cs b/AustinHarris.JsonRpcTestN/Test.cs index 059d2b6..a513c7d 100644 --- a/AustinHarris.JsonRpcTestN/Test.cs +++ b/AustinHarris.JsonRpcTestN/Test.cs @@ -24,26 +24,26 @@ public Poco(int offset) public int Add(int input) { return input + _offset; } } - [TestFixture ()] - public class Test - { - [Test ()] - public void TestCase () - { - } - static object[] services; - - static Test() - { - services = new object[] { - new CalculatorService()}; - } + [TestFixture()] + public class Test + { + [Test()] + public void TestCase() + { + } + static object[] services; + + static Test() + { + services = new object[] { + new CalculatorService()}; + } [Test()] public void TestCanCreateMultipleServicesOfSameTypeInTheirOwnSessions() { - Func request = (int param) => String.Format("{{method:'add',params:[{0}],id:1}}", param); - Func expectedResult = (int param) => String.Format("{{\"jsonrpc\":\"2.0\",\"result\":{0},\"id\":1}}", param); + Func request = (int param) => String.Format("{{method:'add',params:[{0}],id:1}}", param); + Func expectedResult = (int param) => String.Format("{{\"jsonrpc\":\"2.0\",\"result\":{0},\"id\":1}}", param); for (int i = 0; i < 100; i++) { @@ -60,1417 +60,1864 @@ public void TestCanCreateMultipleServicesOfSameTypeInTheirOwnSessions() } } - [Test ()] - public void TestCanCreateAndRemoveSession() - { - var h = JsonRpc.Handler.GetSessionHandler ("this one"); - - h.Register ("workie", new Func(x => "workie ... " + x)); - - var metadata = new System.Collections.Generic.List> { - Tuple.Create ("sooper", typeof(string)), - Tuple.Create ("returns", typeof(string)) - }.ToDictionary(x=> x.Item1, x=> x.Item2); - h.MetaData.AddService("workie", metadata, new System.Collections.Generic.Dictionary()); - - string request = @"{method:'workie',params:{'sooper':'good'},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"workie ... good\",\"id\":1}"; - string expectedResultAfterDestroy = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"Method not found\",\"code\":-32601,\"data\":\"The method does not exist / is not available.\"},\"id\":1}"; - var result = JsonRpcProcessor.Process("this one", request); - result.Wait(); - - - var actual1 = JObject.Parse (result.Result); - var expected1 = JObject.Parse (expectedResult); - Assert.AreEqual(expected1, actual1); - - h.Destroy (); - - var result2 = JsonRpcProcessor.Process("this one", request); - result2.Wait(); - - Assert.AreEqual(JObject.Parse(expectedResultAfterDestroy), JObject.Parse(result2.Result)); - } - - [Test ()] - public void TestInProcessClient() - { - string request = @"{method:'NullableFloatToNullableFloat',params:[0.0],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":0.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void NullableDateTimeToNullableDateTime() - { - string request = @"{method:'NullableDateTimeToNullableDateTime',params:['2014-06-30T14:50:38.5208399+09:00'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"2014-06-30T14:50:38.5208399+09:00\",\"id\":1}"; - var expectedDate = DateTime.Parse("2014-06-30T14:50:38.5208399+09:00"); - var result = JsonRpcProcessor.Process(request); - result.Wait(); - var acutalDate = DateTime.Parse(result.Result.Substring(27, 33)); - Assert.AreEqual(expectedDate, acutalDate); - } - - [Test ()] - public void NullableFloatToNullableFloat() - { - string request = @"{method:'NullableFloatToNullableFloat',params:[1.2345],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.2345,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void NullableFloatToNullableFloat3() - { - string request = @"{method:'NullableFloatToNullableFloat',params:[3.14159],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":3.14159,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - - [Test ()] - public void NullableFloatToNullableFloat2() - { - string request = @"{method:'NullableFloatToNullableFloat',params:[null],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void DecimalToNullableDecimal() - { - string request = @"{method:'DecimalToNullableDecimal',params:[0.0],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":0.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void StringToListOfString() - { - string request = @"{method:'StringToListOfString',params:['some string'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"one\",\"two\",\"three\",\"some string\"],\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void CustomStringToListOfString() - { - string request = @"{method:'CustomStringToListOfString',params:[{str:'some string'}],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"one\",\"two\",\"three\",\"some string\"],\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.AreEqual(result.Result, expectedResult); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void StringToThrowingException() - { - string request = @"{method:'StringToThrowingException',params:['some string'],id:1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - StringAssert.Contains ("-32603", result.Result); - } - - [Test ()] - public void StringToRefException() - { - string request = @"{method:'StringToRefException',params:['some string'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"refException worked\",\"code\":-1,\"data\":null},\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.AreEqual(JObject.Parse(expectedResult),JObject.Parse( result.Result)); - } - - [Test ()] - public void StringToThrowJsonRpcException() - { - string request = @"{method:'StringToThrowJsonRpcException',params:['some string'],id:1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - StringAssert.Contains ("-2700", result.Result); - } - - [Test ()] - public void ReturnsDateTime() - { - string request = @"{method:'ReturnsDateTime',params:[],id:1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - } - - [Test ()] - public void ReturnsCustomRecursiveClass() - { - string request = @"{method:'ReturnsCustomRecursiveClass',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":{\"Nested1\":{\"Nested1\":null,\"Value1\":5},\"Value1\":10},\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - - [Test ()] - public void FloatToFloat() - { - string request = @"{method:'FloatToFloat',params:[0.123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":0.123,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - - [Test ()] - public void IntToInt() - { - string request = @"{method:'IntToInt',params:[789],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void OptionalParamInt16() - { - string request = @"{method:'TestOptionalParamInt16',params:[789],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void OptionalParamInt16NoParam() - { - string request = @"{method:'TestOptionalParamInt16',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void Int16ToInt16() - { - string request = @"{method:'Int16ToInt16',params:[789],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void Int32ToInt32() - { - string request = @"{method:'Int32ToInt32',params:[789],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void Int64ToInt64() - { - string request = @"{method:'Int64ToInt64',params:[78915984515564],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":78915984515564,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - - [Test ()] - public void TestOptionalParamByteMissing() - { - string request = @"{method:'TestOptionalParambyte',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamSbyteMissing() - { - string request = @"{method:'TestOptionalParamsbyte',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamShortMissing() - { - string request = @"{method:'TestOptionalParamshort',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamintMissing() - { - string request = @"{method:'TestOptionalParamint',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamLongMissing() - { - string request = @"{method:'TestOptionalParamlong',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUshortMissing() - { - string request = @"{method:'TestOptionalParamushort',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUintMissing() - { - string request = @"{method:'TestOptionalParamuint',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUlongMissing() - { - string request = @"{method:'TestOptionalParamulong',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamFloatMissing() - { - string request = @"{method:'TestOptionalParamfloat',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamDoubleMissing() - { - string request = @"{method:'TestOptionalParamdouble',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamBoolMissing() - { - string request = @"{method:'TestOptionalParambool',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamCharMissing() - { - string request = @"{method:'TestOptionalParamchar',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"a\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamDecimalMissing() - { - string request = @"{method:'TestOptionalParamdecimal',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void TestOptionalParamBytePresent() - { - string request = @"{method:'TestOptionalParambyte',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamSbytePresent() - { - string request = @"{method:'TestOptionalParamsbyte',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamShortPresent() - { - string request = @"{method:'TestOptionalParamshort',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamintPresent() - { - string request = @"{method:'TestOptionalParamint',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamLongPresent() - { - string request = @"{method:'TestOptionalParamlong',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUshortPresent() - { - string request = @"{method:'TestOptionalParamushort',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUintPresent() - { - string request = @"{method:'TestOptionalParamuint',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUlongPresent() - { - string request = @"{method:'TestOptionalParamulong',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamFloatPresent() - { - string request = @"{method:'TestOptionalParamfloat',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamDoublePresent() - { - string request = @"{method:'TestOptionalParamdouble',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamBoolPresent() - { - string request = @"{method:'TestOptionalParambool',params:[false],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":false,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamCharPresent() - { - string request = @"{method:'TestOptionalParamchar',params:["+(int)'b'+"],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"b\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamDecimalPresent() - { - string request = @"{method:'TestOptionalParamdecimal',params:[71],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void TestOptionalParamBytePresentObjectSyntax() - { - string request = @"{method:'TestOptionalParambyte',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamSbytePresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamsbyte',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamShortPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamshort',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamintPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamint',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamLongPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamlong',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUshortPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamushort',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUintPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamuint',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUlongPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamulong',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamFloatPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamfloat',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamDoublePresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamdouble',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamBoolPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParambool',params:{'input':false},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":false,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamCharPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamchar',params:{'input':"+(int)'c'+"},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"c\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamDecimalPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamdecimal',params:{'input':71},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void TestOptionalParamByteMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParambyte',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamSbyteMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamsbyte',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamShortMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamshort',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamintMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamint',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamLongMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamlong',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUshortMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamushort',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUintMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamuint',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUlongMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamulong',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamFloatMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamfloat',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamDoubleMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamdouble',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamBoolMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParambool',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamCharMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamchar',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"a\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamDecimalMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamdecimal',params:{},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void TestOptionalParamByte_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParambyte_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":98,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamSbyte_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamsbyte_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":126,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamShort_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamshort_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamint_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamint_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamLong_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamlong_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUshort_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamushort_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUint_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamuint_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUlong_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamulong_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamFloat_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamfloat_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamDouble_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamdouble_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamBool_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParambool_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamChar_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamchar_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamDecimal_2ndMissingObjectSyntax() - { - string request = @"{method:'TestOptionalParamdecimal_2x',params:{input1:123},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void TestOptionalParamByte_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParambyte_2x',params:{input1:123, input2: 67},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":67,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamByte_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParambyte_2x',params:[123, 67],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":67,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamByte_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParambyte_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":98,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamSbyte_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamsbyte_2x',params:{input1:123, input2: 97},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":97,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamSbyte_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamsbyte_2x',params:[123, 98],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":98,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamSbyte_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamsbyte_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":126,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamShort_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamshort_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamShort_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamshort_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamShort_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamshort_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamint_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamint_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamint_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamint_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamint_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamint_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamLong_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamlong_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamLong_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamlong_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamLong_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamlong_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUshort_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamushort_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUshort_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamushort_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUshort_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamushort_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUint_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamuint_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUint_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamuint_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUint_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamuint_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUlong_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamulong_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUlong_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamulong_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamUlong_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamulong_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamFloat_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamfloat_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamFloat_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamfloat_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamFloat_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamfloat_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamDouble_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamdouble_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamDouble_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamdouble_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamDouble_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamdouble_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamBool_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParambool_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamBool_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParambool_2x',params:[true, false],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":false,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamBool_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParambool_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamChar_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamchar_2x',params:{'input1':" + (int)'c' + ", 'input2':" + (int)'d' + "},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamChar_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamchar_2x',params:[" + (int)'c' + ", " + (int)'d' + "],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamChar_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamchar_2x',params:["+(int)'c'+"],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamDecimal_2ndPresentObjectSyntax() - { - string request = @"{method:'TestOptionalParamdecimal_2x',params:{input1:123, input2: 671},id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamDecimal_2ndPresentArraySyntax() - { - string request = @"{method:'TestOptionalParamdecimal_2x',params:[123, 671],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - [Test ()] - public void TestOptionalParamDecimal_2ndMissingArraySyntax() - { - string request = @"{method:'TestOptionalParamdecimal_2x',params:[123],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void TestOptionalParametersStrings_BothMissing() - { - string request = @"{method:'TestOptionalParameters_Strings',params:[],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[null,null],\"id\":1}"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void TestOptionalParametersStrings_SecondMissing() - { - string request = @"{method:'TestOptionalParameters_Strings',params:['first'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"first\",null],\"id\":1}"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void TestOptionalParametersStrings_BothExists() - { - string request = @"{method:'TestOptionalParameters_Strings',params:['first','second'],id:1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"first\",\"second\"],\"id\":1}"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void TestOptionalParametersBoolsAndStrings() - { - string request = - "{\"jsonrpc\":\"2.0\",\"method\":\"TestOptionalParametersBoolsAndStrings\",\"params\":{\"input1\":\"murkel\"},\"Id\":1}"; - string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - Assert.IsFalse(result.Result.Contains("error")); - Assert.AreEqual(expectedResult, result.Result); - } - - [Test ()] - public void TestBatchResultWrongRequests() - { - string request = @"[{},{""jsonrpc"":""2.0"",""id"":4}]"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - - Assert.IsTrue(Regex.IsMatch(result.Result, @"\[(\{.*""error"":.*?,""id"":.*?\}),(\{.*""error"":.*?,""id"":.*?\})\]"), "Should have two errors."); - } - - [Test ()] - public void TestBatchResultMultipleMethodCallsNotificationAtLast() - { - string request = - @"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}]"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - - Assert.IsFalse(result.Result.EndsWith(@",]"), "result.Result.EndsWith(@',]')"); - - } - - [Test ()] - public void TestEmptyBatchResult() - { - var secondRequest = @"{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}"; - var result = JsonRpcProcessor.Process(secondRequest); - result.Wait(); - - Assert.IsTrue(string.IsNullOrEmpty(result.Result)); - } - - [Test ()] - public void TestLeftOutParams() - { - var request = - @"{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""id"":1}"; - - var result = JsonRpcProcessor.Process(request); - result.Wait(); - - Assert.IsFalse(result.Result.Contains(@"error"":{""code"":-32602"), @"According to JSON-RPC 2.0 the ""params"" member MAY be omitted."); - } - - [Test ()] - public void TestMultipleResults() - { - var result = - JsonRpcProcessor.Process( - @"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]"); - result.Wait(); - - Assert.IsTrue(result.Result.EndsWith("]")); - } - - [Test ()] - public void TestSingleResultBatch() - { - var result = - JsonRpcProcessor.Process(@"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]"); - result.Wait(); - Assert.IsFalse(result.Result.EndsWith("]")); - } - } + [Test()] + public void TestCanCreateAndRemoveSession() + { + var h = JsonRpc.Handler.GetSessionHandler("this one"); + + h.Register("workie", new Func(x => "workie ... " + x)); + + var metadata = new System.Collections.Generic.List> { + Tuple.Create ("sooper", typeof(string)), + Tuple.Create ("returns", typeof(string)) + }.ToDictionary(x => x.Item1, x => x.Item2); + h.MetaData.AddService("workie", metadata, new System.Collections.Generic.Dictionary()); + + string request = @"{method:'workie',params:{'sooper':'good'},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"workie ... good\",\"id\":1}"; + string expectedResultAfterDestroy = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"Method not found\",\"code\":-32601,\"data\":\"The method does not exist / is not available.\"},\"id\":1}"; + var result = JsonRpcProcessor.Process("this one", request); + result.Wait(); + + + var actual1 = JObject.Parse(result.Result); + var expected1 = JObject.Parse(expectedResult); + Assert.AreEqual(expected1, actual1); + + h.Destroy(); + + var result2 = JsonRpcProcessor.Process("this one", request); + result2.Wait(); + + Assert.AreEqual(JObject.Parse(expectedResultAfterDestroy), JObject.Parse(result2.Result)); + } + + [Test()] + public void TestInProcessClient() + { + string request = @"{method:'NullableFloatToNullableFloat',params:[0.0],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":0.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void NullableDateTimeToNullableDateTime() + { + string request = @"{method:'NullableDateTimeToNullableDateTime',params:['2014-06-30T14:50:38.5208399+09:00'],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"2014-06-30T14:50:38.5208399+09:00\",\"id\":1}"; + var expectedDate = DateTime.Parse("2014-06-30T14:50:38.5208399+09:00"); + var result = JsonRpcProcessor.Process(request); + result.Wait(); + var acutalDate = DateTime.Parse(result.Result.Substring(27, 33)); + Assert.AreEqual(expectedDate, acutalDate); + } + + [Test()] + public void NullableFloatToNullableFloat() + { + string request = @"{method:'NullableFloatToNullableFloat',params:[1.2345],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.2345,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void NullableFloatToNullableFloat3() + { + string request = @"{method:'NullableFloatToNullableFloat',params:[3.14159],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":3.14159,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + + [Test()] + public void NullableFloatToNullableFloat2() + { + string request = @"{method:'NullableFloatToNullableFloat',params:[null],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void DecimalToNullableDecimal() + { + string request = @"{method:'DecimalToNullableDecimal',params:[0.0],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":0.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void StringToListOfString() + { + string request = @"{method:'StringToListOfString',params:['some string'],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"one\",\"two\",\"three\",\"some string\"],\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void CustomStringToListOfString() + { + string request = @"{method:'CustomStringToListOfString',params:[{str:'some string'}],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"one\",\"two\",\"three\",\"some string\"],\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(result.Result, expectedResult); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void StringToThrowingException() + { + string request = @"{method:'StringToThrowingException',params:['some string'],id:1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + StringAssert.Contains("-32603", result.Result); + } + + [Test()] + public void StringToRefException() + { + string request = @"{method:'StringToRefException',params:['some string'],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"refException worked\",\"code\":-1,\"data\":null},\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(JObject.Parse(expectedResult), JObject.Parse(result.Result)); + } + + [Test()] + public void StringToThrowJsonRpcException() + { + string request = @"{method:'StringToThrowJsonRpcException',params:['some string'],id:1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + StringAssert.Contains("-2700", result.Result); + } + + [Test()] + public void ReturnsDateTime() + { + string request = @"{method:'ReturnsDateTime',params:[],id:1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + } + + [Test()] + public void ReturnsCustomRecursiveClass() + { + string request = @"{method:'ReturnsCustomRecursiveClass',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":{\"Nested1\":{\"Nested1\":null,\"Value1\":5},\"Value1\":10},\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + + [Test()] + public void FloatToFloat() + { + string request = @"{method:'FloatToFloat',params:[0.123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":0.123,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + + [Test()] + public void IntToInt() + { + string request = @"{method:'IntToInt',params:[789],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void OptionalParamInt16() + { + string request = @"{method:'TestOptionalParamInt16',params:[789],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void OptionalParamInt16NoParam() + { + string request = @"{method:'TestOptionalParamInt16',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void Int16ToInt16() + { + string request = @"{method:'Int16ToInt16',params:[789],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void Int32ToInt32() + { + string request = @"{method:'Int32ToInt32',params:[789],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":789,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void Int64ToInt64() + { + string request = @"{method:'Int64ToInt64',params:[78915984515564],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":78915984515564,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + + [Test()] + public void TestOptionalParamByteMissing() + { + string request = @"{method:'TestOptionalParambyte',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamSbyteMissing() + { + string request = @"{method:'TestOptionalParamsbyte',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamShortMissing() + { + string request = @"{method:'TestOptionalParamshort',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamintMissing() + { + string request = @"{method:'TestOptionalParamint',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamLongMissing() + { + string request = @"{method:'TestOptionalParamlong',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUshortMissing() + { + string request = @"{method:'TestOptionalParamushort',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUintMissing() + { + string request = @"{method:'TestOptionalParamuint',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUlongMissing() + { + string request = @"{method:'TestOptionalParamulong',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamFloatMissing() + { + string request = @"{method:'TestOptionalParamfloat',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamDoubleMissing() + { + string request = @"{method:'TestOptionalParamdouble',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamBoolMissing() + { + string request = @"{method:'TestOptionalParambool',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamCharMissing() + { + string request = @"{method:'TestOptionalParamchar',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"a\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamDecimalMissing() + { + string request = @"{method:'TestOptionalParamdecimal',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void TestOptionalParamBytePresent() + { + string request = @"{method:'TestOptionalParambyte',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamSbytePresent() + { + string request = @"{method:'TestOptionalParamsbyte',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamShortPresent() + { + string request = @"{method:'TestOptionalParamshort',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamintPresent() + { + string request = @"{method:'TestOptionalParamint',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamLongPresent() + { + string request = @"{method:'TestOptionalParamlong',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUshortPresent() + { + string request = @"{method:'TestOptionalParamushort',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUintPresent() + { + string request = @"{method:'TestOptionalParamuint',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUlongPresent() + { + string request = @"{method:'TestOptionalParamulong',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamFloatPresent() + { + string request = @"{method:'TestOptionalParamfloat',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamDoublePresent() + { + string request = @"{method:'TestOptionalParamdouble',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamBoolPresent() + { + string request = @"{method:'TestOptionalParambool',params:[false],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":false,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamCharPresent() + { + string request = @"{method:'TestOptionalParamchar',params:[" + (int)'b' + "],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"b\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamDecimalPresent() + { + string request = @"{method:'TestOptionalParamdecimal',params:[71],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void TestOptionalParamBytePresentObjectSyntax() + { + string request = @"{method:'TestOptionalParambyte',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamSbytePresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamsbyte',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamShortPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamshort',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamintPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamint',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamLongPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamlong',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUshortPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamushort',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUintPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamuint',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUlongPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamulong',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamFloatPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamfloat',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamDoublePresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamdouble',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamBoolPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParambool',params:{'input':false},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":false,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamCharPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamchar',params:{'input':" + (int)'c' + "},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"c\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamDecimalPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamdecimal',params:{'input':71},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":71.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void TestOptionalParamByteMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParambyte',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamSbyteMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamsbyte',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamShortMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamshort',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamintMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamint',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamLongMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamlong',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUshortMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamushort',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUintMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamuint',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUlongMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamulong',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamFloatMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamfloat',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamDoubleMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamdouble',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamBoolMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParambool',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamCharMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamchar',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"a\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamDecimalMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamdecimal',params:{},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":1.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void TestOptionalParamByte_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParambyte_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":98,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamSbyte_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamsbyte_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":126,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamShort_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamshort_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamint_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamint_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamLong_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamlong_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUshort_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamushort_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUint_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamuint_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUlong_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamulong_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamFloat_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamfloat_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamDouble_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamdouble_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamBool_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParambool_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamChar_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamchar_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamDecimal_2ndMissingObjectSyntax() + { + string request = @"{method:'TestOptionalParamdecimal_2x',params:{input1:123},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void TestOptionalParamByte_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParambyte_2x',params:{input1:123, input2: 67},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":67,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamByte_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParambyte_2x',params:[123, 67],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":67,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamByte_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParambyte_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":98,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamSbyte_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamsbyte_2x',params:{input1:123, input2: 97},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":97,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamSbyte_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamsbyte_2x',params:[123, 98],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":98,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamSbyte_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamsbyte_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":126,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamShort_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamshort_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamShort_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamshort_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamShort_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamshort_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamint_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamint_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamint_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamint_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamint_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamint_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamLong_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamlong_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamLong_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamlong_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamLong_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamlong_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUshort_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamushort_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUshort_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamushort_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUshort_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamushort_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUint_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamuint_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUint_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamuint_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUint_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamuint_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUlong_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamulong_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUlong_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamulong_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamUlong_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamulong_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamFloat_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamfloat_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamFloat_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamfloat_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamFloat_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamfloat_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamDouble_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamdouble_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamDouble_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamdouble_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamDouble_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamdouble_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamBool_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParambool_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamBool_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParambool_2x',params:[true, false],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":false,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamBool_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParambool_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamChar_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamchar_2x',params:{'input1':" + (int)'c' + ", 'input2':" + (int)'d' + "},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamChar_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamchar_2x',params:[" + (int)'c' + ", " + (int)'d' + "],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamChar_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamchar_2x',params:[" + (int)'c' + "],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"d\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamDecimal_2ndPresentObjectSyntax() + { + string request = @"{method:'TestOptionalParamdecimal_2x',params:{input1:123, input2: 671},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamDecimal_2ndPresentArraySyntax() + { + string request = @"{method:'TestOptionalParamdecimal_2x',params:[123, 671],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":671.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + [Test()] + public void TestOptionalParamDecimal_2ndMissingArraySyntax() + { + string request = @"{method:'TestOptionalParamdecimal_2x',params:[123],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":987.0,\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void TestOptionalParametersStrings_BothMissing() + { + string request = @"{method:'TestOptionalParameters_Strings',params:[],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[null,null],\"id\":1}"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void TestOptionalParametersStrings_SecondMissing() + { + string request = @"{method:'TestOptionalParameters_Strings',params:['first'],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"first\",null],\"id\":1}"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void TestOptionalParametersStrings_BothExists() + { + string request = @"{method:'TestOptionalParameters_Strings',params:['first','second'],id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[\"first\",\"second\"],\"id\":1}"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void TestOptionalParametersBoolsAndStrings() + { + string request = + "{\"jsonrpc\":\"2.0\",\"method\":\"TestOptionalParametersBoolsAndStrings\",\"params\":{\"input1\":\"murkel\"},\"Id\":1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":true,\"id\":1}"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsFalse(result.Result.Contains("error")); + Assert.AreEqual(expectedResult, result.Result); + } + + [Test()] + public void TestBatchResultWrongRequests() + { + string request = @"[{},{""jsonrpc"":""2.0"",""id"":4}]"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + + Assert.IsTrue(Regex.IsMatch(result.Result, @"\[(\{.*""error"":.*?,""id"":.*?\}),(\{.*""error"":.*?,""id"":.*?\})\]"), "Should have two errors."); + } + + [Test()] + public void TestBatchResultMultipleMethodCallsNotificationAtLast() + { + string request = + @"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}]"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + + Assert.IsFalse(result.Result.EndsWith(@",]"), "result.Result.EndsWith(@',]')"); + + } + + [Test()] + public void TestEmptyBatchResult() + { + var secondRequest = @"{""jsonrpc"":""2.0"",""method"":""Notify"",""params"":[""Hello World!""]}"; + var result = JsonRpcProcessor.Process(secondRequest); + result.Wait(); + + Assert.IsTrue(string.IsNullOrEmpty(result.Result)); + } + + [Test()] + public void TestLeftOutParams() + { + var request = + @"{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""id"":1}"; + + var result = JsonRpcProcessor.Process(request); + result.Wait(); + + Assert.IsFalse(result.Result.Contains(@"error"":{""code"":-32602"), @"According to JSON-RPC 2.0 the ""params"" member MAY be omitted."); + } + + [Test()] + public void TestMultipleResults() + { + var result = + JsonRpcProcessor.Process( + @"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1},{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]"); + result.Wait(); + + Assert.IsTrue(result.Result.EndsWith("]")); + } + + [Test()] + public void TestSingleResultBatch() + { + var result = + JsonRpcProcessor.Process(@"[{""jsonrpc"":""2.0"",""method"":""ReturnsDateTime"",""params"":{},""id"":1}]"); + result.Wait(); + Assert.IsFalse(result.Result.EndsWith("]")); + } + + class PreProcessHandlerLocal + { + public JsonRequest rpc = null; + public object context = null; + public int run = 0; + + public JsonRpcException PreProcess(JsonRequest rpc, object context) + { + run++; + + this.rpc = rpc; + this.context = context; + + return null; + } + } + + [Test()] + public void TestPreProcessor() + { + try { + PreProcessHandlerLocal handler = new PreProcessHandlerLocal(); + Config.SetPreProcessHandler(new PreProcessHandler(handler.PreProcess)); + string request = @"{method:'TestPreProcessor',params:{inputValue:'some string'},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"Success!\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + AssertJsonAreEqual(expectedResult, result.Result); + Assert.AreEqual(1, handler.run); + Assert.NotNull(handler.rpc, "RPC should not be null"); + Assert.Null(handler.context, "Context should be null"); + } finally { + Config.SetPreProcessHandler(null); + } + + } + + [Test()] + public void TestPreProcessorThrowsJsonRPCException() + { + try + { + PreProcessHandlerLocal handler = new PreProcessHandlerLocal(); + Config.SetPreProcessHandler(new PreProcessHandler(handler.PreProcess)); + string request = @"{method:'TestPreProcessorThrowsJsonRPCException',params:{inputValue:'some string'},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-27000,\"message\":\"Just some testing\",\"data\":null},\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + AssertJsonAreEqual(expectedResult, result.Result); + Assert.AreEqual(1, handler.run); + Assert.NotNull(handler.rpc, "RPC should not be null"); + Assert.Null(handler.context, "Context should be null"); + } + finally + { + Config.SetPreProcessHandler(null); + } + } + + [Test()] + public void TestPreProcessorThrowsException() + { + try + { + PreProcessHandlerLocal handler = new PreProcessHandlerLocal(); + Config.SetPreProcessHandler(new PreProcessHandler(handler.PreProcess)); + string request = @"{method:'TestPreProcessorThrowsException',params:{inputValue:'some string'},id:1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + StringAssert.Contains("-32603", result.Result); + Assert.AreEqual(1, handler.run); + Assert.NotNull(handler.rpc, "RPC should not be null"); + Assert.Null(handler.context, "Context should be null"); + } + finally + { + Config.SetPreProcessHandler(null); + } + } + + [Test()] + public void TestPreProcessorSetsException() + { + try + { + PreProcessHandlerLocal handler = new PreProcessHandlerLocal(); + Config.SetPreProcessHandler(new PreProcessHandler(handler.PreProcess)); + string request = @"{method:'TestPreProcessorSetsException',params:{inputValue:'some string'},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-27000,\"message\":\"This exception was thrown using: JsonRpcContext.SetException()\",\"data\":null},\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + AssertJsonAreEqual(expectedResult, result.Result); + Assert.AreEqual(1, handler.run); + Assert.NotNull(handler.rpc, "RPC should not be null"); + Assert.Null(handler.context, "Context should be null"); + } + finally + { + Config.SetPreProcessHandler(null); + } + } + + [Test()] + public void TestPreProcessOnSession() + { + var sessionId = "my session"; + var h = JsonRpc.Handler.GetSessionHandler(sessionId); + PreProcessHandlerLocal preHandler = new PreProcessHandlerLocal(); + h.SetPreProcessHandler(new PreProcessHandler(preHandler.PreProcess)); + + h.Register("workie", new Func(x => "workie ... " + x)); + + var metadata = new System.Collections.Generic.List> { + Tuple.Create ("sooper", typeof(string)), + Tuple.Create ("returns", typeof(string)) + }.ToDictionary(x => x.Item1, x => x.Item2); + h.MetaData.AddService("workie", metadata, new System.Collections.Generic.Dictionary()); + + string request = @"{method:'workie',params:{'sooper':'good'},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"workie ... good\",\"id\":1}"; + string expectedResultAfterDestroy = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"Method not found\",\"code\":-32601,\"data\":\"The method does not exist / is not available.\"},\"id\":1}"; + var result = JsonRpcProcessor.Process(sessionId, request); + result.Wait(); + + var actual1 = JObject.Parse(result.Result); + var expected1 = JObject.Parse(expectedResult); + Assert.AreEqual(expected1, actual1); + Assert.AreEqual(1, preHandler.run); + + h.Destroy(); + + var result2 = JsonRpcProcessor.Process(sessionId, request); + result2.Wait(); + + Assert.AreEqual(1, preHandler.run); + Assert.AreEqual(JObject.Parse(expectedResultAfterDestroy), JObject.Parse(result2.Result)); + } + + class PostProcessHandlerLocal + { + public JsonRequest rpc = null; + public JsonResponse response = null; + public object context = null; + public int run = 0; + private bool changeResponse_; + + public PostProcessHandlerLocal(bool changeResponse) + { + changeResponse_ = changeResponse; + } + + public JsonRpcException PostProcess(JsonRequest rpc, JsonResponse response, object context) + { + run++; + + this.rpc = rpc; + this.response = response; + this.context = context; + + if (changeResponse_) + { + return new JsonRpcException(-123, "Test error", null); + } + return null; + } + } + + [Test()] + public void TestPostProcessor() + { + try + { + PostProcessHandlerLocal handler = new PostProcessHandlerLocal(false); + Config.SetPostProcessHandler(new PostProcessHandler(handler.PostProcess)); + string request = @"{method:'TestPostProcessor',params:{inputValue:'some string'},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"Success!\",\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + AssertJsonAreEqual(expectedResult, result.Result); + Assert.AreEqual(1, handler.run, "Expect number of times run 1"); + Assert.NotNull(handler.rpc, "RPC should not be null"); + Assert.NotNull(handler.response, "response should not be null"); + Assert.AreEqual("Success!", (string)handler.response.Result); + Assert.Null(handler.context, "Context should be null"); + } + finally + { + Config.SetPostProcessHandler(null); + } + } + + [Test()] + public void TestPostProcessorThrowsJsonRPCException() + { + try + { + PostProcessHandlerLocal handler = new PostProcessHandlerLocal(false); + Config.SetPostProcessHandler(new PostProcessHandler(handler.PostProcess)); + string request = @"{method:'TestPostProcessorThrowsJsonRPCException',params:{inputValue:'some string'},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-27000,\"message\":\"Just some testing\",\"data\":null},\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + AssertJsonAreEqual(expectedResult, result.Result); + Assert.AreEqual(1, handler.run); + Assert.NotNull(handler.rpc, "RPC should not be null"); + Assert.NotNull(handler.response, "response should not be null"); + Assert.Null(handler.response.Result, "Result should be null"); + Assert.NotNull(handler.response.Error, "Error should not be null"); + Assert.AreEqual(-27000, handler.response.Error.code, "Error code mismatch"); + Assert.AreEqual("Just some testing", handler.response.Error.message, "Error message mismatch"); + Assert.Null(handler.context, "Context should be null"); + } + finally + { + Config.SetPostProcessHandler(null); + } + } + + [Test()] + public void TestPostProcessorThrowsException() + { + try + { + PostProcessHandlerLocal handler = new PostProcessHandlerLocal(false); + Config.SetPostProcessHandler(new PostProcessHandler(handler.PostProcess)); + string request = @"{method:'TestPostProcessorThrowsException',params:{inputValue:'some string'},id:1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + StringAssert.Contains("-32603", result.Result); + Assert.AreEqual(1, handler.run); + Assert.NotNull(handler.rpc, "RPC should not be null"); + Assert.NotNull(handler.response, "response should not be null"); + Assert.Null(handler.response.Result, "Result should be null"); + Assert.NotNull(handler.response.Error, "Error should not be null"); + Assert.AreEqual(-32603, handler.response.Error.code, "Error code mismatch"); + Assert.Null(handler.context, "Context should be null"); + } + finally + { + Config.SetPostProcessHandler(null); + } + } + + [Test()] + public void TestPostProcessorSetsException() + { + try + { + PostProcessHandlerLocal handler = new PostProcessHandlerLocal(false); + Config.SetPostProcessHandler(new PostProcessHandler(handler.PostProcess)); + string request = @"{method:'TestPostProcessorSetsException',params:{inputValue:'some string'},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-27001,\"message\":\"This exception was thrown using: JsonRpcContext.SetException()\",\"data\":null},\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + AssertJsonAreEqual(expectedResult, result.Result); + Assert.AreEqual(1, handler.run); + Assert.NotNull(handler.rpc, "RPC should not be null"); + Assert.Null(handler.context, "Context should be null"); + } + finally + { + Config.SetPreProcessHandler(null); + } + } + + + [Test()] + public void TestPostProcessorChangesReturn() + { + try + { + PostProcessHandlerLocal handler = new PostProcessHandlerLocal(true); + Config.SetPostProcessHandler(new PostProcessHandler(handler.PostProcess)); + string request = @"{method:'TestPostProcessor',params:{inputValue:'some string'},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-123,\"message\":\"Test error\",\"data\":null},\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + AssertJsonAreEqual(expectedResult, result.Result); + Assert.AreEqual(1, handler.run); + Assert.AreEqual(1, handler.run, "Expect number of times run 1"); + Assert.NotNull(handler.rpc, "RPC should not be null"); + Assert.NotNull(handler.response, "response should not be null"); + Assert.AreEqual("Success!", (string)handler.response.Result); + Assert.Null(handler.context, "Context should be null"); + } + finally + { + Config.SetPostProcessHandler(null); + } + } + + [Test()] + public void TestPostProcessorThrowsJsonRPCExceptionChangesReturn() + { + try + { + PostProcessHandlerLocal handler = new PostProcessHandlerLocal(true); + Config.SetPostProcessHandler(new PostProcessHandler(handler.PostProcess)); + string request = @"{method:'TestPostProcessorThrowsJsonRPCException',params:{inputValue:'some string'},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-123,\"message\":\"Test error\",\"data\":null},\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + AssertJsonAreEqual(expectedResult, result.Result); + Assert.AreEqual(1, handler.run); + Assert.NotNull(handler.rpc, "RPC should not be null"); + Assert.NotNull(handler.response, "response should not be null"); + Assert.Null(handler.response.Result, "Result should be null"); + Assert.NotNull(handler.response.Error, "Error should not be null"); + Assert.AreEqual(-27000, handler.response.Error.code, "Error code mismatch"); + Assert.AreEqual("Just some testing", handler.response.Error.message, "Error message mismatch"); + Assert.Null(handler.context, "Context should be null"); + } + finally + { + Config.SetPostProcessHandler(null); + } + } + + [Test()] + public void TestPostProcessorThrowsExceptionChangesReturn() + { + try + { + PostProcessHandlerLocal handler = new PostProcessHandlerLocal(true); + Config.SetPostProcessHandler(new PostProcessHandler(handler.PostProcess)); + string request = @"{method:'TestPostProcessorThrowsException',params:{inputValue:'some string'},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"Test error\",\"code\":-123,\"data\":null},\"id\":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + AssertJsonAreEqual(expectedResult, result.Result); + Assert.AreEqual(1, handler.run); + Assert.NotNull(handler.rpc, "RPC should not be null"); + Assert.NotNull(handler.response, "response should not be null"); + Assert.Null(handler.response.Result, "Result should be null"); + Assert.NotNull(handler.response.Error, "Error should not be null"); + Assert.AreEqual(-32603, handler.response.Error.code, "Error code mismatch"); + Assert.Null(handler.context, "Context should be null"); + } + finally + { + Config.SetPostProcessHandler(null); + } + } + + [Test()] + public void TestPostProcessOnSession() + { + var sessionId = "my first session"; + var h = JsonRpc.Handler.GetSessionHandler(sessionId); + PostProcessHandlerLocal postHandler = new PostProcessHandlerLocal(false); + h.SetPostProcessHandler(new PostProcessHandler(postHandler.PostProcess)); + + h.Register("workie", new Func(x => "workie ... " + x)); + + var metadata = new System.Collections.Generic.List> { + Tuple.Create ("sooper", typeof(string)), + Tuple.Create ("returns", typeof(string)) + }.ToDictionary(x => x.Item1, x => x.Item2); + h.MetaData.AddService("workie", metadata, new System.Collections.Generic.Dictionary()); + + string request = @"{method:'workie',params:{'sooper':'good'},id:1}"; + string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"workie ... good\",\"id\":1}"; + string expectedResultAfterDestroy = "{\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"Method not found\",\"code\":-32601,\"data\":\"The method does not exist / is not available.\"},\"id\":1}"; + var result = JsonRpcProcessor.Process(sessionId, request); + result.Wait(); + + var actual1 = JObject.Parse(result.Result); + var expected1 = JObject.Parse(expectedResult); + Assert.AreEqual(expected1, actual1); + Assert.AreEqual(1, postHandler.run); + + h.Destroy(); + + var result2 = JsonRpcProcessor.Process(sessionId, request); + result2.Wait(); + + Assert.AreEqual(1, postHandler.run); + Assert.AreEqual(JObject.Parse(expectedResultAfterDestroy), JObject.Parse(result2.Result)); + } + + private static void AssertJsonAreEqual(string expectedJson, string actualJson) + { + Newtonsoft.Json.Linq.JObject expected = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(expectedJson); + Newtonsoft.Json.Linq.JObject actual = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(actualJson); + AssertJsonAreEqual(expected, actual, "root"); + } + + private static void AssertJsonAreEqual(JToken expectedJson, JToken actualJson, string path) + { + Assert.AreEqual(expectedJson.GetType(), actualJson.GetType(), "Type mismatch at " + path); + if (expectedJson is JObject) + { + AssertJsonAreEqual((JObject)expectedJson, (JObject)actualJson, path); + } else if (expectedJson is JObject) + { + AssertJsonAreEqual((JArray)expectedJson, (JArray)actualJson, path); + } else if (expectedJson is JValue) + { + AssertJsonAreEqual((JValue)expectedJson, (JValue)actualJson, path); + } else + { + throw new Exception("I don't know how to handle " + expectedJson.GetType().ToString()); + } + } + + private static void AssertJsonAreEqual(JObject expectedJson, JObject actualJson, string path) + { + Assert.AreEqual(expectedJson.Count, actualJson.Count, "Count of json object at " + path); + for (var expectedElementsEnumerator = expectedJson.GetEnumerator(); expectedElementsEnumerator.MoveNext(); ) + { + JToken actualElement = null; + Assert.IsTrue(actualJson.TryGetValue(expectedElementsEnumerator.Current.Key, out actualElement), "Couldn't find " + path + "[" + expectedElementsEnumerator.Current.Key + "]"); + AssertJsonAreEqual(expectedElementsEnumerator.Current.Value, actualElement, path + "[" + expectedElementsEnumerator.Current.Key + "]"); + } + } + + private static void AssertJsonAreEqual(JArray expectedJson, JArray actualJson, string path) + { + Assert.AreEqual(expectedJson.Count, actualJson.Count, "Count of json array at " + path); + for (int jsonIndex = 0; jsonIndex < expectedJson.Count; jsonIndex++) + { + AssertJsonAreEqual(expectedJson[jsonIndex], actualJson[jsonIndex], path + "[" + jsonIndex.ToString() + "]"); + } + } + + private static void AssertJsonAreEqual(JValue expectedJson, JValue actualJson, string path) + { + Assert.AreEqual(expectedJson.Type, actualJson.Type, path); + switch (expectedJson.Type) + { + case JTokenType.Boolean: + Assert.AreEqual((bool)expectedJson.Value, (bool)actualJson.Value, path); + break; + case JTokenType.Integer: + Assert.AreEqual((System.Int64)expectedJson.Value, (System.Int64)actualJson.Value, path); + break; + case JTokenType.String: + Assert.AreEqual((string)expectedJson.Value, (string)actualJson.Value, path); + break; + case JTokenType.Null: + //Not used + break; + default: + throw new Exception("I don't know how to handle type " + expectedJson.Type.ToString()); + } + } + } } diff --git a/AustinHarris.JsonRpcTestN/service.cs b/AustinHarris.JsonRpcTestN/service.cs index ddbad98..649696d 100644 --- a/AustinHarris.JsonRpcTestN/service.cs +++ b/AustinHarris.JsonRpcTestN/service.cs @@ -292,6 +292,7 @@ private IList TestOptionalParameters_Strings(string input1 = null, strin input2 }; } + [JsonRpcMethod] public bool TestOptionalParametersBoolsAndStrings(string input1, bool input2 = true, string input3 = "") { @@ -303,5 +304,55 @@ public void Notify(string message) { Trace.WriteLine(string.Format("Notified about: {0}", message)); } + + [JsonRpcMethod] + public string TestPreProcessor(string inputValue) + { + return "Success!"; + } + + [JsonRpcMethod] + public string TestPreProcessorThrowsJsonRPCException(string inputValue) + { + throw new JsonRpcException(-27000, "Just some testing", null); + } + + [JsonRpcMethod] + public string TestPreProcessorThrowsException(string inputValue) + { + throw new Exception("TestException"); + } + + [JsonRpcMethod] + public string TestPreProcessorSetsException(string inputValue) + { + JsonRpcContext.SetException(new JsonRpcException(-27000, "This exception was thrown using: JsonRpcContext.SetException()", null)); + return null; + } + + [JsonRpcMethod] + public string TestPostProcessor(string inputValue) + { + return "Success!"; + } + + [JsonRpcMethod] + public string TestPostProcessorThrowsJsonRPCException(string inputValue) + { + throw new JsonRpcException(-27000, "Just some testing", null); + } + + [JsonRpcMethod] + public string TestPostProcessorThrowsException(string inputValue) + { + throw new Exception("TestException"); + } + + [JsonRpcMethod] + public string TestPostProcessorSetsException(string inputValue) + { + JsonRpcContext.SetException(new JsonRpcException(-27001, "This exception was thrown using: JsonRpcContext.SetException()", null)); + return null; + } } } diff --git a/Json-Rpc/Config.cs b/Json-Rpc/Config.cs index 5c2c1e7..9e6692e 100644 --- a/Json-Rpc/Config.cs +++ b/Json-Rpc/Config.cs @@ -13,6 +13,16 @@ namespace AustinHarris.JsonRpc /// The context associated with this request /// Any non-null result causes the operation to be aborted, and the JsonRpcException is returned to the caller. public delegate JsonRpcException PreProcessHandler(JsonRequest request, object context); + /// + /// The PostProcessHandler is called after the response has been created and prior to returning the data to the caller. + /// If any non-null result is returned from the PostProcessHandler, the current return value is discared and the new return value used + /// in preference. + /// + /// The jsonRpc Request that has been processed. + /// The jsonRpc Response that has been created. + /// The context associated with this request/response pair + /// Any non-null result causes the result to be discarded and the JsonRpcException is returned to the caller. + public delegate JsonRpcException PostProcessHandler(JsonRequest request, JsonResponse response, object context); /// /// Global configurations for JsonRpc @@ -28,6 +38,15 @@ public static void SetPreProcessHandler(PreProcessHandler handler) Handler.DefaultHandler.SetPreProcessHandler(handler); } + /// + /// Sets the the PostProcessing Handler on the default session. + /// + /// + public static void SetPostProcessHandler(PostProcessHandler handler) + { + Handler.DefaultHandler.SetPostProcessHandler(handler); + } + /// /// Sets the PreProcessing Handler on a specific session /// diff --git a/Json-Rpc/Handler.cs b/Json-Rpc/Handler.cs index db2dadc..4f2c43f 100644 --- a/Json-Rpc/Handler.cs +++ b/Json-Rpc/Handler.cs @@ -139,6 +139,7 @@ private void RemoveRpcException() } private AustinHarris.JsonRpc.PreProcessHandler externalPreProcessingHandler; + private AustinHarris.JsonRpc.PostProcessHandler externalPostProcessingHandler; private Func externalErrorHandler; private Func parseErrorHandler; private Dictionary Handlers { get; set; } @@ -185,12 +186,6 @@ public void UnRegister(string key) /// public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null, Action callback = null) { - //empty delegate declaration if callback is not provided - if (null == callback) - { - callback = delegate(JsonResponse a) { }; - } - AddRpcContext(RpcContext); var preProcessingException = PreProcess(Rpc, RpcContext); @@ -202,9 +197,8 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null, Action callback, JsonRequest request, JsonResponse response, object context) + { + if (externalPostProcessingHandler != null) + { + try + { + JsonRpcException exception = externalPostProcessingHandler(request, response, context); + if (exception != null) + { + response = new JsonResponse() { Error = exception }; + } + } + catch (Exception ex) + { + response = new JsonResponse() { Error = ProcessException(request, new JsonRpcException(-32603, "Internal Error", ex)) }; + } + } + + if (callback != null) + callback.Invoke(response); + + return response; + } + + public void SetPreProcessHandler(AustinHarris.JsonRpc.PreProcessHandler handler) { externalPreProcessingHandler = handler; } + + public void SetPostProcessHandler(AustinHarris.JsonRpc.PostProcessHandler handler) + { + externalPostProcessingHandler = handler; + } } } From 1439d8ffcee80bcf34770c9994240649aa2977e6 Mon Sep 17 00:00:00 2001 From: Christopher Dawes Date: Sat, 9 Apr 2016 18:26:47 +0100 Subject: [PATCH 46/81] When there were too many arguments you'd get an index out of bounds exception rather than the nicer -32602 error that should be had --- AustinHarris.JsonRpcTestN/Test.cs | 10 ++++++++++ Json-Rpc/Handler.cs | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/AustinHarris.JsonRpcTestN/Test.cs b/AustinHarris.JsonRpcTestN/Test.cs index a513c7d..45b769a 100644 --- a/AustinHarris.JsonRpcTestN/Test.cs +++ b/AustinHarris.JsonRpcTestN/Test.cs @@ -1852,6 +1852,16 @@ public void TestPostProcessOnSession() Assert.AreEqual(JObject.Parse(expectedResultAfterDestroy), JObject.Parse(result2.Result)); } + [Test()] + public void TestExtraParameters() + { + string request = @"{method:'ReturnsDateTime',params:{extra:'mytext'},id:1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.IsTrue(result.Result.Contains("error")); + Assert.IsTrue(result.Result.Contains("\"code\":-32602")); + } + private static void AssertJsonAreEqual(string expectedJson, string actualJson) { Newtonsoft.Json.Linq.JObject expected = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(expectedJson); diff --git a/Json-Rpc/Handler.cs b/Json-Rpc/Handler.cs index 4f2c43f..9922f95 100644 --- a/Json-Rpc/Handler.cs +++ b/Json-Rpc/Handler.cs @@ -261,7 +261,7 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null, Action; - for (int i = 0; i < loopCt; i++) + for (int i = 0; i < loopCt && i < metadata.parameters.Length; i++) { if (asDict.ContainsKey(metadata.parameters[i].Name) == false) { From b9f435a38e051550aea12da79b3857740d3c8c04 Mon Sep 17 00:00:00 2001 From: Martin Daetz Date: Wed, 27 Apr 2016 16:58:06 +0200 Subject: [PATCH 47/81] solve recursive type issue --- Json-Rpc/SMDService.cs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/Json-Rpc/SMDService.cs b/Json-Rpc/SMDService.cs index 0487a36..2c3fa8b 100644 --- a/Json-Rpc/SMDService.cs +++ b/Json-Rpc/SMDService.cs @@ -42,19 +42,24 @@ public void AddService(string method, Dictionary parameters, Dictio public static int AddType(JObject jo) { - var hash = "t_" + jo.ToString().GetHashCode(); + var hash = string.Format("t_{0}", jo.ToString().GetHashCode()); + lock (TypeHashes) - { - var idx = 0; - if (TypeHashes.Contains(hash) == false) - { - TypeHashes.Add(hash); - idx = TypeHashes.IndexOf(hash); - Types.Add(idx, jo); - } + { + if (TypeHashes.Contains(hash)) return TypeHashes.IndexOf(hash); + + TypeHashes.Add(hash); + var idx = TypeHashes.IndexOf(hash); + Types.Add(idx, jo); } + return TypeHashes.IndexOf(hash); } + + public static bool ContainsType(JObject jo) + { + return TypeHashes.Contains(string.Format("t_{0}", jo.ToString().GetHashCode())); + } } public class SMDService @@ -163,11 +168,14 @@ internal static int GetTypeRecursive(Type t) { JObject jo = new JObject(); jo.Add("__name", t.Name.ToLower()); - if (isSimpleType(t)) + + if (isSimpleType(t) || SMD.ContainsType(jo)) { return SMD.AddType(jo); } + var retVal = SMD.AddType(jo); + var genArgs = t.GetGenericArguments(); PropertyInfo[] properties = t.GetProperties(); FieldInfo[] fields = t.GetFields(); @@ -225,7 +233,7 @@ internal static int GetTypeRecursive(Type t) } } - return SMD.AddType(jo); + return retVal; } internal static bool isSimpleType(Type t) From bf97f1fdbc185bd87a5d0ceab43c5865fcc85eee Mon Sep 17 00:00:00 2001 From: Martin Daetz Date: Thu, 28 Apr 2016 10:11:33 +0200 Subject: [PATCH 48/81] add unit test --- AustinHarris.JsonRpcTestN/Test.cs | 10 ++++++++++ AustinHarris.JsonRpcTestN/service.cs | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/AustinHarris.JsonRpcTestN/Test.cs b/AustinHarris.JsonRpcTestN/Test.cs index 45b769a..2a53969 100644 --- a/AustinHarris.JsonRpcTestN/Test.cs +++ b/AustinHarris.JsonRpcTestN/Test.cs @@ -1862,6 +1862,16 @@ public void TestExtraParameters() Assert.IsTrue(result.Result.Contains("\"code\":-32602")); } + [Test] + public void TestNestedReturnType() + { + var request = @"{""jsonrpc"":""2.0"",""method"":""TestNestedReturnType"",""id"":1}"; + var expected = @"{""jsonrpc"":""2.0"",""result"":{""NodeId"":1,""Leafs"":[{""NodeId"":2,""Leafs"":[]},{""NodeId"":3,""Leafs"":[]}]},""id"":1}"; + var result = JsonRpcProcessor.Process(request); + result.Wait(); + Assert.AreEqual(expected, result.Result); + } + private static void AssertJsonAreEqual(string expectedJson, string actualJson) { Newtonsoft.Json.Linq.JObject expected = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(expectedJson); diff --git a/AustinHarris.JsonRpcTestN/service.cs b/AustinHarris.JsonRpcTestN/service.cs index 649696d..5da391f 100644 --- a/AustinHarris.JsonRpcTestN/service.cs +++ b/AustinHarris.JsonRpcTestN/service.cs @@ -7,6 +7,13 @@ namespace AustinHarris.JsonRpcTestN { + public class TreeNode + { + public int NodeId { get; set; } + + public IList Leafs { get; set; } + } + public class CalculatorService : JsonRpcService { [JsonRpcMethod] @@ -354,5 +361,21 @@ public string TestPostProcessorSetsException(string inputValue) JsonRpcContext.SetException(new JsonRpcException(-27001, "This exception was thrown using: JsonRpcContext.SetException()", null)); return null; } + + [JsonRpcMethod] + public TreeNode TestNestedReturnType() + { + return new TreeNode + { + NodeId = 1, + Leafs = + new[] + { + new TreeNode {NodeId = 2, Leafs = new List()}, + new TreeNode {NodeId = 3, Leafs = new List()} + } + }; + } + } } From 94bb7714b32c99810e41d55bc19f55f8fec7690d Mon Sep 17 00:00:00 2001 From: Steven Schobert Date: Fri, 17 Jun 2016 09:16:12 -0500 Subject: [PATCH 49/81] Update package name in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ac873c..5ba55be 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ PM> Install-Package AustinHarris.JsonRpc To install JSON-RPC.NET AspNet, run the following command in the Package Manager Console ``` -PM> Install-Package AustinHarris.AspNet +PM> Install-Package AustinHarris.JsonRpc.AspNet ``` ##### Performance From ef1be5f449d215b43ec7e70c3a0c2c56b652157d Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Sat, 5 Nov 2016 22:27:18 -0600 Subject: [PATCH 50/81] Simplify a few portions of the code. --- .../AustinHarris.JsonRpc.AspNet.csproj | 4 +- AustinHarris.JsonRpc.AspNet/packages.config | 2 +- AustinHarris.JsonRpc.sln | 63 +++++++------ .../AustinHarris.JsonRpcTestN.csproj | 4 +- AustinHarris.JsonRpcTestN/Test.cs | 13 +-- AustinHarris.JsonRpcTestN/packages.config | 2 +- Json-Rpc/AustinHarris.JsonRpc.csproj | 10 +-- Json-Rpc/Handler.cs | 29 ++---- Json-Rpc/JsonRpcProcessor.cs | 19 +--- Json-Rpc/SMDService.cs | 8 +- Json-Rpc/ServiceBinder.cs | 4 +- Json-Rpc/packages.config | 4 +- TestServer_Console/TestServer_Console.csproj | 9 +- TestServer_Console/packages.config | 4 +- TestServer_Console/service.cs | 90 +++++++++++++++++++ 15 files changed, 159 insertions(+), 106 deletions(-) diff --git a/AustinHarris.JsonRpc.AspNet/AustinHarris.JsonRpc.AspNet.csproj b/AustinHarris.JsonRpc.AspNet/AustinHarris.JsonRpc.AspNet.csproj index bf84656..134986f 100644 --- a/AustinHarris.JsonRpc.AspNet/AustinHarris.JsonRpc.AspNet.csproj +++ b/AustinHarris.JsonRpc.AspNet/AustinHarris.JsonRpc.AspNet.csproj @@ -36,8 +36,8 @@ 4 - - ..\packages\Newtonsoft.Json.8.0.2\lib\net40\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll True diff --git a/AustinHarris.JsonRpc.AspNet/packages.config b/AustinHarris.JsonRpc.AspNet/packages.config index 28e5e44..7c276ed 100644 --- a/AustinHarris.JsonRpc.AspNet/packages.config +++ b/AustinHarris.JsonRpc.AspNet/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/AustinHarris.JsonRpc.sln b/AustinHarris.JsonRpc.sln index 3fa6f16..858a102 100644 --- a/AustinHarris.JsonRpc.sln +++ b/AustinHarris.JsonRpc.sln @@ -1,12 +1,13 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 -VisualStudioVersion = 12.0.30723.0 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BBFBBA8A-2F75-422C-ACCD-D05A6EF7244C}" ProjectSection(SolutionItems) = preProject AustinHarris.JsonRpc.vsmdi = AustinHarris.JsonRpc.vsmdi Local.testsettings = Local.testsettings + Performance1.psess = Performance1.psess TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings EndProjectSection EndProject @@ -44,22 +45,18 @@ Global {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|Mixed Platforms.Build.0 = Release|x86 {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|x86.ActiveCfg = Release|x86 {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|x86.Build.0 = Release|x86 - {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|ARM.ActiveCfg = Debug|Any CPU - {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|ARM.Build.0 = Debug|Any CPU - {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|x86.ActiveCfg = Debug|x86 - {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|x86.Build.0 = Debug|x86 - {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|Any CPU.Build.0 = Release|Any CPU - {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|ARM.ActiveCfg = Release|Any CPU - {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|ARM.Build.0 = Release|Any CPU - {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|x86.ActiveCfg = Release|x86 - {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|x86.Build.0 = Release|x86 + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|ARM.ActiveCfg = Debug|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|x86.ActiveCfg = Debug|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Any CPU.Build.0 = Release|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|ARM.ActiveCfg = Release|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|x86.ActiveCfg = Release|Any CPU {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Debug|Any CPU.Build.0 = Debug|Any CPU {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Debug|ARM.ActiveCfg = Debug|Any CPU @@ -76,20 +73,22 @@ Global {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Release|Mixed Platforms.Build.0 = Release|Any CPU {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Release|x86.ActiveCfg = Release|Any CPU {8569B076-5A8B-4D6A-B75D-EF75A390AA5F}.Release|x86.Build.0 = Release|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|ARM.ActiveCfg = Debug|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Debug|x86.ActiveCfg = Debug|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Any CPU.Build.0 = Release|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|ARM.ActiveCfg = Release|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {FFFDEBBC-93F5-4A22-9EC5-D86A4A792DBB}.Release|x86.ActiveCfg = Release|Any CPU - EndGlobalSection - GlobalSection(NestedProjects) = preSolution + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|ARM.ActiveCfg = Debug|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|ARM.Build.0 = Debug|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|x86.ActiveCfg = Debug|x86 + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Debug|x86.Build.0 = Debug|x86 + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|Any CPU.Build.0 = Release|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|ARM.ActiveCfg = Release|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|ARM.Build.0 = Release|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|x86.ActiveCfg = Release|x86 + {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj index 0c4bd29..fe8c6d8 100644 --- a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj +++ b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj @@ -30,8 +30,8 @@ false - - ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True diff --git a/AustinHarris.JsonRpcTestN/Test.cs b/AustinHarris.JsonRpcTestN/Test.cs index 2a53969..6c53676 100644 --- a/AustinHarris.JsonRpcTestN/Test.cs +++ b/AustinHarris.JsonRpcTestN/Test.cs @@ -64,14 +64,11 @@ public void TestCanCreateMultipleServicesOfSameTypeInTheirOwnSessions() public void TestCanCreateAndRemoveSession() { var h = JsonRpc.Handler.GetSessionHandler("this one"); - - h.Register("workie", new Func(x => "workie ... " + x)); - var metadata = new System.Collections.Generic.List> { Tuple.Create ("sooper", typeof(string)), Tuple.Create ("returns", typeof(string)) }.ToDictionary(x => x.Item1, x => x.Item2); - h.MetaData.AddService("workie", metadata, new System.Collections.Generic.Dictionary()); + h.MetaData.AddService("workie", metadata, new System.Collections.Generic.Dictionary(),new Func(x => "workie ... " + x)); string request = @"{method:'workie',params:{'sooper':'good'},id:1}"; string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"workie ... good\",\"id\":1}"; @@ -1582,13 +1579,11 @@ public void TestPreProcessOnSession() PreProcessHandlerLocal preHandler = new PreProcessHandlerLocal(); h.SetPreProcessHandler(new PreProcessHandler(preHandler.PreProcess)); - h.Register("workie", new Func(x => "workie ... " + x)); - var metadata = new System.Collections.Generic.List> { Tuple.Create ("sooper", typeof(string)), Tuple.Create ("returns", typeof(string)) }.ToDictionary(x => x.Item1, x => x.Item2); - h.MetaData.AddService("workie", metadata, new System.Collections.Generic.Dictionary()); + h.MetaData.AddService("workie", metadata, new System.Collections.Generic.Dictionary(),new Func(x => "workie ... " + x)); string request = @"{method:'workie',params:{'sooper':'good'},id:1}"; string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"workie ... good\",\"id\":1}"; @@ -1824,13 +1819,11 @@ public void TestPostProcessOnSession() PostProcessHandlerLocal postHandler = new PostProcessHandlerLocal(false); h.SetPostProcessHandler(new PostProcessHandler(postHandler.PostProcess)); - h.Register("workie", new Func(x => "workie ... " + x)); - var metadata = new System.Collections.Generic.List> { Tuple.Create ("sooper", typeof(string)), Tuple.Create ("returns", typeof(string)) }.ToDictionary(x => x.Item1, x => x.Item2); - h.MetaData.AddService("workie", metadata, new System.Collections.Generic.Dictionary()); + h.MetaData.AddService("workie", metadata, new System.Collections.Generic.Dictionary(), new Func(x => "workie ... " + x)); string request = @"{method:'workie',params:{'sooper':'good'},id:1}"; string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"workie ... good\",\"id\":1}"; diff --git a/AustinHarris.JsonRpcTestN/packages.config b/AustinHarris.JsonRpcTestN/packages.config index d274cb4..3632280 100644 --- a/AustinHarris.JsonRpcTestN/packages.config +++ b/AustinHarris.JsonRpcTestN/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/Json-Rpc/AustinHarris.JsonRpc.csproj b/Json-Rpc/AustinHarris.JsonRpc.csproj index 9d67f72..1f54453 100644 --- a/Json-Rpc/AustinHarris.JsonRpc.csproj +++ b/Json-Rpc/AustinHarris.JsonRpc.csproj @@ -71,12 +71,15 @@ - - ..\packages\Newtonsoft.Json.8.0.2\lib\net40\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll True + + + @@ -92,7 +95,4 @@ --> - - - \ No newline at end of file diff --git a/Json-Rpc/Handler.cs b/Json-Rpc/Handler.cs index 9922f95..35fb29d 100644 --- a/Json-Rpc/Handler.cs +++ b/Json-Rpc/Handler.cs @@ -34,7 +34,6 @@ private Handler(string sessionId) { SessionId = sessionId; this.MetaData = new SMD(); - this.Handlers = new Dictionary(); } #endregion @@ -74,7 +73,6 @@ public static void DestroySession(string sessionId) { Handler h; _sessionHandlers.TryRemove(sessionId, out h); - h.Handlers.Clear(); h.MetaData.Services.Clear(); } /// @@ -142,7 +140,6 @@ private void RemoveRpcException() private AustinHarris.JsonRpc.PostProcessHandler externalPostProcessingHandler; private Func externalErrorHandler; private Func parseErrorHandler; - private Dictionary Handlers { get; set; } #endregion /// @@ -154,27 +151,8 @@ private void RemoveRpcException() #region Public Methods - /// - /// Registers a jsonRpc method name (key) to be mapped to a specific function - /// - /// The Method as it will be called from JsonRpc - /// The method that will be invoked - /// - public bool Register(string key, Delegate handle) - { - var result = false; - - if (!this.Handlers.ContainsKey(key)) - { - this.Handlers.Add(key, handle); - } - - return result; - } - public void UnRegister(string key) { - this.Handlers.Remove(key); MetaData.Services.Remove(key); } @@ -203,10 +181,13 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null, Action - { - var tuple = (Tuple)_async; - ProcessJsonRpcState(tuple.Item1, tuple.Item2); - }, new Tuple(async, context)); - + Process(Handler.DefaultSessionId(), async, context); } public static void Process(string sessionId, JsonRpcStateAsync async, object context = null) @@ -132,19 +127,11 @@ public static void Process(string sessionId, JsonRpcStateAsync async, object con var t = Task.Factory.StartNew((_async) => { var i = (Tuple)_async; - ProcessJsonRpcState(i.Item1, i.Item2, i.Item3); + async.Result = ProcessInternal(i.Item1, i.Item2.JsonRpc, i.Item3); + async.SetCompleted(); }, new Tuple(sessionId, async, context)); } - internal static void ProcessJsonRpcState(JsonRpcStateAsync async, object jsonRpcContext = null) - { - ProcessJsonRpcState(Handler.DefaultSessionId(), async, jsonRpcContext); - } - internal static void ProcessJsonRpcState(string sessionId, JsonRpcStateAsync async, object jsonRpcContext = null) - { - async.Result = ProcessInternal(sessionId, async.JsonRpc, jsonRpcContext); - async.SetCompleted(); - } public static Task Process(string jsonRpc, object context = null) { diff --git a/Json-Rpc/SMDService.cs b/Json-Rpc/SMDService.cs index 2c3fa8b..232ad89 100644 --- a/Json-Rpc/SMDService.cs +++ b/Json-Rpc/SMDService.cs @@ -34,9 +34,9 @@ public SMD () TypeHashes = new List(); } - public void AddService(string method, Dictionary parameters, Dictionary defaultValues) + public void AddService(string method, Dictionary parameters, Dictionary defaultValues, Delegate dele) { - var newService = new SMDService(transport,"JSON-RPC-2.0",parameters, defaultValues); + var newService = new SMDService(transport,"JSON-RPC-2.0",parameters, defaultValues, dele); Services.Add(method,newService); } @@ -64,6 +64,7 @@ public static bool ContainsType(JObject jo) public class SMDService { + public Delegate dele; /// /// Defines a service method http://dojotoolkit.org/reference-guide/1.8/dojox/rpc/smd.html /// @@ -71,9 +72,10 @@ public class SMDService /// URL, PATH, JSON, JSON-RPC-1.0, JSON-RPC-1.1, JSON-RPC-2.0 /// /// - public SMDService(string transport, string envelope, Dictionary parameters, Dictionary defaultValues ) + public SMDService(string transport, string envelope, Dictionary parameters, Dictionary defaultValues, Delegate dele) { // TODO: Complete member initialization + this.dele = dele; this.transport = transport; this.envelope = envelope; this.parameters = new SMDAdditionalParameters[parameters.Count-1]; // last param is return type similar to Func<,> diff --git a/Json-Rpc/ServiceBinder.cs b/Json-Rpc/ServiceBinder.cs index d6b8451..5c984ab 100644 --- a/Json-Rpc/ServiceBinder.cs +++ b/Json-Rpc/ServiceBinder.cs @@ -12,7 +12,6 @@ public static void bindService(string sessionID, Func serviceFactory) { var instance = serviceFactory(); var item = instance.GetType(); // var item = typeof(T); - var regMethod = typeof(Handler).GetMethod("Register"); var methods = item.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(m => m.GetCustomAttributes(typeof(JsonRpcMethodAttribute), false).Length > 0); foreach (var meth in methods) @@ -42,8 +41,7 @@ public static void bindService(string sessionID, Func serviceFactory) var methodName = handlerAttribute.JsonMethodName == string.Empty ? meth.Name : handlerAttribute.JsonMethodName; var newDel = Delegate.CreateDelegate(System.Linq.Expressions.Expression.GetDelegateType(paras.Values.ToArray()), instance /*Need to add support for other methods outside of this instance*/, meth); var handlerSession = Handler.GetSessionHandler(sessionID); - regMethod.Invoke(handlerSession, new object[] { methodName, newDel }); - handlerSession.MetaData.AddService(methodName, paras, defaultValues); + handlerSession.MetaData.AddService(methodName, paras, defaultValues, newDel); } } } diff --git a/Json-Rpc/packages.config b/Json-Rpc/packages.config index 79f852f..7c276ed 100644 --- a/Json-Rpc/packages.config +++ b/Json-Rpc/packages.config @@ -1,4 +1,4 @@  - - + + \ No newline at end of file diff --git a/TestServer_Console/TestServer_Console.csproj b/TestServer_Console/TestServer_Console.csproj index 5e276d2..76a4d79 100644 --- a/TestServer_Console/TestServer_Console.csproj +++ b/TestServer_Console/TestServer_Console.csproj @@ -50,8 +50,8 @@ false - - ..\packages\Newtonsoft.Json.8.0.2\lib\net40\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll True @@ -76,6 +76,9 @@ AustinHarris.JsonRpc + + + + + + + + + \ No newline at end of file diff --git a/Json-Rpc/Properties/AssemblyInfo.cs b/Json-Rpc/Properties/AssemblyInfo.cs deleted file mode 100644 index 802d0fd..0000000 --- a/Json-Rpc/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Json-Rpc.Net Core")] -[assembly: AssemblyDescription("Core functionality for JsonRpc.Net")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Austin Harris")] -[assembly: AssemblyProduct("Json-Rpc.Net Core")] -[assembly: AssemblyCopyright("Austin Harris")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("2f8036b2-223d-4b90-b6a9-fadddeb3ac0d")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -[assembly: AssemblyVersion("1.0.5.0")] -[assembly: AssemblyFileVersion("1.0.5.0")] diff --git a/Json-Rpc/packages.config b/Json-Rpc/packages.config deleted file mode 100644 index 7c276ed..0000000 --- a/Json-Rpc/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/README.md b/README.md index 553edd8..8bf66a5 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,12 @@ json-rpc.net ============ -.Net [![astn-jsonrpc MyGet Build Status](https://www.myget.org/BuildSource/Badge/astn-jsonrpc?identifier=fbc64a4a-f9a7-4306-87ba-de0bb9d23cb7)](https://www.myget.org/feed/Activity/astn-jsonrpc) Mono [![Build Status](https://travis-ci.org/Astn/JSON-RPC.NET.svg?branch=master)](https://travis-ci.org/Astn/JSON-RPC.NET) +![.github/workflows/buildtest.yml](https://github.com/Astn/JSON-RPC.NET/workflows/.github/workflows/buildtest.yml/badge.svg) JSON-RPC.Net is a high performance Json-Rpc 2.0 server, leveraging the popular JSON.NET library. Host in ASP.NET, also supports sockets and pipes, oh my! ##### Requirements -* dotnet 4.0 or mono +* dotnet-standard (dotnet core | mono | .net framework) ##### License JSON-RPC.net is licensed under The MIT License (MIT), check the [LICENSE](https://github.com/CoiniumServ/JSON-RPC.NET/blob/master/LICENSE) file for details. @@ -29,10 +29,25 @@ To install JSON-RPC.NET AspNet, run the following command in the Package Manager PM> Install-Package AustinHarris.JsonRpc.AspNet ``` -##### Performance +## Performance -Under ideal conditions > 120k rpc/sec (cpu i7-2600, console test server) +These are results from running the TestServer_Console project. +##### Xeon E-2176M @ 2.70GHz 64.0 GB (Date: Thu Apr 30 17:34:22 2020 -0600) + +``` +Starting benchmark +processed 50 rpc in 137ms for 364.96 rpc/sec +processed 100 rpc in 0ms for ∞ rpc/sec +processed 300 rpc in 1ms for 300,000.00 rpc/sec +processed 1,200 rpc in 7ms for 171,428.57 rpc/sec +processed 6,000 rpc in 26ms for 230,769.23 rpc/sec +processed 36,000 rpc in 166ms for 216,867.47 rpc/sec +processed 252,000 rpc in 1,121ms for 224,799.29 rpc/sec +Finished benchmark... +``` + +##### Intel i7 920 @ 2.67GHz 12.0 GB (Date: Maybe in 2015?) > ``` Starting benchmark @@ -47,10 +62,7 @@ processed 2,016,000 rpc in 13,930ms for 144,723 rpc/sec Finished benchmark... ``` -###### Test machine -i7 920 @ 2.67 GHz -12.0 GB diff --git a/TestServer_Console/Program.cs b/TestServer_Console/Program.cs index 6d9c125..df3152f 100644 --- a/TestServer_Console/Program.cs +++ b/TestServer_Console/Program.cs @@ -68,7 +68,7 @@ private static void Benchmark() } Task.WaitAll(tasks); sw.Stop(); - Console.WriteLine("processed {0} rpc in {1}ms for {2} rpc/sec", cnt, sw.ElapsedMilliseconds, (double)cnt * 1000d / sw.ElapsedMilliseconds); + Console.WriteLine("processed {0:N0} rpc in \t {1:N0}ms for \t {2:N} rpc/sec", cnt, sw.ElapsedMilliseconds, (double)cnt * 1000d / sw.ElapsedMilliseconds); } diff --git a/TestServer_Console/Properties/AssemblyInfo.cs b/TestServer_Console/Properties/AssemblyInfo.cs deleted file mode 100644 index fdd1edf..0000000 --- a/TestServer_Console/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("TestServer_Console")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("TestServer_Console")] -[assembly: AssemblyCopyright("Copyright © 2012")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("5e7696bc-52cc-48f8-a575-40b17165ee20")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TestServer_Console/TestServer_Console.csproj b/TestServer_Console/TestServer_Console.csproj index be9574b..ba5f427 100644 --- a/TestServer_Console/TestServer_Console.csproj +++ b/TestServer_Console/TestServer_Console.csproj @@ -1,98 +1,24 @@ - - + + - Debug - x86 - {31AE59FC-B6F6-4AC7-A7B9-1E07630AE42B} + Austin Harris Exe - Properties - TestServer_Console - TestServer_Console - v4.0 - Client - 512 - SAK - SAK - SAK - SAK - ..\ - true + netcoreapp3.1 - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - x86 - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - AnyCPU - bin\Debug\ - 4 - false - - - AnyCPU - bin\Release\ - 4 - true - false - - - - ..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll - True - - - - - - - - - - ..\packages\Newtonsoft.Json.7.0.1\lib\net40\Newtonsoft.Json.dll - - + + - - - + + + - - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307} - AustinHarris.JsonRpc - + + + - + - - - - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - + \ No newline at end of file diff --git a/TestServer_Console/packages.config b/TestServer_Console/packages.config deleted file mode 100644 index e307e1c..0000000 --- a/TestServer_Console/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file From d840b1c0cd6d10d83fda3c82284e0c829bf496a1 Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Thu, 30 Apr 2020 19:43:38 -0600 Subject: [PATCH 73/81] README.md (#115) * README.md * Don't build md files * Maybe order matters? --- .github/workflows/build_publish_master.yml | 2 ++ .github/workflows/build_pull_request.yml | 2 ++ README.md | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_publish_master.yml b/.github/workflows/build_publish_master.yml index 2f837be..1a7fe10 100644 --- a/.github/workflows/build_publish_master.yml +++ b/.github/workflows/build_publish_master.yml @@ -1,6 +1,8 @@ name: Build Master on: push: + paths-ignore: + - "**/*.md" branches: [ master ] jobs: diff --git a/.github/workflows/build_pull_request.yml b/.github/workflows/build_pull_request.yml index 57c1677..f3e06e9 100644 --- a/.github/workflows/build_pull_request.yml +++ b/.github/workflows/build_pull_request.yml @@ -1,6 +1,8 @@ name: Pull Reqest on: pull_request: + paths-ignore: + - "**/*.md" branches: [ master ] jobs: diff --git a/README.md b/README.md index 8bf66a5..af89410 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ json-rpc.net ============ -![.github/workflows/buildtest.yml](https://github.com/Astn/JSON-RPC.NET/workflows/.github/workflows/buildtest.yml/badge.svg) +![Build Master](https://github.com/Astn/JSON-RPC.NET/workflows/Build%20Master/badge.svg) JSON-RPC.Net is a high performance Json-Rpc 2.0 server, leveraging the popular JSON.NET library. Host in ASP.NET, also supports sockets and pipes, oh my! From 24f4869f3aee6ab1d1f09da55bd2b48bcaef36ec Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Thu, 30 Apr 2020 20:17:22 -0600 Subject: [PATCH 74/81] Update README.md (#116) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index af89410..7847e55 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ json-rpc.net ============ -![Build Master](https://github.com/Astn/JSON-RPC.NET/workflows/Build%20Master/badge.svg) +![Build Master](https://github.com/Astn/JSON-RPC.NET/workflows/Build%20Master/badge.svg) ![NuGet Badge](https://buildstats.info/nuget/AustinHarris.JsonRpc) JSON-RPC.Net is a high performance Json-Rpc 2.0 server, leveraging the popular JSON.NET library. Host in ASP.NET, also supports sockets and pipes, oh my! From cea2cd0c7514873024a38942b4362ce529474c9f Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Thu, 30 Apr 2020 21:02:42 -0600 Subject: [PATCH 75/81] Update README.md --- README.md | 55 +++++++++++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 7847e55..7847e23 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,29 @@ json-rpc.net JSON-RPC.Net is a high performance Json-Rpc 2.0 server, leveraging the popular JSON.NET library. Host in ASP.NET, also supports sockets and pipes, oh my! +## Performance + +These are results from running the TestServer_Console project. + +##### Xeon E-2176M @ 2.70GHz 64.0 GB (Date: Thu Apr 30 17:34:22 2020 -0600) + +``` +Starting benchmark +processed 50 rpc in 137ms for 364.96 rpc/sec +processed 100 rpc in 0ms for ∞ rpc/sec +processed 300 rpc in 1ms for 300,000.00 rpc/sec +processed 1,200 rpc in 7ms for 171,428.57 rpc/sec +processed 6,000 rpc in 26ms for 230,769.23 rpc/sec +processed 36,000 rpc in 166ms for 216,867.47 rpc/sec +processed 252,000 rpc in 1,121ms for 224,799.29 rpc/sec +Finished benchmark... +``` + +## Do you like this? + +[![https://www.buymeacoffee.com/Ekati](https://cdn.buymeacoffee.com/buttons/default-blue.png)](https://www.buymeacoffee.com/Ekati) + + ##### Requirements * dotnet-standard (dotnet core | mono | .net framework) @@ -29,38 +52,6 @@ To install JSON-RPC.NET AspNet, run the following command in the Package Manager PM> Install-Package AustinHarris.JsonRpc.AspNet ``` -## Performance - -These are results from running the TestServer_Console project. - -##### Xeon E-2176M @ 2.70GHz 64.0 GB (Date: Thu Apr 30 17:34:22 2020 -0600) - -``` -Starting benchmark -processed 50 rpc in 137ms for 364.96 rpc/sec -processed 100 rpc in 0ms for ∞ rpc/sec -processed 300 rpc in 1ms for 300,000.00 rpc/sec -processed 1,200 rpc in 7ms for 171,428.57 rpc/sec -processed 6,000 rpc in 26ms for 230,769.23 rpc/sec -processed 36,000 rpc in 166ms for 216,867.47 rpc/sec -processed 252,000 rpc in 1,121ms for 224,799.29 rpc/sec -Finished benchmark... -``` - -##### Intel i7 920 @ 2.67GHz 12.0 GB (Date: Maybe in 2015?) -> -``` -Starting benchmark -processed 50 rpc in 0ms for ∞ rpc/sec -processed 100 rpc in 2ms for 50,000 rpc/sec -processed 300 rpc in 1ms for 300,000 rpc/sec -processed 1,200 rpc in 6ms for 200,000 rpc/sec -processed 6,000 rpc in 37ms for 162,162 rpc/sec -processed 36,000 rpc in 228ms for 157,894 rpc/sec -processed 252,000 rpc in 1,688ms for 149,289 rpc/sec -processed 2,016,000 rpc in 13,930ms for 144,723 rpc/sec -Finished benchmark... -``` From 19e680e0e4aab7096f589be0726196c699991f0c Mon Sep 17 00:00:00 2001 From: astn Date: Thu, 21 May 2020 18:42:06 -0600 Subject: [PATCH 76/81] Fixes #118 Thanks to @HoMS1987 for submitting this issue and doing the first round of development on solving the problem. --- .../AustinHarris.JsonRpcTestN.csproj | 2 +- AustinHarris.JsonRpcTestN/Test.cs | 12 ++++++++++++ AustinHarris.JsonRpcTestN/service.cs | 6 ++++++ Json-Rpc/Handler.cs | 8 ++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj index 350cada..c5db038 100644 --- a/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj +++ b/AustinHarris.JsonRpcTestN/AustinHarris.JsonRpcTestN.csproj @@ -2,7 +2,7 @@ Austin Harris - netstandard2.0;netcoreapp3.0;netcoreapp3.1 + netcoreapp3.0;netcoreapp3.1 diff --git a/AustinHarris.JsonRpcTestN/Test.cs b/AustinHarris.JsonRpcTestN/Test.cs index e90e80c..3a92f3f 100644 --- a/AustinHarris.JsonRpcTestN/Test.cs +++ b/AustinHarris.JsonRpcTestN/Test.cs @@ -1379,6 +1379,18 @@ public void TestOptionalParametersBoolsAndStrings() Assert.IsFalse(result.Result.Contains("error")); Assert.AreEqual(expectedResult, result.Result); } + + [TestCase("{method:\"TestDifferentOptionalParameters\",params:{location:\"loc1\", uid:\"abc123\", wavelengths: [0.0], traces: [0.0]},id:1}", ExpectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"this is the requested measurement\",\"id\":1}")] + [TestCase("{method:\"TestDifferentOptionalParameters\",params:{uid:\"abc123\", wavelengths: [0.0], traces: [0.0]},id:1}", ExpectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"this is the requested measurement\",\"id\":1}")] + [TestCase("{method:\"TestDifferentOptionalParameters\",params:{location:\"loc1\", uid:\"abc123\", traces: [0.0]},id:1}", ExpectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"this is the requested measurement\",\"id\":1}")] + [TestCase("{method:\"TestDifferentOptionalParameters\",params:{location:\"loc1\", uid:\"abc123\", wavelengths: [0.0]},id:1}", ExpectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"this is the requested measurement\",\"id\":1}")] + [TestCase("{method:\"TestDifferentOptionalParameters\",params:{uid:\"abc123\", wavelengths: [0.0]},id:1}", ExpectedResult = "{\"jsonrpc\":\"2.0\",\"result\":\"this is the requested measurement\",\"id\":1}")] + public string TestDifferentOptionalParametersNamedWorking(string request) + { + var result = JsonRpcProcessor.Process(request); + result.Wait(); + return result.Result; + } [Test()] public void TestBatchResultWrongRequests() diff --git a/AustinHarris.JsonRpcTestN/service.cs b/AustinHarris.JsonRpcTestN/service.cs index 623a0e8..b34d957 100644 --- a/AustinHarris.JsonRpcTestN/service.cs +++ b/AustinHarris.JsonRpcTestN/service.cs @@ -389,6 +389,12 @@ public TreeNode TestNestedReturnType() } }; } + + [JsonRpcMethod] + private string TestDifferentOptionalParameters(string uid, string location = null, List traces = null, List wavelengths = null) + { + return "this is the requested measurement"; + } } } diff --git a/Json-Rpc/Handler.cs b/Json-Rpc/Handler.cs index 0834e1f..1c746b5 100644 --- a/Json-Rpc/Handler.cs +++ b/Json-Rpc/Handler.cs @@ -267,6 +267,14 @@ public JsonResponse Handle(JsonRequest Rpc, Object RpcContext = null) } else { + var foundDefault = metadata.defaultValues + .FirstOrDefault(defaul => defaul.Name == metadata.parameters[i].Name); + if (foundDefault != null) + { + parameters[i] = foundDefault.Value; + continue; + } + JsonResponse response = new JsonResponse() { Error = ProcessException(Rpc, From 0b0b0681b87f44d90a186710f13ec42232d49988 Mon Sep 17 00:00:00 2001 From: astn Date: Thu, 21 May 2020 18:52:52 -0600 Subject: [PATCH 77/81] Bump Nuget Version --- Json-Rpc/AustinHarris.JsonRpc.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Json-Rpc/AustinHarris.JsonRpc.csproj b/Json-Rpc/AustinHarris.JsonRpc.csproj index af1c65c..39046d8 100644 --- a/Json-Rpc/AustinHarris.JsonRpc.csproj +++ b/Json-Rpc/AustinHarris.JsonRpc.csproj @@ -4,7 +4,7 @@ Austin Harris Json-Rpc.Net Core Core functionality for JsonRpc.Net - 1.2.0.1 + 1.2.1.2 $(VersionSuffix) Austin Harris netstandard2.0;netstandard2.1;netcoreapp3.1 From c77c6600a6a8bb1fd8058787f2a9be9d1f1fd735 Mon Sep 17 00:00:00 2001 From: astn Date: Thu, 21 May 2020 21:50:00 -0600 Subject: [PATCH 78/81] Bump Nuget Version --- Json-Rpc/AustinHarris.JsonRpc.csproj | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Json-Rpc/AustinHarris.JsonRpc.csproj b/Json-Rpc/AustinHarris.JsonRpc.csproj index 39046d8..2f48389 100644 --- a/Json-Rpc/AustinHarris.JsonRpc.csproj +++ b/Json-Rpc/AustinHarris.JsonRpc.csproj @@ -4,9 +4,16 @@ Austin Harris Json-Rpc.Net Core Core functionality for JsonRpc.Net - 1.2.1.2 + 1.2.2 $(VersionSuffix) Austin Harris + https://github.com/Astn/JSON-RPC.NET + https://raw.githubusercontent.com/Astn/JSON-RPC.NET/master/LICENSE + + Improves support for optional parameters - @HoMS1987 https://github.com/HoMS1987 + Fixes protocol validation of the ID property - @pedrolcl https://github.com/pedrolcl + DotNet Core support - @astn https://github.com/astn + netstandard2.0;netstandard2.1;netcoreapp3.1 true From dd1fa1434ef66c238652acf2261f1881070fe1cd Mon Sep 17 00:00:00 2001 From: Karel Hovorka Date: Sat, 11 Sep 2021 01:38:46 +0200 Subject: [PATCH 79/81] Passing optional JsonSerializerSettings. --- Json-Rpc/JsonRpcProcessor.cs | 49 ++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/Json-Rpc/JsonRpcProcessor.cs b/Json-Rpc/JsonRpcProcessor.cs index 1d7e1a7..c43442c 100644 --- a/Json-Rpc/JsonRpcProcessor.cs +++ b/Json-Rpc/JsonRpcProcessor.cs @@ -13,34 +13,41 @@ namespace AustinHarris.JsonRpc { public static class JsonRpcProcessor { - public static void Process(JsonRpcStateAsync async, object context = null) + public static void Process(JsonRpcStateAsync async, object context = null, + JsonSerializerSettings settings = null) { - Process(Handler.DefaultSessionId(), async, context); + Process(Handler.DefaultSessionId(), async, context, settings); } - public static void Process(string sessionId, JsonRpcStateAsync async, object context = null) + public static void Process(string sessionId, JsonRpcStateAsync async, object context = null, + JsonSerializerSettings settings = null) { - Process(sessionId, async.JsonRpc, context) + Process(sessionId, async.JsonRpc, context, settings) .ContinueWith(t => - { - async.Result = t.Result; - async.SetCompleted(); - }); + { + async.Result = t.Result; + async.SetCompleted(); + }); } - public static Task Process(string jsonRpc, object context = null) + + public static Task Process(string jsonRpc, object context = null, + JsonSerializerSettings settings = null) { - return Process(Handler.DefaultSessionId(), jsonRpc, context); + return Process(Handler.DefaultSessionId(), jsonRpc, context, settings); } - public static Task Process(string sessionId, string jsonRpc, object context = null) - { + + public static Task Process(string sessionId, string jsonRpc, object context = null, + JsonSerializerSettings settings = null) + { return Task.Factory.StartNew((_) => { - var tuple = (Tuple)_; - return ProcessInternal(tuple.Item1, tuple.Item2, tuple.Item3); - }, new Tuple(sessionId, jsonRpc, context)); + var tuple = (Tuple)_; + return ProcessInternal(tuple.Item1, tuple.Item2, tuple.Item3, tuple.Item4); + }, new Tuple(sessionId, jsonRpc, context, settings)); } - private static string ProcessInternal(string sessionId, string jsonRpc, object jsonRpcContext) + private static string ProcessInternal(string sessionId, string jsonRpc, object jsonRpcContext, + JsonSerializerSettings settings = null) { var handler = Handler.GetSessionHandler(sessionId); @@ -50,12 +57,12 @@ private static string ProcessInternal(string sessionId, string jsonRpc, object j { if (isSingleRpc(jsonRpc)) { - var foo = JsonConvert.DeserializeObject(jsonRpc); + var foo = JsonConvert.DeserializeObject(jsonRpc, settings); batch = new[] { foo }; } else { - batch = JsonConvert.DeserializeObject(jsonRpc); + batch = JsonConvert.DeserializeObject(jsonRpc, settings); } } catch (Exception ex) @@ -63,7 +70,7 @@ private static string ProcessInternal(string sessionId, string jsonRpc, object j return Newtonsoft.Json.JsonConvert.SerializeObject(new JsonResponse { Error = handler.ProcessParseException(jsonRpc, new JsonRpcException(-32700, "Parse error", ex)) - }); + }, settings); } if (batch.Length == 0) @@ -72,7 +79,7 @@ private static string ProcessInternal(string sessionId, string jsonRpc, object j { Error = handler.ProcessParseException(jsonRpc, new JsonRpcException(3200, "Invalid Request", "Batch of calls was empty.")) - }); + }, settings); } var singleBatch = batch.Length == 1; @@ -156,7 +163,7 @@ private static string ProcessInternal(string sessionId, string jsonRpc, object j sbResult = new StringBuilder("["); } - sbResult.Append(JsonConvert.SerializeObject(jsonResponse)); + sbResult.Append(JsonConvert.SerializeObject(jsonResponse, settings)); if (i < batch.Length - 1) { sbResult.Append(','); From 177be604e532fe2c1e11fec9d4c8447138f7f741 Mon Sep 17 00:00:00 2001 From: astn Date: Sat, 11 Sep 2021 03:48:10 -0600 Subject: [PATCH 80/81] Bumb nuget version. Update release notes. Expose ProcessSync as public. --- Json-Rpc/AustinHarris.JsonRpc.csproj | 2 +- Json-Rpc/AustinHarris.JsonRpc.nuspec | 2 +- Json-Rpc/Handler.cs | 2 +- Json-Rpc/JsonRpcProcessor.cs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Json-Rpc/AustinHarris.JsonRpc.csproj b/Json-Rpc/AustinHarris.JsonRpc.csproj index 2f48389..f6a680d 100644 --- a/Json-Rpc/AustinHarris.JsonRpc.csproj +++ b/Json-Rpc/AustinHarris.JsonRpc.csproj @@ -4,7 +4,7 @@ Austin Harris Json-Rpc.Net Core Core functionality for JsonRpc.Net - 1.2.2 + 1.2.3 $(VersionSuffix) Austin Harris https://github.com/Astn/JSON-RPC.NET diff --git a/Json-Rpc/AustinHarris.JsonRpc.nuspec b/Json-Rpc/AustinHarris.JsonRpc.nuspec index 0922df6..ad36f62 100644 --- a/Json-Rpc/AustinHarris.JsonRpc.nuspec +++ b/Json-Rpc/AustinHarris.JsonRpc.nuspec @@ -12,7 +12,7 @@ false The fastest .Net JSON RPC Server JSON-RPC.Net is a high performance Json-Rpc 2.0 server, leveraging the popular JSON.NET library. Easily create a JSON RPC server for your Angular javascript apps, also supports sockets and pipes, oh my! - Named Parameters via attributes -rommar. Fix nuget dependency requirements -jbreens. Cleaner service registration -xmedeko + Optional JsonSerializer Settings - @hovi. ProcessSync is now public - @astn en-US fast json rpc server socket javascript json-rpc.net json-rpc jsonrpc json.net web services webapi service angular server angularjs diff --git a/Json-Rpc/Handler.cs b/Json-Rpc/Handler.cs index 1c746b5..095bacb 100644 --- a/Json-Rpc/Handler.cs +++ b/Json-Rpc/Handler.cs @@ -492,7 +492,7 @@ private object CleanUpParameter(object p, SMDAdditionalParameters metaData) private JsonRpcException PreProcess(JsonRequest request, object context) { - return externalPreProcessingHandler == null ? null : externalPreProcessingHandler(request, context); + return externalPreProcessingHandler?.Invoke(request, context); } private JsonResponse PostProcess(JsonRequest request, JsonResponse response, object context) diff --git a/Json-Rpc/JsonRpcProcessor.cs b/Json-Rpc/JsonRpcProcessor.cs index c43442c..8915b8d 100644 --- a/Json-Rpc/JsonRpcProcessor.cs +++ b/Json-Rpc/JsonRpcProcessor.cs @@ -42,11 +42,11 @@ public static Task Process(string sessionId, string jsonRpc, object cont return Task.Factory.StartNew((_) => { var tuple = (Tuple)_; - return ProcessInternal(tuple.Item1, tuple.Item2, tuple.Item3, tuple.Item4); + return ProcessSync(tuple.Item1, tuple.Item2, tuple.Item3, tuple.Item4); }, new Tuple(sessionId, jsonRpc, context, settings)); } - private static string ProcessInternal(string sessionId, string jsonRpc, object jsonRpcContext, + public static string ProcessSync(string sessionId, string jsonRpc, object jsonRpcContext, JsonSerializerSettings settings = null) { var handler = Handler.GetSessionHandler(sessionId); From 16865f232f791fca7fb2a5def0ab3c23a0f3aff3 Mon Sep 17 00:00:00 2001 From: Gerardo Contijoch Date: Fri, 11 Aug 2023 08:36:15 -0300 Subject: [PATCH 81/81] Fix: JsonRpcProcessor does not ignore JsonSerializerSettings when serializing responses --- Json-Rpc/JsonRpcProcessor.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Json-Rpc/JsonRpcProcessor.cs b/Json-Rpc/JsonRpcProcessor.cs index 8915b8d..5020e88 100644 --- a/Json-Rpc/JsonRpcProcessor.cs +++ b/Json-Rpc/JsonRpcProcessor.cs @@ -138,11 +138,11 @@ public static string ProcessSync(string sessionId, string jsonRpc, object jsonRp } if (jsonResponse.Error != null) { - writer.WritePropertyName("error"); writer.WriteRawValue(JsonConvert.SerializeObject(jsonResponse.Error)); + writer.WritePropertyName("error"); writer.WriteRawValue(JsonConvert.SerializeObject(jsonResponse.Error, settings)); } else { - writer.WritePropertyName("result"); writer.WriteRawValue(JsonConvert.SerializeObject(jsonResponse.Result)); + writer.WritePropertyName("result"); writer.WriteRawValue(JsonConvert.SerializeObject(jsonResponse.Result, settings)); } writer.WritePropertyName("id"); writer.WriteValue(jsonResponse.Id); writer.WriteEndObject();