public void CallWithParamNamesInAltCase() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); string responseString = server.Process("{ id : 1, method : 'Say', params : { MESSAGE : 'Hello' } }"); Assert.AreEqual("Hello", JsonRpcServices.GetResult((IDictionary)Parse(responseString))); }
public void CallIdempotentMethodWithIdempotencyRequired() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); server.RequireIdempotency = true; JsonRpcServices.GetResult((IDictionary)Parse(server.Process("{ id : 1, method : 'Idem', params : [] }"))); }
public void ArgWithOneOrTwoCharNameDroppedBug() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService2()); string responseString = server.Process("{ id : 1, method : 'Echo', params : { o : 123 } }"); IDictionary response = (IDictionary) Parse(responseString); Assert.AreEqual(123, Convert.ToInt32(JsonRpcServices.GetResult(response))); }
public void CallWithIntArray() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); string responseString = server.Process("{ id : 42, method : 'sum', params : [ [ 1, 2, 3, 4, 5 ] ] }"); IDictionary response = (IDictionary)Parse(responseString); Assert.AreEqual(15, (int)(JsonNumber)JsonRpcServices.GetResult(response)); }
public void SimpleCall() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); string responseString = server.Process("{ id : 1, method : 'Say', params : [ 'Hello' ] }"); IDictionary response = (IDictionary) Parse(responseString); Assert.AreEqual(1, (int) (JsonNumber) response["id"]); Assert.AreEqual("Hello", response["result"]); }
public void CallWithPositionalArgs() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService2()); string responseString = server.Process("{ id : 1, method : 'EchoMany', params : { 0:11,1:12,2:13,3:14,4:15,5:16,6:17,7:18,8:19,9:20,10:21,11:22,12:23,13:24,14:25,15:26,16:27,17:28,18:29,19:30,20:31,21:32,22:33,23:34,24:35,25:36 } }"); IDictionary response = (IDictionary)Parse(responseString); Assert.AreEqual(new int[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36 }, JsonRpcServices.GetResult(response, typeof(int[]))); }
public void PositionNineArgDroppedBug() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService2()); string responseString = server.Process("{ id : 1, method : 'Echo', params : { o : 123 } }"); IDictionary response = (IDictionary)Parse(responseString); Assert.AreEqual(123, Convert.ToInt32(JsonRpcServices.GetResult(response))); }
public void CallWithUnknownArgsHarmless() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); string responseString = server.Process("{ id : 1, method : 'Say', params : { message : 'Hello', bad : 'World' } }"); IDictionary response = (IDictionary)Parse(responseString); Assert.AreEqual("Hello", JsonRpcServices.GetResult(response)); }
public void SimpleCall() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); string responseString = server.Process("{ id : 1, method : 'Say', params : [ 'Hello' ] }"); IDictionary response = (IDictionary)Parse(responseString); Assert.AreEqual(1, (int)(JsonNumber)response["id"]); Assert.AreEqual("Hello", response["result"]); }
public void CallWithArrayResult() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); string responseString = server.Process("{ id : 'F9A2CC85-79A2-489f-AE61-84348654008C', method : 'replicate', params : [ 'Hello', 3 ] }"); IDictionary response = (IDictionary) Parse(responseString); Assert.AreEqual("F9A2CC85-79A2-489f-AE61-84348654008C", response["id"]); object[] result = ((JsonArray) response["result"]).ToArray(); Assert.AreEqual(new string[] { "Hello", "Hello", "Hello" }, result); }
public void CallWithNamedArgs() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); string responseString = server.Process("{ id : 42, method : 'replicate', params : { count : 3, text : 'Hello' } }"); IDictionary response = (IDictionary)Parse(responseString); object[] result = ((JsonArray)JsonRpcServices.GetResult(response)).ToArray(); Assert.AreEqual(new string[] { "Hello", "Hello", "Hello" }, result); }
public void CustomExportContextUsedDuringRequestProcessing() { JsonRpcDispatcher dispatcher = new JsonRpcDispatcher(new TestService()); TestExporter exporter = new TestExporter(); Assert.IsFalse(exporter.ExportCalled); dispatcher.JsonExporter = new JsonExportHandler(exporter.Export); dispatcher.Process("{ id: 1, method: Dummy }"); Assert.IsTrue(exporter.ExportCalled); }
public void CallWithArrayResult() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); string responseString = server.Process("{ id : 'F9A2CC85-79A2-489f-AE61-84348654008C', method : 'replicate', params : [ 'Hello', 3 ] }"); IDictionary response = (IDictionary)Parse(responseString); Assert.AreEqual("F9A2CC85-79A2-489f-AE61-84348654008C", response["id"]); object[] result = ((JsonArray)response["result"]).ToArray(); Assert.AreEqual(new string[] { "Hello", "Hello", "Hello" }, result); }
public void ProcWithArrayArg() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); string responseString = server.Process("{ id : 42, method : 'rev', params : [ [ 1, 'two', 3 ] ] }"); IDictionary response = (IDictionary) Parse(responseString); object[] result = ((JsonArray) response["result"]).ToArray(); Assert.AreEqual(3, (int) (JsonNumber) result[0]); Assert.AreEqual("two", result[1]); Assert.AreEqual(1, (int) (JsonNumber) result[2]); }
public void ProcWithArrayArg() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); string responseString = server.Process("{ id : 42, method : 'rev', params : [ [ 1, 'two', 3 ] ] }"); IDictionary response = (IDictionary)Parse(responseString); object[] result = ((JsonArray)response["result"]).ToArray(); Assert.AreEqual(3, (int)(JsonNumber)result[0]); Assert.AreEqual("two", result[1]); Assert.AreEqual(1, (int)(JsonNumber)result[2]); }
public void Bug8320() { // // Bug #8320: Parameter at Dispatcher without method are not handeld // http://developer.berlios.de/bugs/?func=detailbug&bug_id=8320&group_id=4638 // JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); string responseString = server.Process("{ id : 42, params : [ [ 1, 2, 3, 4, 5 ] ], method : 'sum' }"); IDictionary response = (IDictionary) Parse(responseString); Assert.AreEqual(15, (int) (JsonNumber) JsonRpcServices.GetResult(response)); }
public void Bug8320() { // // Bug #8320: Parameter at Dispatcher without method are not handeld // http://developer.berlios.de/bugs/?func=detailbug&bug_id=8320&group_id=4638 // JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); string responseString = server.Process("{ id : 42, params : [ [ 1, 2, 3, 4, 5 ] ], method : 'sum' }"); IDictionary response = (IDictionary)Parse(responseString); Assert.AreEqual(15, (int)(JsonNumber)JsonRpcServices.GetResult(response)); }
public void RequestIdReportedEvenWhenBadJson() { // // This test exercises the following bug: // Bug #10421: No ID on response when non-existing method called // https://developer.berlios.de/bugs/?func=detailbug&bug_id=10421&group_id=4638 // JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); IDictionary response = (IDictionary)JsonConvert.Import(server.Process("{ id : 42, method : 'foo }")); Assert.IsNotNull(response["error"]); object id = response["id"]; Assert.IsNotNull(id); Assert.AreEqual(42, ((JsonNumber)id).ToInt32()); }
void Start() { ALE.Tcp.Net.CreateTcpSocketServer((e, client) => { try { Debug.Log("Connected"); using (var stream = client.GetStream()) using (var reader = new StreamReader(stream, Encoding.UTF8)) using (var writer = new StreamWriter(stream, new UTF8Encoding(false))) { Service service = new Service(); JsonRpcDispatcher dispatcher = new JsonRpcDispatcher(service); dispatcher.Process(reader, writer); writer.Flush(); stream.Flush(); } } catch (System.Exception ex) { Debug.Log(ex); } finally { Debug.Log("Disconnected"); } }).Listen(hostname, listenPort, "http://localhost"); }
public void UnknownRequestMembersSkipped() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); JsonRpcServices.GetResult((IDictionary)Parse(server.Process("{ id : 1, foo : [bar], method : 'Dummy', params : [] }"))); }
public void NotificationNotSupported() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); server.Process("{ id : null, method : 'Dummy' }"); }
public void CustomExportContextUsedDuringRequestProcessing() { JsonRpcDispatcher dispatcher = new JsonRpcDispatcher(new TestService()); TestExportContext context = new TestExportContext(); Assert.IsFalse(context.ExportCalled); dispatcher.ExportContext = context; dispatcher.Process("{ id: 1, method: Dummy }"); Assert.IsTrue(context.ExportCalled); }
public void CallWithParamNamesInAltCase() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); string responseString = server.Process("{ id : 1, method : 'Say', params : { MESSAGE : 'Hello' } }"); Assert.AreEqual("Hello", JsonRpcServices.GetResult((IDictionary) Parse(responseString))); }
public void RequestIdReportedEvenWhenBadJson() { // // This test exercises the following bug: // Bug #10421: No ID on response when non-existing method called // https://developer.berlios.de/bugs/?func=detailbug&bug_id=10421&group_id=4638 // JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); IDictionary response = (IDictionary) JsonConvert.Import(server.Process("{ id : 42, method : 'foo }")); Assert.IsNotNull(response["error"]); object id = response["id"]; Assert.IsNotNull(id); Assert.AreEqual(42, ((JsonNumber) id).ToInt32()); }
public void UnknownRequestMembersSkipped() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); JsonRpcServices.GetResult((IDictionary) Parse(server.Process("{ id : 1, foo : [bar], method : 'Dummy', params : [] }"))); }
public void CallIdempotentMethodWithIdempotencyRequired() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); server.RequireIdempotency = true; JsonRpcServices.GetResult((IDictionary) Parse(server.Process("{ id : 1, method : 'Idem', params : [] }"))); }
public void CallWithPositionalArgs() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService2()); string responseString = server.Process("{ id : 1, method : 'EchoMany', params : { 0:11,1:12,2:13,3:14,4:15,5:16,6:17,7:18,8:19,9:20,10:21,11:22,12:23,13:24,14:25,15:26,16:27,17:28,18:29,19:30,20:31,21:32,22:33,23:34,24:35,25:36 } }"); IDictionary response = (IDictionary) Parse(responseString); Assert.AreEqual(new int[] { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36 }, JsonRpcServices.GetResult(response, typeof(int[]))); }
public void CallWithUnknownArgsHarmless() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); string responseString = server.Process("{ id : 1, method : 'Say', params : { message : 'Hello', bad : 'World' } }"); IDictionary response = (IDictionary) Parse(responseString); Assert.AreEqual("Hello", JsonRpcServices.GetResult(response)); }
public void CallWithNamedArgs() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); string responseString = server.Process("{ id : 42, method : 'replicate', params : { count : 3, text : 'Hello' } }"); IDictionary response = (IDictionary) Parse(responseString); object[] result = ((JsonArray) JsonRpcServices.GetResult(response)).ToArray(); Assert.AreEqual(new string[] { "Hello", "Hello", "Hello" }, result); }
public void CallWithIntArray() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); string responseString = server.Process("{ id : 42, method : 'sum', params : [ [ 1, 2, 3, 4, 5 ] ] }"); IDictionary response = (IDictionary) Parse(responseString); Assert.AreEqual(15, (int) (JsonNumber) JsonRpcServices.GetResult(response)); }
public void CustomImportContextUsedDuringRequestProcessing() { JsonRpcDispatcher dispatcher = new JsonRpcDispatcher(new TestService()); TestImporter importer = new TestImporter(); Assert.IsFalse(importer.ImportCalled); dispatcher.JsonImporter = new JsonImportHandler(importer.Import); dispatcher.Process("{ id: 1, method: Dummy }"); Assert.IsTrue(importer.ImportCalled); }