예제 #1
0
        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)));
        }
예제 #2
0
 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));
 }
예제 #3
0
 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)));
 }
예제 #4
0
        public void CallIdempotentMethodWithIdempotencyRequired()
        {
            JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService());

            server.RequireIdempotency = true;
            JsonRpcServices.GetResult((IDictionary)Parse(server.Process("{ id : 1, method : 'Idem', params : [] }")));
        }
예제 #5
0
        public void SetJsonImporter()
        {
            JsonRpcDispatcher dispatcher = new JsonRpcDispatcher(new TestService());
            JsonImportHandler importer   = new JsonImportHandler(new ImportContext().Import);

            dispatcher.JsonImporter = importer;
            Assert.AreSame(importer, dispatcher.JsonImporter);
        }
예제 #6
0
        public void SetJsonExporter()
        {
            JsonRpcDispatcher dispatcher = new JsonRpcDispatcher(new TestService());
            JsonExportHandler exporter   = new JsonExportHandler(new ExportContext().Export);

            dispatcher.JsonExporter = exporter;
            Assert.AreSame(exporter, dispatcher.JsonExporter);
        }
예제 #7
0
        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[])));
        }
예제 #8
0
        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)));
        }
예제 #9
0
        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"]);
 }
예제 #11
0
        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));
        }
예제 #12
0
        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 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);
 }
예제 #14
0
        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"]);
        }
예제 #15
0
        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 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]);
 }
예제 #17
0
        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);
        }
예제 #18
0
        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]);
        }
예제 #19
0
        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));
        }
예제 #20
0
        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));
        }
예제 #21
0
        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());
        }
예제 #22
0
 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 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 SetImportContext()
 {
     JsonRpcDispatcher dispatcher = new JsonRpcDispatcher(new TestService());
     ImportContext context = new ImportContext();
     dispatcher.ImportContext = context;
     Assert.AreSame(context, dispatcher.ImportContext);
 }
 public void UnknownRequestMembersSkipped()
 {
     JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService());
     JsonRpcServices.GetResult((IDictionary) Parse(server.Process("{ id : 1, foo : [bar], method : 'Dummy', params : [] }")));
 }
        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 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[])));
 }
예제 #29
0
 public void SetJsonExporter()
 {
     JsonRpcDispatcher dispatcher = new JsonRpcDispatcher(new TestService());
     JsonExportHandler exporter = new JsonExportHandler(new ExportContext().Export);
     dispatcher.JsonExporter = exporter;
     Assert.AreSame(exporter, dispatcher.JsonExporter);
 }
예제 #30
0
 public void SetJsonImporter()
 {
     JsonRpcDispatcher dispatcher = new JsonRpcDispatcher(new TestService());
     JsonImportHandler importer = new JsonImportHandler(new ImportContext().Import);
     dispatcher.JsonImporter = importer;
     Assert.AreSame(importer, dispatcher.JsonImporter);
 }
 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 NotificationNotSupported()
 {
     JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService());
     server.Process("{ id : null, method : 'Dummy' }");
 }
예제 #33
0
        public void UnknownRequestMembersSkipped()
        {
            JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService());

            JsonRpcServices.GetResult((IDictionary)Parse(server.Process("{ id : 1, foo : [bar], method : 'Dummy', params : [] }")));
        }
 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));
 }
예제 #35
0
        public void NotificationNotSupported()
        {
            JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService());

            server.Process("{ id : null, method : 'Dummy' }");
        }
 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);
 }
예제 #37
0
 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);
 }