Ejemplo n.º 1
0
        public void ResolveActionExcludesIHubMethods()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            MethodDescriptor actionInfo1;
            MethodDescriptor actionInfo2;
            MethodDescriptor actionInfo3;
            MethodDescriptor actionInfo4;

            resolver.TryGetMethod(new HubDescriptor {
                HubType = typeof(HubWithOverrides2), Name = "TestHub"
            }, "OnDisconnected", out actionInfo1, new IJsonValue[] { });
            resolver.TryGetMethod(new HubDescriptor {
                HubType = typeof(HubWithOverrides2), Name = "TestHub"
            }, "OnReconnected", out actionInfo2, new IJsonValue[] { });
            resolver.TryGetMethod(new HubDescriptor {
                HubType = typeof(HubWithOverrides2), Name = "TestHub"
            }, "OnConnected", out actionInfo3, new IJsonValue[] { });
            resolver.TryGetMethod(new HubDescriptor {
                HubType = typeof(HubWithOverrides2), Name = "TestHub"
            }, "Dispose", out actionInfo4, new IJsonValue[] { });

            Assert.Null(actionInfo1);
            Assert.Null(actionInfo2);
            Assert.Null(actionInfo3);
            Assert.Null(actionInfo4);
        }
        public void ResolveActionExcludesObjectMethods()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            MethodDescriptor actionInfo1;
            MethodDescriptor actionInfo2;
            MethodDescriptor actionInfo3;
            MethodDescriptor actionInfo4;

            resolver.TryGetMethod(new HubDescriptor {
                HubType = typeof(MyHubWithObjectMethods), Name = "TestHub"
            }, "GetHashCode", out actionInfo1, new IJsonValue[] { });
            resolver.TryGetMethod(new HubDescriptor {
                HubType = typeof(MyHubWithObjectMethods), Name = "TestHub"
            }, "Equals", out actionInfo2, new IJsonValue[] { JTokenify("test") });
            resolver.TryGetMethod(new HubDescriptor {
                HubType = typeof(MyHubWithObjectMethods), Name = "TestHub"
            }, "ToString", out actionInfo3, new IJsonValue[] { });
            resolver.TryGetMethod(new HubDescriptor {
                HubType = typeof(MyHubWithObjectMethods), Name = "TestHub"
            }, "Dispose", out actionInfo4, new IJsonValue[] { JTokenify(false) });

            Assert.Null(actionInfo1);
            Assert.Null(actionInfo2);
            Assert.Null(actionInfo3);
            Assert.Null(actionInfo4);
        }
Ejemplo n.º 3
0
        public void ResolveActionBindsComplexArrayArgument()
        {
            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"
            }, "MethodWithArrayOfComplete", out actionInfo, new IJsonValue[] { new JTokenValue(new JArray(new object[] { arg })) });

            Assert.NotNull(actionInfo);
            var complexArray = binder.ResolveMethodParameters(actionInfo, new JTokenValue(new JArray(new object[] { arg })))[0] as Complex[];

            Assert.Equal(1, complexArray.Length);
            var complex = complexArray[0];

            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);
        }
Ejemplo n.º 4
0
        public void ResolveActionExcludeHubMethods()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            MethodDescriptor actionInfo1;
            MethodDescriptor actionInfo2;

            resolver.TryGetMethod(new HubDescriptor {
                HubType = typeof(TestHub), Name = "TestHub"
            }, "AddToGroup", out actionInfo1, new[] { JTokenify("admin") });
            resolver.TryGetMethod(new HubDescriptor {
                HubType = typeof(TestHub), Name = "TestHub"
            }, "RemoveFromGroup", out actionInfo2, new[] { JTokenify("admin") });

            Assert.Null(actionInfo1);
            Assert.Null(actionInfo2);
        }
Ejemplo n.º 5
0
        public void ResolveActionExcludesEvents()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            MethodDescriptor actionInfo1;
            MethodDescriptor actionInfo2;

            resolver.TryGetMethod(new HubDescriptor {
                HubType = typeof(MyHubWithEvents), Name = "TestHub"
            }, "add_MyEvent", out actionInfo1, new IJsonValue[] { JTokenify("x") });
            resolver.TryGetMethod(new HubDescriptor {
                HubType = typeof(MyHubWithEvents), Name = "TestHub"
            }, "remove_MyEvent", out actionInfo2, new IJsonValue[] { JTokenify("x") });

            Assert.Null(actionInfo1);
            Assert.Null(actionInfo2);
        }
Ejemplo n.º 6
0
        public void ResolveActionReturnsNullIfMethodAmbiguous()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            MethodDescriptor actionInfo;

            resolver.TryGetMethod(new HubDescriptor {
                HubType = typeof(TestHub), Name = "TestHub"
            }, "Bar", out actionInfo, new[] { JTokenify(1) });

            Assert.Null(actionInfo);
        }
Ejemplo n.º 7
0
        public void ResolveActionExcludesPropetiesOnBaseTypes()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            MethodDescriptor actionInfo;

            resolver.TryGetMethod(new HubDescriptor {
                HubType = typeof(TestHub), Name = "TestHub"
            }, "get_Clients", out actionInfo, new IJsonValue[] { });

            Assert.Null(actionInfo);
        }
Ejemplo n.º 8
0
        public void ResolveActionLocatesPublicMethodsOnHub()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            MethodDescriptor actionInfo;

            resolver.TryGetMethod(new HubDescriptor {
                HubType = typeof(TestHub), Name = "TestHub"
            }, "Foo", out actionInfo, new IJsonValue[] { });

            Assert.NotNull(actionInfo);
            Assert.Equal("Foo", actionInfo.Name);
            Assert.Equal(0, actionInfo.Parameters.Count);
        }
Ejemplo n.º 9
0
        public void ResolveActionPicksMethodWithMatchingArguments()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            MethodDescriptor actionInfo;

            resolver.TryGetMethod(new HubDescriptor {
                HubType = typeof(TestHub), Name = "TestHub"
            }, "Foo", out actionInfo, new[] { JTokenify(1) });

            Assert.NotNull(actionInfo);
            Assert.Equal("Foo", actionInfo.Name);
            Assert.Equal(1, actionInfo.Parameters.Count);
        }
Ejemplo n.º 10
0
        public void ResolveActionOnDerivedHubFindsMethodOnBasedType()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            MethodDescriptor actionInfo;

            resolver.TryGetMethod(new HubDescriptor {
                Type = typeof(TestDerivedHub), Name = "TestHub"
            }, "Foo", out actionInfo, new IJsonValue[] { });

            Assert.NotNull(actionInfo);
            Assert.Equal("Foo", actionInfo.Name);
            Assert.Equal(0, actionInfo.Parameters.Count);
        }
Ejemplo n.º 11
0
        public void ResolveActionBindsArrayOfByteArray()
        {
            var resolver = new ReflectedMethodDescriptorProvider();
            var binder   = new DefaultParameterResolver();

            var arg = JTokenify(new[] { Encoding.UTF8.GetBytes("Hello World!") });

            MethodDescriptor actionInfo;

            resolver.TryGetMethod(new HubDescriptor {
                HubType = typeof(TestHub), Name = "TestHub"
            }, "MethodListOfByteArray", out actionInfo, new IJsonValue[] { arg });

            Assert.NotNull(actionInfo);
            var arg0 = (List <byte[]>)binder.ResolveMethodParameters(actionInfo, arg)[0];

            Assert.Equal("Hello World!", Encoding.UTF8.GetString(arg0[0]));
        }
Ejemplo n.º 12
0
        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, arg)[0];

            Assert.Equal(new Guid("1d6a1d30-599f-4495-ace7-303fd87204bb"), arg0);
        }
Ejemplo n.º 13
0
        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, arg1, arg2);

            Assert.Null(args[0]);
            Assert.Null(args[1]);
        }
Ejemplo n.º 14
0
        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 JTokenValue(arg))[0] as int[];

            Assert.Equal(1, args[0]);
            Assert.Equal(2, args[1]);
            Assert.Equal(3, args[2]);
        }