public void MethodIdempotency() { ServiceClass clazz = JsonRpcServices.GetClassFromType(typeof(IdempotencyTestService)); Assert.IsFalse(clazz.GetMethodByName("NonIdempotentMethod").Idempotent); Assert.IsTrue(clazz.GetMethodByName("IdempotentMethod").Idempotent); }
public void MethodWithWarpedParametersButVoidResult() { ServiceClass clazz = JsonRpcServices.GetClassFromType(typeof(ServiceWithMethodsUsingWarpedParameters)); Method foo = clazz.FindMethodByName("FooNoResult"); Assert.AreEqual(typeof(void), foo.ResultType); }
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 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 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 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 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 Invocation() { ServiceClass clazz = JsonRpcServices.GetClassFromType(typeof(TestService)); TestService service = new TestService(); object result = clazz.GetMethodByName("Sum").Invoke(service, null, new object[] { 2, 3 }); Assert.AreEqual(5, result); }
public void AttributeFromMethod() { ServiceClass clazz = JsonRpcServices.GetClassFromType(typeof(TestService)); Method method = clazz.FindMethodByName("Baz"); Assert.AreEqual("Baz", method.Name); Assert.AreEqual("Bar", method.InternalName); }
public void CustomNameViaAttribute() { ServiceClass clazz = JsonRpcServices.GetClassFromType(typeof(TestService)); Method method = clazz.FindMethodByName("Foo"); Assert.AreEqual("Foo", method.Name); Assert.AreEqual("Foo", method.InternalName); }
public void FindFirstCustomAttribute() { ArrayList expectedValues = new ArrayList(new int[] { 12, 34, 56 }); Method method = JsonRpcServices.GetClassFromType(typeof(TestService)).GetMethodByName("Foo"); MyAttribute attribute = (MyAttribute)method.FindFirstCustomAttribute(typeof(MyAttribute)); expectedValues.Remove(attribute.TestValue); Assert.AreEqual(2, expectedValues.Count); }
public void MethodDescriptions() { ServiceClass clazz = JsonRpcServices.GetClassFromType(typeof(TestService)); Assert.AreEqual(0, clazz.GetMethodByName("Foo").Description.Length); Assert.AreEqual(0, clazz.GetMethodByName("Baz").Description.Length); Assert.AreEqual(0, clazz.GetMethodByName("Sum").Description.Length); Assert.AreEqual("Formats a string.", clazz.GetMethodByName("Format").Description); }
public void ResultTypeIsMethodReturnType() { ServiceClass clazz = JsonRpcServices.GetClassFromType(typeof(TestService)); Assert.AreEqual(typeof(void), clazz.GetMethodByName("Foo").ResultType); Assert.AreEqual(typeof(void), clazz.GetMethodByName("Baz").ResultType); Assert.AreEqual(typeof(int), clazz.GetMethodByName("Sum").ResultType); Assert.AreEqual(typeof(string), clazz.GetMethodByName("Format").ResultType); }
public virtual ServiceClass GetClass() { if (_class == null) { _class = JsonRpcServices.GetClassFromType(GetType()); } return(_class); }
public void AffliatedWithService() { ServiceClass clazz = JsonRpcServices.GetClassFromType(typeof(TestService)); foreach (Method method in clazz.GetMethods()) { Assert.AreSame(clazz, method.ServiceClass); } }
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 MethodLookupIsCaseFree() { ServiceClass clazz = JsonRpcServices.GetClassFromType(typeof(TestService)); Method foo = clazz.FindMethodByName("Foo"); Assert.AreEqual("Foo", foo.Name); Assert.AreSame(foo, clazz.FindMethodByName("foo")); Assert.AreSame(foo, clazz.FindMethodByName("FOO")); Assert.AreSame(foo, clazz.FindMethodByName("Foo")); }
public void CustomAttributes() { ArrayList expectedValues = new ArrayList(new int[] { 12, 34, 56 }); MyAttribute[] attributes = (MyAttribute[])JsonRpcServices.GetClassFromType(typeof(TestService)).GetMethodByName("Foo").GetCustomAttributes(typeof(MyAttribute)); Assert.AreEqual(3, attributes.Length); foreach (MyAttribute attribute in attributes) { expectedValues.Remove(attribute.TestValue); } Assert.AreEqual(0, expectedValues.Count); }
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 Parameters() { ServiceClass clazz = JsonRpcServices.GetClassFromType(typeof(TestService)); Parameter[] parameters = clazz.GetMethodByName("Sum").GetParameters(); Assert.AreEqual(2, parameters.Length); Parameter parameter; parameter = parameters[0]; Assert.AreEqual("a", parameter.Name); Assert.AreEqual(typeof(int), parameter.ParameterType); Assert.AreEqual(0, parameter.Position); parameter = parameters[1]; Assert.AreEqual("b", parameters[1].Name); Assert.AreEqual(typeof(int), parameter.ParameterType); Assert.AreEqual(1, parameter.Position); }
public void MethodWithWarpedParametersAndResult() { ServiceClass clazz = JsonRpcServices.GetClassFromType(typeof(ServiceWithMethodsUsingWarpedParameters)); Method foo = clazz.FindMethodByName("Foo"); Assert.AreEqual(typeof(DateTime), foo.ResultType); Parameter[] parameters = foo.GetParameters(); Assert.AreEqual(2, parameters.Length); Parameter parameter; parameter = parameters[0]; Assert.AreEqual("stringArg", parameter.Name); Assert.AreEqual(0, parameter.Position); Assert.AreEqual(typeof(string), parameter.ParameterType); parameter = parameters[1]; Assert.AreEqual("intArg", parameter.Name); Assert.AreEqual(1, parameter.Position); Assert.AreEqual(typeof(int), parameter.ParameterType); }
public void ParamArray() { ServiceClass clazz = JsonRpcServices.GetClassFromType(typeof(TestService)); Assert.IsFalse(clazz.GetMethodByName("Foo").HasParamArray); Assert.IsFalse(clazz.GetMethodByName("Baz").HasParamArray); Method method; Parameter[] parameters; method = clazz.GetMethodByName("Sum"); parameters = method.GetParameters(); Assert.IsFalse(method.HasParamArray); Assert.IsFalse(parameters[0].IsParamArray); Assert.IsFalse(parameters[1].IsParamArray); method = clazz.GetMethodByName("Format"); parameters = method.GetParameters(); Assert.IsTrue(method.HasParamArray); Assert.IsFalse(parameters[0].IsParamArray); Assert.IsTrue(parameters[1].IsParamArray); }
public void CustomServiceName() { ServiceClass clazz = JsonRpcServices.GetClassFromType(typeof(TestService)); Assert.AreEqual("MyService", clazz.Name); }
public ServiceClass GetClass() { return(JsonRpcServices.GetClassFromType(GetType())); }
public void UnknownRequestMembersSkipped() { JsonRpcDispatcher server = new JsonRpcDispatcher(new TestService()); JsonRpcServices.GetResult((IDictionary)Parse(server.Process("{ id : 1, foo : [bar], method : 'Dummy', 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 DefaultNameIsMethodName() { ServiceClass clazz = JsonRpcServices.GetClassFromType(typeof(TestService)); Assert.AreEqual("Foo", clazz.FindMethodByName("Foo").Name); }
public void NullService() { JsonRpcServices.GetClassFromType(null); }
public void UntaggedMethodsNotExported() { ServiceClass clazz = JsonRpcServices.GetClassFromType(typeof(EmptyService)); Assert.AreEqual(0, clazz.GetMethods().Length); }
public void TaggedMethodsExported() { ServiceClass clazz = JsonRpcServices.GetClassFromType(typeof(TestService)); Assert.AreEqual(4, clazz.GetMethods().Length); }