From a54682a9090db6ffd228d9a0be77b7f093eb6db2 Mon Sep 17 00:00:00 2001 From: Austin Harris Date: Sat, 12 Sep 2015 01:49:06 -0600 Subject: [PATCH 01/52] 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 02/52] 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 03/52] 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 04/52] 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 05/52] 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 06/52] 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 07/52] 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 08/52] 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 09/52] 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 10/52] 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 11/52] 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 12/52] 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 13/52] 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 14/52] 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 15/52] 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 16/52] 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 17/52] 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 18/52] 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 19/52] 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 20/52] 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 21/52] 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 44/52] 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 45/52] 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 46/52] 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 47/52] 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 48/52] 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 49/52] 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 50/52] 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 51/52] 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 52/52] 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();