public void ResolveActionBindsByteArray() { var resolver = new ReflectedMethodDescriptorProvider(); var binder = new DefaultParameterResolver(); var arg = JTokenify(Encoding.UTF8.GetBytes("Hello World!")); MethodDescriptor actionInfo; resolver.TryGetMethod(new HubDescriptor { HubType = typeof(TestHub), Name = "TestHub" }, "MethodWithByteArray", out actionInfo, new IJsonValue[] { arg }); Assert.NotNull(actionInfo); var arg0 = (byte[])binder.ResolveMethodParameters(actionInfo, arg)[0]; Assert.Equal("Hello World!", Encoding.UTF8.GetString(arg0)); }
public void ResolveActionBindsComplexArguments() { var resolver = new ReflectedMethodDescriptorProvider(); var binder = new DefaultParameterResolver(); var arg = new JObject(new JProperty("Age", 1), new JProperty("Address", new JObject( new JProperty("Street", "The street"), new JProperty("Zip", "34567")))); MethodDescriptor actionInfo; resolver.TryGetMethod(new HubDescriptor { HubType = typeof(TestHub), Name = "TestHub" }, "MethodWithComplex", out actionInfo, new IJsonValue[] { new JTokenValue(arg) }); Assert.NotNull(actionInfo); var complex = binder.ResolveMethodParameters(actionInfo, new JTokenValue(arg))[0] as Complex; Assert.NotNull(complex); Assert.Equal(1, complex.Age); Assert.NotNull(complex.Address); Assert.Equal("The street", complex.Address.Street); Assert.Equal(34567, complex.Address.Zip); }
public void ResolveActionBindsNullables() { var resolver = new ReflectedMethodDescriptorProvider(); var binder = new DefaultParameterResolver(); var arg1 = JTokenify(null); var arg2 = JTokenify(null); MethodDescriptor actionInfo; resolver.TryGetMethod(new HubDescriptor { HubType = typeof(TestHub), Name = "TestHub" }, "MethodWithNullables", out actionInfo, new IJsonValue[] { arg1, arg2 }); Assert.NotNull(actionInfo); var args = binder.ResolveMethodParameters(actionInfo, new[] { arg1, arg2 }); Assert.Null(args[0]); Assert.Null(args[1]); }
public void ResolveActionBindsGuid() { var resolver = new ReflectedMethodDescriptorProvider(); var binder = new DefaultParameterResolver(); var arg = JTokenify(new Guid("1d6a1d30-599f-4495-ace7-303fd87204bb")); MethodDescriptor actionInfo; resolver.TryGetMethod(new HubDescriptor { HubType = typeof(TestHub), Name = "TestHub" }, "MethodWithGuid", out actionInfo, new IJsonValue[] { arg }); Assert.NotNull(actionInfo); var arg0 = (Guid)binder.ResolveMethodParameters(actionInfo, new[] { arg })[0]; Assert.Equal(new Guid("1d6a1d30-599f-4495-ace7-303fd87204bb"), arg0); }
public void ResolveActionBindsSimpleArrayArgument() { var resolver = new ReflectedMethodDescriptorProvider(); var binder = new DefaultParameterResolver(); var arg = new JArray(new[] { 1, 2, 3 }); MethodDescriptor actionInfo; resolver.TryGetMethod(new HubDescriptor { HubType = typeof(TestHub), Name = "TestHub" }, "MethodWithArray", out actionInfo, new IJsonValue[] { new JTokenValue(arg) }); Assert.NotNull(actionInfo); var args = binder.ResolveMethodParameters(actionInfo, new[] { new JTokenValue(arg) })[0] as int[]; Assert.Equal(1, args[0]); Assert.Equal(2, args[1]); Assert.Equal(3, args[2]); }