コード例 #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 CallIdempotentMethodWithIdempotencyRequired()
        {
            JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService());

            server.RequireIdempotency = true;
            JsonRpcServices.GetResult((IDictionary)Parse(server.Process("{ id : 1, method : 'Idem', params : [] }")));
        }
コード例 #3
0
ファイル: TestJsonRpcDispatcher.cs プロジェクト: db48x/KeeFox
 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 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));
        }
コード例 #5
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"]);
 }
コード例 #6
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[])));
        }
コード例 #7
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)));
        }
コード例 #8
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));
        }
コード例 #9
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"]);
        }
コード例 #10
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);
 }
コード例 #11
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);
        }
コード例 #12
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);
        }
コード例 #13
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);
        }
コード例 #14
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]);
 }
コード例 #15
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]);
        }
コード例 #16
0
ファイル: TestJsonRpcDispatcher.cs プロジェクト: db48x/KeeFox
        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));
        }
コード例 #17
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));
        }
コード例 #18
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());
        }
コード例 #19
0
ファイル: Server.cs プロジェクト: nobnak/ALE-JAYROCK
 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");
 }
コード例 #20
0
        public void UnknownRequestMembersSkipped()
        {
            JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService());

            JsonRpcServices.GetResult((IDictionary)Parse(server.Process("{ id : 1, foo : [bar], method : 'Dummy', params : [] }")));
        }
コード例 #21
0
 public void NotificationNotSupported()
 {
     JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService());
     server.Process("{ id : null, method : 'Dummy' }");
 }
コード例 #22
0
 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);
 }
コード例 #23
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)));
 }
コード例 #24
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());
        }
コード例 #25
0
 public void UnknownRequestMembersSkipped()
 {
     JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService());
     JsonRpcServices.GetResult((IDictionary) Parse(server.Process("{ id : 1, foo : [bar], method : 'Dummy', params : [] }")));
 }
コード例 #26
0
 public void CallIdempotentMethodWithIdempotencyRequired()
 {
     JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService());
     server.RequireIdempotency = true;
     JsonRpcServices.GetResult((IDictionary) Parse(server.Process("{ id : 1, method : 'Idem', params : [] }")));
 }
コード例 #27
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[])));
 }
コード例 #28
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));
 }
コード例 #29
0
        public void NotificationNotSupported()
        {
            JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService());

            server.Process("{ id : null, method : 'Dummy' }");
        }
コード例 #30
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);
 }
コード例 #31
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));
 }
コード例 #32
0
ファイル: TestJsonRpcDispatcher.cs プロジェクト: db48x/KeeFox
 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);
 }