コード例 #1
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"]);
 }
コード例 #2
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 = ((JArray) response["result"]).ToArray();
     Assert.AreEqual(new object[] { 3, "two", 1 }, result);
 }
コード例 #3
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);
 }
コード例 #4
0
 public void EchoCall()
 {
     EchoService service = new EchoService();
     JsonRpcDispatcher server = new JsonRpcDispatcher(service);
     service.NextResult = "Hello";
     string responseString = server.Process("{ id : 1, method : 'Say', params : [ 'Hello' ] }");
     IDictionary response = (IDictionary) Parse(responseString);
     Assert.AreEqual(1, response["id"]);
     Assert.IsFalse(response.Contains("error"));
     Assert.AreEqual("Say", service.LastMethodName);
     Assert.AreEqual(new object[] { "Hello" }, service.LastArguments);
     Assert.AreEqual("Hello", response["result"]);
 }
コード例 #5
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));
 }
コード例 #6
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);
 }
コード例 #7
0
 public void NotificationNotSupported()
 {
     JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService());
     server.Process("{ id : null, method : 'Dummy' }");
 }
コード例 #8
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[])));
 }
コード例 #9
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)));
 }
コード例 #10
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));
 }
コード例 #11
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));
        }