Пример #1
0
        public void ReturningNullFromReconnectAccepted()
        {
            var mockHub = new Mock <SomeHub>()
            {
                CallBase = true
            };

            mockHub.Setup(h => h.Reconnect()).Returns <Task>(null).Verifiable();

            var host = new MemoryHost();

            host.HubPipeline.EnableAutoRejoiningGroups();
            host.Configuration.KeepAlive         = null;
            host.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(1);
            host.Configuration.HeartBeatInterval = TimeSpan.FromSeconds(1);
            host.DependencyResolver.Register(typeof(SomeHub), () => mockHub.Object);
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo");

            var hub = connection.CreateProxy("SomeHub");

            connection.Start(host).Wait();

            // Force Reconnect
            Thread.Sleep(TimeSpan.FromSeconds(3));

            hub.Invoke("AllFoo").Wait();

            Thread.Sleep(TimeSpan.FromSeconds(3));

            connection.Stop();

            mockHub.Verify();
        }
Пример #2
0
        public void AddingToMultipleGroups()
        {
            var host = new MemoryHost();

            host.MapHubs();
            int max = 10;

            var countDown  = new CountDownRange <int>(Enumerable.Range(0, max));
            var connection = new Client.Hubs.HubConnection("http://foo");
            var proxy      = connection.CreateProxy("MultGroupHub");

            proxy.On <User>("onRoomJoin", user =>
            {
                Assert.True(countDown.Mark(user.Index));
            });

            connection.Start(host).Wait();

            for (int i = 0; i < max; i++)
            {
                var user = new User {
                    Index = i, Name = "tester", Room = "test" + i
                };
                proxy.Invoke("login", user).Wait();
                proxy.Invoke("joinRoom", user).Wait();
            }

            Assert.True(countDown.Wait(TimeSpan.FromSeconds(10)), "Didn't receive " + max + " messages. Got " + (max - countDown.Count) + " missed " + String.Join(",", countDown.Left.Select(i => i.ToString())));

            connection.Stop();
        }
Пример #3
0
        public void AuthenticatedAndAuthorizedUserCanInvokeAuthorizedHubMethods()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            host.User = new GenericPrincipal(new GenericIdentity("test"), new string[] { "User", "Admin" });

            var hub = connection.CreateProxy("InvokeAuthHub");
            var wh  = new ManualResetEvent(false);

            hub.On <string, string>("invoked", (id, time) =>
            {
                Assert.NotNull(id);
                wh.Set();
            });

            connection.Start(host).Wait();

            hub.Invoke("InvokedFromClient").Wait();

            Assert.True(wh.WaitOne(TimeSpan.FromSeconds(3)));
            connection.Stop();
        }
Пример #4
0
        public void CreatedHubsGetDisposed()
        {
            var mockDemoHubs = new List <Mock <SignalR.Samples.Hubs.DemoHub.DemoHub> >();

            var host = new MemoryHost();

            host.DependencyResolver.Register(typeof(SignalR.Samples.Hubs.DemoHub.DemoHub), () =>
            {
                var mockDemoHub = new Mock <SignalR.Samples.Hubs.DemoHub.DemoHub>()
                {
                    CallBase = true
                };
                mockDemoHubs.Add(mockDemoHub);
                return(mockDemoHub.Object);
            });
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            connection.Start(host).Wait();

            var result = hub.Invoke <string>("ReadStateValue").Result;

            foreach (var mockDemoHub in mockDemoHubs)
            {
                mockDemoHub.Verify(d => d.Dispose(), Times.Once());
            }

            connection.Stop();
        }
Пример #5
0
        public void UnauthenticatedUserCannotInvokeMethodsWhenAuthenticationRequiredGlobally()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            host.HubPipeline.RequireAuthentication();
            host.User = new GenericPrincipal(new GenericIdentity(""), new string[] { });

            var hub = connection.CreateProxy("NoAuthHub");
            var wh  = new ManualResetEvent(false);

            hub.On <string, string>("invoked", (id, time) =>
            {
                Assert.NotNull(id);
                wh.Set();
            });

            connection.Start(host).Wait();

            Assert.Throws <AggregateException>(() => hub.Invoke("InvokedFromClient").Wait());

            Assert.False(wh.WaitOne(TimeSpan.FromSeconds(3)));
            connection.Stop();
        }
Пример #6
0
        public void AddingToMultipleGroups()
        {
            var host = new MemoryHost();
            host.MapHubs();
            int max = 100;

            var countDown = new CountDown(max);
            var list = Enumerable.Range(0, max).ToList();
            var connection = new Client.Hubs.HubConnection("http://foo");
            var proxy = connection.CreateProxy("MultGroupHub");

            proxy.On<User>("onRoomJoin", user =>
            {
                lock (list)
                {
                    list.Remove(user.Index);
                }

                countDown.Dec();
            });

            connection.Start(host).Wait();

            for (int i = 0; i < max; i++)
            {
                proxy.Invoke("login", new User { Index = i, Name = "tester", Room = "test" + i }).Wait();
            }

            Assert.True(countDown.Wait(TimeSpan.FromSeconds(10)), "Didn't receive " + max + " messages. Got " + (max - countDown.Count) + " missed " + String.Join(",", list.Select(i => i.ToString())));

            connection.Stop();
        }
Пример #7
0
        public void UnauthorizedUserCannotInvokeMethodsInHubsAuthorizedSpecifyingUserAndRole()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            host.User = new GenericPrincipal(new GenericIdentity("test"), new string[] { "User", "Admin" });

            var hub = connection.CreateProxy("UserAndRoleAuthHub");
            var wh  = new ManualResetEvent(false);

            hub.On <string, string>("invoked", (id, time) =>
            {
                Assert.NotNull(id);
                wh.Set();
            });

            connection.Start(host).Wait();

            Assert.Throws <AggregateException>(() => hub.Invoke("InvokedFromClient").Wait());

            Assert.False(wh.WaitOne(TimeSpan.FromSeconds(3)));
            connection.Stop();
        }
Пример #8
0
        public void SendToAll()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection1 = new Client.Hubs.HubConnection("http://foo/");
            var connection2 = new Client.Hubs.HubConnection("http://foo/");

            var wh1 = new ManualResetEventSlim(initialState: false);
            var wh2 = new ManualResetEventSlim(initialState: false);

            var hub1 = connection1.CreateProxy("SendToSome");
            var hub2 = connection2.CreateProxy("SendToSome");

            connection1.Start(host).Wait();
            connection2.Start(host).Wait();

            hub1.On("send", wh1.Set);
            hub2.On("send", wh2.Set);

            hub1.Invoke("SendToAll").Wait();

            Assert.True(wh1.WaitHandle.WaitOne(TimeSpan.FromSeconds(5)));
            Assert.True(wh2.WaitHandle.WaitOne(TimeSpan.FromSeconds(5)));

            connection1.Stop();
            connection2.Stop();
        }
Пример #9
0
        public void SendToSpecificAllFromOutsideOfHub()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection1 = new Client.Hubs.HubConnection("http://foo/");
            var connection2 = new Client.Hubs.HubConnection("http://foo/");
            var hubContext  = host.ConnectionManager.GetHubContext("SendToSome");

            var wh1 = new ManualResetEventSlim(initialState: false);
            var wh2 = new ManualResetEventSlim(initialState: false);

            var hub1 = connection1.CreateProxy("SendToSome");
            var hub2 = connection2.CreateProxy("SendToSome");

            connection1.Start(host).Wait();
            connection2.Start(host).Wait();

            hub1.On("send", wh1.Set);
            hub2.On("send", wh2.Set);

            hubContext.Clients.send();

            Assert.True(wh1.WaitHandle.WaitOne(TimeSpan.FromSeconds(5)));
            Assert.True(wh2.WaitHandle.WaitOne(TimeSpan.FromSeconds(5)));

            connection1.Stop();
            connection2.Stop();
        }
Пример #10
0
        public void DisconnectFiresForHubsWhenConnectionGoesAway()
        {
            var host = new MemoryHost();

            host.MapHubs();
            host.Configuration.DisconnectTimeout = TimeSpan.Zero;
            host.Configuration.HeartBeatInterval = TimeSpan.FromSeconds(5);
            var connectWh    = new ManualResetEventSlim();
            var disconnectWh = new ManualResetEventSlim();

            host.DependencyResolver.Register(typeof(MyHub), () => new MyHub(connectWh, disconnectWh));
            var connection = new Client.Hubs.HubConnection("http://foo/");

            connection.CreateProxy("MyHub");

            // Maximum wait time for disconnect to fire (3 heart beat intervals)
            var disconnectWait = TimeSpan.FromTicks(host.Configuration.HeartBeatInterval.Ticks * 3);

            connection.Start(host).Wait();

            Assert.True(connectWh.Wait(TimeSpan.FromSeconds(10)), "Connect never fired");

            connection.Stop();

            Assert.True(disconnectWh.Wait(disconnectWait), "Disconnect never fired");
        }
Пример #11
0
        public void RejoiningGroupsOnlyReceivesGroupsBelongingToHub()
        {
            var host = new MemoryHost();
            var groupsRequestedToBeRejoined  = new List <string>();
            var groupsRequestedToBeRejoined2 = new List <string>();

            host.DependencyResolver.Register(typeof(RejoinMultGroupHub), () => new RejoinMultGroupHub(groupsRequestedToBeRejoined));
            host.DependencyResolver.Register(typeof(RejoinMultGroupHub2), () => new RejoinMultGroupHub2(groupsRequestedToBeRejoined2));
            host.Configuration.KeepAlive         = null;
            host.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(1);
            host.Configuration.HeartBeatInterval = TimeSpan.FromSeconds(1);
            host.MapHubs();

            var connection = new Client.Hubs.HubConnection("http://foo");
            var proxy      = connection.CreateProxy("RejoinMultGroupHub");
            var proxy2     = connection.CreateProxy("RejoinMultGroupHub2");

            connection.Start(host).Wait();

            var user = new User {
                Name = "tester"
            };

            proxy.Invoke("login", user).Wait();
            proxy2.Invoke("login", user).Wait();

            // Force Reconnect
            Thread.Sleep(TimeSpan.FromSeconds(3));

            proxy.Invoke("joinRoom", user).Wait();
            proxy2.Invoke("joinRoom", user).Wait();

            Thread.Sleep(TimeSpan.FromSeconds(3));

            Assert.True(groupsRequestedToBeRejoined.Contains("foo"));
            Assert.True(groupsRequestedToBeRejoined.Contains("tester"));
            Assert.False(groupsRequestedToBeRejoined.Contains("foo2"));
            Assert.False(groupsRequestedToBeRejoined.Contains("tester2"));
            Assert.True(groupsRequestedToBeRejoined2.Contains("foo2"));
            Assert.True(groupsRequestedToBeRejoined2.Contains("tester2"));
            Assert.False(groupsRequestedToBeRejoined2.Contains("foo"));
            Assert.False(groupsRequestedToBeRejoined2.Contains("tester"));

            connection.Stop();
        }
Пример #12
0
        public void RejoiningGroupsOnlyReceivesGroupsBelongingToHub()
        {
            var logRejoiningGroups = new LogRejoiningGroupsModule();
            var host = new MemoryHost();

            host.HubPipeline.AddModule(logRejoiningGroups);

            host.Configuration.KeepAlive         = null;
            host.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(1);
            host.Configuration.HeartBeatInterval = TimeSpan.FromSeconds(1);
            host.MapHubs();

            var connection = new Client.Hubs.HubConnection("http://foo");
            var proxy      = connection.CreateProxy("MultGroupHub");
            var proxy2     = connection.CreateProxy("MultGroupHub2");

            connection.Start(host).Wait();

            var user = new User {
                Name = "tester"
            };

            proxy.Invoke("login", user).Wait();
            proxy2.Invoke("login", user).Wait();

            // Force Reconnect
            Thread.Sleep(TimeSpan.FromSeconds(3));

            proxy.Invoke("joinRoom", user).Wait();
            proxy2.Invoke("joinRoom", user).Wait();

            Thread.Sleep(TimeSpan.FromSeconds(3));

            Assert.True(logRejoiningGroups.GroupsRejoined["MultGroupHub"].Contains("foo"));
            Assert.True(logRejoiningGroups.GroupsRejoined["MultGroupHub"].Contains("tester"));
            Assert.False(logRejoiningGroups.GroupsRejoined["MultGroupHub"].Contains("foo2"));
            Assert.False(logRejoiningGroups.GroupsRejoined["MultGroupHub"].Contains("tester2"));
            Assert.True(logRejoiningGroups.GroupsRejoined["MultGroupHub2"].Contains("foo2"));
            Assert.True(logRejoiningGroups.GroupsRejoined["MultGroupHub2"].Contains("tester2"));
            Assert.False(logRejoiningGroups.GroupsRejoined["MultGroupHub2"].Contains("foo"));
            Assert.False(logRejoiningGroups.GroupsRejoined["MultGroupHub2"].Contains("tester"));

            connection.Stop();
        }
Пример #13
0
        public void HubGroupsRejoinWhenAutoRejoiningGroupsEnabled()
        {
            var host = new MemoryHost();

            host.HubPipeline.EnableAutoRejoiningGroups();
            host.Configuration.KeepAlive         = null;
            host.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(1);
            host.Configuration.HeartBeatInterval = TimeSpan.FromSeconds(1);
            host.MapHubs();
            int max = 10;

            var countDown = new CountDownRange <int>(Enumerable.Range(0, max));
            var countDownAfterReconnect = new CountDownRange <int>(Enumerable.Range(max, max));
            var connection = new Client.Hubs.HubConnection("http://foo");
            var proxy      = connection.CreateProxy("MultGroupHub");

            proxy.On <User>("onRoomJoin", u =>
            {
                if (u.Index < max)
                {
                    Assert.True(countDown.Mark(u.Index));
                }
                else
                {
                    Assert.True(countDownAfterReconnect.Mark(u.Index));
                }
            });

            connection.Start(host).Wait();

            var user = new User {
                Name = "tester"
            };

            proxy.Invoke("login", user).Wait();

            for (int i = 0; i < max; i++)
            {
                user.Index = i;
                proxy.Invoke("joinRoom", user).Wait();
            }

            // Force Reconnect
            Thread.Sleep(TimeSpan.FromSeconds(3));

            for (int i = max; i < 2 * max; i++)
            {
                user.Index = i;
                proxy.Invoke("joinRoom", user).Wait();
            }

            Assert.True(countDown.Wait(TimeSpan.FromSeconds(3)), "Didn't receive " + max + " messages. Got " + (max - countDown.Count) + " missed " + String.Join(",", countDown.Left.Select(i => i.ToString())));
            Assert.True(countDownAfterReconnect.Wait(TimeSpan.FromSeconds(3)), "Didn't receive " + max + " messages. Got " + (max - countDownAfterReconnect.Count) + " missed " + String.Join(",", countDownAfterReconnect.Left.Select(i => i.ToString())));

            connection.Stop();
        }
Пример #14
0
        public void GenericTaskWithException()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            connection.Start(host).Wait();

            var ex = Assert.Throws<AggregateException>(() => hub.Invoke("GenericTaskWithException").Wait());

            Assert.Equal("Exception of type 'System.Exception' was thrown.", ex.GetBaseException().Message);
        }
Пример #15
0
        public void GetValueFromServer()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            connection.Start(host).Wait();

            var result = hub.Invoke<int>("GetValue").Result;

            Assert.Equal(10, result);
        }
Пример #16
0
        public static void StressGroups()
        {
            var host = new MemoryHost();

            host.MapHubs();
            int max = 15;

            var countDown  = new CountDown(max);
            var list       = Enumerable.Range(0, max).ToList();
            var connection = new Client.Hubs.HubConnection("http://foo");
            var proxy      = connection.CreateProxy("MultGroupHub");

            proxy.On <int>("Do", i =>
            {
                lock (list)
                {
                    if (!list.Remove(i))
                    {
                        Debugger.Break();
                    }
                }

                countDown.Dec();
            });

            try
            {
                connection.Start(host).Wait();

                for (int i = 0; i < max; i++)
                {
                    proxy.Invoke("Do", i).Wait();
                }

                if (!countDown.Wait(TimeSpan.FromSeconds(10)))
                {
                    Console.WriteLine("Didn't receive " + max + " messages. Got " + (max - countDown.Count) + " missed (" + String.Join(",", list.Select(i => i.ToString())) + ")");
                    var bus = host.DependencyResolver.Resolve <INewMessageBus>();
                    Debugger.Break();
                }
            }
            finally
            {
                connection.Stop();
                host.Dispose();

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Пример #17
0
        public void Overloads()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            connection.Start(host).Wait();

            hub.Invoke("Overload").Wait();
            int n = hub.Invoke<int>("Overload", 1).Result;

            Assert.Equal(1, n);
        }
Пример #18
0
        public void GetValueFromServer()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            connection.Start(host).Wait();

            var result = hub.Invoke <int>("GetValue").Result;

            Assert.Equal(10, result);
            connection.Stop();
        }
Пример #19
0
        public void GenericTaskWithException()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            connection.Start(host).Wait();

            var ex = Assert.Throws <AggregateException>(() => hub.Invoke("GenericTaskWithException").Wait());

            Assert.Equal("Exception of type 'System.Exception' was thrown.", ex.GetBaseException().Message);
            connection.Stop();
        }
Пример #20
0
        public void GenericTaskWithContinueWith()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            connection.Start(host).Wait();

            int result = hub.Invoke <int>("GenericTaskWithContinueWith").Result;

            Assert.Equal(4, result);
            connection.Stop();
        }
Пример #21
0
        public void UnsupportedOverloads()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            connection.Start(host).Wait();

            var ex = Assert.Throws <InvalidOperationException>(() => hub.Invoke("UnsupportedOverload", 13177).Wait());

            Assert.Equal("'UnsupportedOverload' method could not be resolved.", ex.GetBaseException().Message);
            connection.Stop();
        }
Пример #22
0
        public void SettingState()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            hub["name"] = "test";

            connection.Start(host).Wait();

            var result = hub.Invoke<string>("ReadStateValue").Result;

            Assert.Equal("test", result);
        }
Пример #23
0
        public void ComplexPersonState()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://site/");

            var hub = connection.CreateProxy("demo");

            var wh = new ManualResetEvent(false);

            connection.Start(host).Wait();

            var person = new SignalR.Samples.Hubs.DemoHub.DemoHub.Person
            {
                Address = new SignalR.Samples.Hubs.DemoHub.DemoHub.Address
                {
                    Street = "Redmond",
                    Zip    = "98052"
                },
                Age  = 25,
                Name = "David"
            };

            var     person1 = hub.Invoke <SignalR.Samples.Hubs.DemoHub.DemoHub.Person>("ComplexType", person).Result;
            var     person2 = hub.GetValue <SignalR.Samples.Hubs.DemoHub.DemoHub.Person>("person");
            JObject obj     = ((dynamic)hub).person;
            var     person3 = obj.ToObject <SignalR.Samples.Hubs.DemoHub.DemoHub.Person>();

            Assert.NotNull(person1);
            Assert.NotNull(person2);
            Assert.NotNull(person3);
            Assert.Equal("David", person1.Name);
            Assert.Equal("David", person2.Name);
            Assert.Equal("David", person3.Name);
            Assert.Equal(25, person1.Age);
            Assert.Equal(25, person2.Age);
            Assert.Equal(25, person3.Age);
            Assert.Equal("Redmond", person1.Address.Street);
            Assert.Equal("Redmond", person2.Address.Street);
            Assert.Equal("Redmond", person3.Address.Street);
            Assert.Equal("98052", person1.Address.Zip);
            Assert.Equal("98052", person2.Address.Zip);
            Assert.Equal("98052", person3.Address.Zip);

            connection.Stop();
        }
Пример #24
0
        public void GenericTaskWithException()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            connection.Start(host).Wait();

            var ex = Assert.Throws <AggregateException>(() => hub.Invoke("GenericTaskWithException").Wait());

            Assert.IsType <InvalidOperationException>(ex.GetBaseException());
            Assert.Contains("System.Exception", ex.GetBaseException().Message);
            connection.Stop();
        }
Пример #25
0
        public void CustomQueryStringRaw()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/", "a=b");

            var hub = connection.CreateProxy("CustomQueryHub");

            connection.Start(host).Wait();

            var result = hub.Invoke <string>("GetQueryString", "a").Result;

            Assert.Equal("b", result);

            connection.Stop();
        }
Пример #26
0
        public void ComplexPersonState()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://site/");

            var hub = connection.CreateProxy("demo");

            var wh = new ManualResetEvent(false);

            connection.Start(host).Wait();

            var person = new SignalR.Samples.Hubs.DemoHub.DemoHub.Person
            {
                Address = new SignalR.Samples.Hubs.DemoHub.DemoHub.Address
                {
                    Street = "Redmond",
                    Zip = "98052"
                },
                Age = 25,
                Name = "David"
            };

            var person1 = hub.Invoke<SignalR.Samples.Hubs.DemoHub.DemoHub.Person>("ComplexType", person).Result;
            var person2 = hub.GetValue<SignalR.Samples.Hubs.DemoHub.DemoHub.Person>("person");
            JObject obj = ((dynamic)hub).person;
            var person3 = obj.ToObject<SignalR.Samples.Hubs.DemoHub.DemoHub.Person>();

            Assert.NotNull(person1);
            Assert.NotNull(person2);
            Assert.NotNull(person3);
            Assert.Equal("David", person1.Name);
            Assert.Equal("David", person2.Name);
            Assert.Equal("David", person3.Name);
            Assert.Equal(25, person1.Age);
            Assert.Equal(25, person2.Age);
            Assert.Equal(25, person3.Age);
            Assert.Equal("Redmond", person1.Address.Street);
            Assert.Equal("Redmond", person2.Address.Street);
            Assert.Equal("Redmond", person3.Address.Street);
            Assert.Equal("98052", person1.Address.Zip);
            Assert.Equal("98052", person2.Address.Zip);
            Assert.Equal("98052", person3.Address.Zip);

            connection.Stop();
        }
Пример #27
0
        public void UnauthenticatedUserCanInvokeMethodsInOutgoingAuthorizedHubs()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            host.User = new GenericPrincipal(new GenericIdentity(""), new string[] { "User", "NotAdmin" });

            var hub = connection.CreateProxy("OutgoingAuthHub");

            connection.Start(host).Wait();

            hub.Invoke("InvokedFromClient").Wait();

            connection.Stop();
        }
Пример #28
0
        public void CreateProxyAfterConnectionStartsThrows()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://site/");

            try
            {
                connection.Start(host).Wait();
                Assert.Throws <InvalidOperationException>(() => connection.CreateProxy("demo"));
            }
            finally
            {
                connection.Stop();
            }
        }
Пример #29
0
        public void Overloads()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            connection.Start(host).Wait();

            hub.Invoke("Overload").Wait();
            int n = hub.Invoke <int>("Overload", 1).Result;

            Assert.Equal(1, n);
            connection.Stop();
        }
Пример #30
0
        public void SettingState()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            connection.Start(host).Wait();

            var result = hub.Invoke <string>("SetStateValue", "test").Result;

            Assert.Equal("test", result);
            Assert.Equal("test", hub["Company"]);

            connection.Stop();
        }
Пример #31
0
        public void ReadingState()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            hub["name"] = "test";

            connection.Start(host).Wait();

            var result = hub.Invoke <string>("ReadStateValue").Result;

            Assert.Equal("test", result);

            connection.Stop();
        }
Пример #32
0
        public void DynamicInvokeTest()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var    connection = new Client.Hubs.HubConnection("http://site/");
            string callback   = "!!!CallMeBack!!!";

            var hub = connection.CreateProxy("demo");

            var wh = new ManualResetEvent(false);

            hub.On(callback, () => wh.Set());

            connection.Start(host).Wait();

            hub.Invoke("DynamicInvoke", callback).Wait();

            Assert.True(wh.WaitOne(TimeSpan.FromSeconds(5)));
            connection.Stop();
        }
Пример #33
0
        public void ChangeHubUrl()
        {
            var host = new MemoryHost();
            host.MapHubs("/foo");
            var connection = new Client.Hubs.HubConnection("http://site/foo", useDefaultUrl: false);

            var hub = connection.CreateProxy("demo");

            var wh = new ManualResetEvent(false);

            hub.On("signal", id =>
            {
                Assert.NotNull(id);
                wh.Set();
            });

            connection.Start(host).Wait();

            hub.Invoke("DynamicTask").Wait();

            Assert.True(wh.WaitOne(TimeSpan.FromSeconds(5)));
        }
Пример #34
0
        public void AuthenticatedUserCanReceiveHubMessagesFromOutgoingAuthorizedHubs()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            host.User = new GenericPrincipal(new GenericIdentity("Admin"), new string[] { });

            var hub = connection.CreateProxy("OutgoingAuthHub");
            var wh  = new ManualResetEvent(false);

            hub.On <string, string, object>("joined", (id, time, authInfo) =>
            {
                Assert.NotNull(id);
                wh.Set();
            });

            connection.Start(host).Wait();

            Assert.True(wh.WaitOne(TimeSpan.FromSeconds(3)));
            connection.Stop();
        }
Пример #35
0
        public void AuthenticatedAndAuthorizedUserCanInvokeMethodsInHubsAuthorizedWithRoles()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            host.User = new GenericPrincipal(new GenericIdentity("test"), new string[] { "Admin" });

            var hub = connection.CreateProxy("AdminAuthHub");
            var wh = new ManualResetEvent(false);
            hub.On<string, string>("invoked", (id, time) =>
            {
                Assert.NotNull(id);
                wh.Set();
            });

            connection.Start(host).Wait();

            hub.Invoke("InvokedFromClient").Wait();

            Assert.True(wh.WaitOne(TimeSpan.FromSeconds(3)));
            connection.Stop();
        }
Пример #36
0
        public void DisconnectFiresForHubsWhenConnectionGoesAway()
        {
            var host = new MemoryHost();
            host.MapHubs();
            host.Configuration.DisconnectTimeout = TimeSpan.Zero;
            host.Configuration.HeartBeatInterval = TimeSpan.FromSeconds(5);
            var connectWh = new ManualResetEventSlim();
            var disconnectWh = new ManualResetEventSlim();
            host.DependencyResolver.Register(typeof(MyHub), () => new MyHub(connectWh, disconnectWh));
            var connection = new Client.Hubs.HubConnection("http://foo/");

            connection.CreateProxy("MyHub");

            // Maximum wait time for disconnect to fire (3 heart beat intervals)
            var disconnectWait = TimeSpan.FromTicks(host.Configuration.HeartBeatInterval.Ticks * 3);

            connection.Start(host).Wait();

            Assert.True(connectWh.Wait(TimeSpan.FromSeconds(10)), "Connect never fired");

            connection.Stop();

            Assert.True(disconnectWh.Wait(disconnectWait), "Disconnect never fired");
        }
Пример #37
0
        public void GuidTest()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://site/");

            var hub = connection.CreateProxy("demo");

            var wh = new ManualResetEvent(false);

            hub.On <Guid>("TestGuid", id =>
            {
                Assert.NotNull(id);
                wh.Set();
            });

            connection.Start(host).Wait();

            hub.Invoke("TestGuid").Wait();

            Assert.True(wh.WaitOne(TimeSpan.FromSeconds(5)));
            connection.Stop();
        }
Пример #38
0
        public void UnauthenticatedUserCannotReceiveHubMessagesWhenAuthenticationRequiredGlobally()
        {
            var host = new MemoryHost();

            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            host.HubPipeline.RequireAuthentication();
            host.User = new GenericPrincipal(new GenericIdentity(""), new string[] { });

            var hub = connection.CreateProxy("NoAuthHub");
            var wh  = new ManualResetEvent(false);

            hub.On <string, string, object>("joined", (id, time, authInfo) =>
            {
                Assert.NotNull(id);
                wh.Set();
            });

            connection.Start(host).Wait();

            Assert.False(wh.WaitOne(TimeSpan.FromSeconds(3)));
            connection.Stop();
        }
Пример #39
0
        public void ChangeHubUrl()
        {
            var host = new MemoryHost();

            host.MapHubs("/foo");
            var connection = new Client.Hubs.HubConnection("http://site/foo", useDefaultUrl: false);

            var hub = connection.CreateProxy("demo");

            var wh = new ManualResetEvent(false);

            hub.On("signal", id =>
            {
                Assert.NotNull(id);
                wh.Set();
            });

            connection.Start(host).Wait();

            hub.Invoke("DynamicTask").Wait();

            Assert.True(wh.WaitOne(TimeSpan.FromSeconds(5)));
            connection.Stop();
        }
Пример #40
0
        public static void StressGroups()
        {
            var host = new MemoryHost();
            host.HubPipeline.EnableAutoRejoiningGroups();
            host.MapHubs();
            int max = 15;

            var countDown = new CountDown(max);
            var list = Enumerable.Range(0, max).ToList();
            var connection = new Client.Hubs.HubConnection("http://foo");
            var proxy = connection.CreateProxy("MultGroupHub");

            var bus = (MessageBus)host.DependencyResolver.Resolve<IMessageBus>();

            proxy.On<int>("Do", i =>
            {
                lock (list)
                {
                    if (!list.Remove(i))
                    {
                        Debugger.Break();
                    }
                }

                countDown.Dec();
            });

            try
            {
                connection.Start(host).Wait();

                for (int i = 0; i < max; i++)
                {
                    proxy.Invoke("Do", i).Wait();
                }

                int retry = 3;
                bool result = false;

                do
                {
                    result = countDown.Wait(TimeSpan.FromSeconds(10));
                    if (!result)
                    {
                        Console.WriteLine("Didn't receive " + max + " messages. Got " + (max - countDown.Count) + " missed (" + String.Join(",", list.Select(i => i.ToString())) + ")");
                        Console.WriteLine("A=" + bus.AllocatedWorkers + " B=" + bus.BusyWorkers);
                        countDown.Reset();
                    }

                    retry--;

                } while (retry > 0);

                if (!result)
                {
                    Console.WriteLine("A=" + bus.AllocatedWorkers + " B=" + bus.BusyWorkers);
                    Debugger.Break();
                }
            }
            finally
            {
                connection.Stop();
                host.Dispose();

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Пример #41
0
        public void TaskWithException()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            connection.Start(host).Wait();

            var ex = Assert.Throws<AggregateException>(() => hub.Invoke("TaskWithException").Wait());

            Assert.IsType<InvalidOperationException>(ex.GetBaseException());
            Assert.Contains("System.Exception", ex.GetBaseException().Message);
            connection.Stop();
        }
Пример #42
0
        public static void StressGroups()
        {
            var host = new MemoryHost();
            host.MapHubs();
            int max = 15;

            var countDown = new CountDown(max);
            var list = Enumerable.Range(0, max).ToList();
            var connection = new Client.Hubs.HubConnection("http://foo");
            var proxy = connection.CreateProxy("MultGroupHub");

            proxy.On<int>("Do", i =>
            {
                lock (list)
                {
                    if (!list.Remove(i))
                    {
                        Debugger.Break();
                    }
                }

                countDown.Dec();
            });

            try
            {
                connection.Start(new Client.Transports.ServerSentEventsTransport(host)).Wait();

                for (int i = 0; i < max; i++)
                {
                    proxy.Invoke("Do", i).Wait();
                }

                if (!countDown.Wait(TimeSpan.FromSeconds(10)))
                {
                    Console.WriteLine("Didn't receive " + max + " messages. Got " + (max - countDown.Count) + " missed (" + String.Join(",", list.Select(i => i.ToString())) + ")");
                    var bus = host.DependencyResolver.Resolve<INewMessageBus>();
                    Debugger.Break();
                }
            }
            finally
            {
                connection.Stop();
                host.Dispose();

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Пример #43
0
        public void UnauthenticatedUserCanInvokeMethodsInOutgoingAuthorizedHubs()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            host.User = new GenericPrincipal(new GenericIdentity(""), new string[] { "User", "NotAdmin" });

            var hub = connection.CreateProxy("OutgoingAuthHub");

            connection.Start(host).Wait();

            hub.Invoke("InvokedFromClient").Wait();

            connection.Stop();
        }
Пример #44
0
        public void UnauthenticatedUserCannotInvokeMethodsWhenAuthenticationRequiredGlobally()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            host.HubPipeline.RequireAuthentication();
            host.User = new GenericPrincipal(new GenericIdentity(""), new string[] { });

            var hub = connection.CreateProxy("NoAuthHub");
            var wh = new ManualResetEvent(false);
            hub.On<string, string>("invoked", (id, time) =>
            {
                Assert.NotNull(id);
                wh.Set();
            });

            connection.Start(host).Wait();

            Assert.Throws<AggregateException>(() => hub.Invoke("InvokedFromClient").Wait());

            Assert.False(wh.WaitOne(TimeSpan.FromSeconds(3)));
            connection.Stop();
        }
Пример #45
0
        public void SendToSpecificClientFromOutsideOfHub()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection1 = new Client.Hubs.HubConnection("http://foo/");
            var hubContext = host.ConnectionManager.GetHubContext("SendToSome");

            var wh1 = new ManualResetEventSlim(initialState: false);

            var hub1 = connection1.CreateProxy("SendToSome");

            connection1.Start(host).Wait();

            hub1.On("send", wh1.Set);

            hubContext.Client(connection1.ConnectionId).send();

            Assert.True(wh1.WaitHandle.WaitOne(TimeSpan.FromSeconds(5)));

            connection1.Stop();
        }
Пример #46
0
        public void CustomQueryStringRaw()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/", "a=b");

            var hub = connection.CreateProxy("CustomQueryHub");

            connection.Start(host).Wait();

            var result = hub.Invoke<string>("GetQueryString", "a").Result;

            Assert.Equal("b", result);

            connection.Stop();
        }
Пример #47
0
        public void RejoiningGroupsOnlyReceivesGroupsBelongingToHub()
        {
            var host = new MemoryHost();
            var groupsRequestedToBeRejoined = new List<string>();
            var groupsRequestedToBeRejoined2 = new List<string>();
            host.DependencyResolver.Register(typeof(RejoinMultGroupHub), () => new RejoinMultGroupHub(groupsRequestedToBeRejoined));
            host.DependencyResolver.Register(typeof(RejoinMultGroupHub2), () => new RejoinMultGroupHub2(groupsRequestedToBeRejoined2));
            host.Configuration.KeepAlive = null;
            host.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(1);
            host.Configuration.HeartBeatInterval = TimeSpan.FromSeconds(1);
            host.MapHubs();

            var connection = new Client.Hubs.HubConnection("http://foo");
            var proxy = connection.CreateProxy("RejoinMultGroupHub");
            var proxy2 = connection.CreateProxy("RejoinMultGroupHub2");

            connection.Start(host).Wait();

            var user = new User { Name = "tester" };
            proxy.Invoke("login", user).Wait();
            proxy2.Invoke("login", user).Wait();

            // Force Reconnect
            Thread.Sleep(TimeSpan.FromSeconds(3));

            proxy.Invoke("joinRoom", user).Wait();
            proxy2.Invoke("joinRoom", user).Wait();

            Thread.Sleep(TimeSpan.FromSeconds(3));

            Assert.True(groupsRequestedToBeRejoined.Contains("foo"));
            Assert.True(groupsRequestedToBeRejoined.Contains("tester"));
            Assert.False(groupsRequestedToBeRejoined.Contains("foo2"));
            Assert.False(groupsRequestedToBeRejoined.Contains("tester2"));
            Assert.True(groupsRequestedToBeRejoined2.Contains("foo2"));
            Assert.True(groupsRequestedToBeRejoined2.Contains("tester2"));
            Assert.False(groupsRequestedToBeRejoined2.Contains("foo"));
            Assert.False(groupsRequestedToBeRejoined2.Contains("tester"));

            connection.Stop();
        }
Пример #48
0
        public void UnauthenticatedUserCannotReceiveHubMessagesWhenAuthenticationRequiredGlobally()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            host.HubPipeline.RequireAuthentication();
            host.User = new GenericPrincipal(new GenericIdentity(""), new string[] { });

            var hub = connection.CreateProxy("NoAuthHub");
            var wh = new ManualResetEvent(false);
            hub.On<string, string, object>("joined", (id, time, authInfo) =>
            {
                Assert.NotNull(id);
                wh.Set();
            });

            connection.Start(host).Wait();

            Assert.False(wh.WaitOne(TimeSpan.FromSeconds(3)));
            connection.Stop();
        }
Пример #49
0
        public void ReturningNullFromReconnectAccepted()
        {
            var mockHub = new Mock<SomeHub>() { CallBase = true };
            mockHub.Setup(h => h.OnReconnected()).Returns<Task>(null).Verifiable();

            var host = new MemoryHost();
            host.HubPipeline.EnableAutoRejoiningGroups();
            host.Configuration.KeepAlive = null;
            host.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(1);
            host.Configuration.HeartBeatInterval = TimeSpan.FromSeconds(1);
            host.DependencyResolver.Register(typeof(SomeHub), () => mockHub.Object);
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo");

            var hub = connection.CreateProxy("SomeHub");
            connection.Start(host).Wait();

            // Force Reconnect
            Thread.Sleep(TimeSpan.FromSeconds(3));

            hub.Invoke("AllFoo").Wait();

            Thread.Sleep(TimeSpan.FromSeconds(3));

            connection.Stop();

            mockHub.Verify();
        }
Пример #50
0
        public void AuthenticatedAndAuthorizedUserCanReceiveHubMessagesFromHubsAuthorizedSpecifyingUserAndRole()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            host.User = new GenericPrincipal(new GenericIdentity("User"), new string[] { "test", "Admin" });

            var hub = connection.CreateProxy("UserAndRoleAuthHub");
            var wh = new ManualResetEvent(false);
            hub.On<string, string, object>("joined", (id, time, authInfo) =>
            {
                Assert.NotNull(id);
                wh.Set();
            });

            connection.Start(host).Wait();

            Assert.True(wh.WaitOne(TimeSpan.FromSeconds(3)));
            connection.Stop();
        }
Пример #51
0
        public void SendToSelf()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection1 = new Client.Hubs.HubConnection("http://foo/");
            var connection2 = new Client.Hubs.HubConnection("http://foo/");

            var wh1 = new ManualResetEventSlim(initialState: false);
            var wh2 = new ManualResetEventSlim(initialState: false);

            var hub1 = connection1.CreateProxy("SendToSome");
            var hub2 = connection2.CreateProxy("SendToSome");

            connection1.Start(host).Wait();
            connection2.Start(host).Wait();

            hub1.On("send", wh1.Set);
            hub2.On("send", wh2.Set);

            hub1.Invoke("SendToSelf").Wait();

            Assert.True(wh1.WaitHandle.WaitOne(TimeSpan.FromSeconds(5)));
            Assert.False(wh2.WaitHandle.WaitOne(TimeSpan.FromSeconds(5)));

            connection1.Stop();
            connection2.Stop();
        }
Пример #52
0
        public void HubGroupsRejoinWhenRejoiningGroupsOverridden()
        {
            var host = new MemoryHost();
            host.Configuration.KeepAlive = null;
            host.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(1);
            host.Configuration.HeartBeatInterval = TimeSpan.FromSeconds(1);
            host.MapHubs();
            int max = 10;

            var countDown = new CountDownRange<int>(Enumerable.Range(0, max));
            var countDownAfterReconnect = new CountDownRange<int>(Enumerable.Range(max, max));
            var connection = new Client.Hubs.HubConnection("http://foo");
            var proxy = connection.CreateProxy("RejoinMultGroupHub");

            proxy.On<User>("onRoomJoin", u =>
            {
                if (u.Index < max)
                {
                    Assert.True(countDown.Mark(u.Index));
                }
                else
                {
                    Assert.True(countDownAfterReconnect.Mark(u.Index));
                }
            });

            connection.Start(host).Wait();

            var user = new User { Name = "tester" };
            proxy.Invoke("login", user).Wait();

            for (int i = 0; i < max; i++)
            {
                user.Index = i;
                proxy.Invoke("joinRoom", user).Wait();
            }

            // Force Reconnect
            Thread.Sleep(TimeSpan.FromSeconds(3));

            for (int i = max; i < 2 * max; i++)
            {
                user.Index = i;
                proxy.Invoke("joinRoom", user).Wait();
            }

            Assert.True(countDown.Wait(TimeSpan.FromSeconds(30)), "Didn't receive " + max + " messages. Got " + (max - countDown.Count) + " missed " + String.Join(",", countDown.Left.Select(i => i.ToString())));
            Assert.True(countDownAfterReconnect.Wait(TimeSpan.FromSeconds(30)), "Didn't receive " + max + " messages. Got " + (max - countDownAfterReconnect.Count) + " missed " + String.Join(",", countDownAfterReconnect.Left.Select(i => i.ToString())));

            connection.Stop();
        }
Пример #53
0
        public void UnauthorizedUserCannotInvokeMethodsInHubsAuthorizedSpecifyingUserAndRole()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            host.User = new GenericPrincipal(new GenericIdentity("test"), new string[] { "User", "Admin" });

            var hub = connection.CreateProxy("UserAndRoleAuthHub");
            var wh = new ManualResetEvent(false);
            hub.On<string, string>("invoked", (id, time) =>
            {
                Assert.NotNull(id);
                wh.Set();
            });

            connection.Start(host).Wait();

            Assert.Throws<AggregateException>(() => hub.Invoke("InvokedFromClient").Wait());

            Assert.False(wh.WaitOne(TimeSpan.FromSeconds(3)));
            connection.Stop();
        }
Пример #54
0
        public void CreateProxyAfterConnectionStartsThrows()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://site/");

            try
            {
                connection.Start(host).Wait();
                Assert.Throws<InvalidOperationException>(() => connection.CreateProxy("demo"));
            }
            finally
            {
                connection.Stop();
            }
        }
Пример #55
0
        public void GuidTest()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://site/");

            var hub = connection.CreateProxy("demo");

            var wh = new ManualResetEvent(false);

            hub.On<Guid>("TestGuid", id =>
            {
                Assert.NotNull(id);
                wh.Set();
            });

            connection.Start(host).Wait();

            hub.Invoke("TestGuid").Wait();

            Assert.True(wh.WaitOne(TimeSpan.FromSeconds(5)));
            connection.Stop();
        }
Пример #56
0
        public void CreatedHubsGetDisposed()
        {
            var mockDemoHubs = new List<Mock<SignalR.Samples.Hubs.DemoHub.DemoHub>>();

            var host = new MemoryHost();
            host.DependencyResolver.Register(typeof(SignalR.Samples.Hubs.DemoHub.DemoHub), () =>
            {
                var mockDemoHub = new Mock<SignalR.Samples.Hubs.DemoHub.DemoHub>() { CallBase = true };
                mockDemoHubs.Add(mockDemoHub);
                return mockDemoHub.Object;
            });
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            connection.Start(host).Wait();

            var result = hub.Invoke<string>("ReadStateValue").Result;

            foreach (var mockDemoHub in mockDemoHubs)
            {
                mockDemoHub.Verify(d => d.Dispose(), Times.Once());
            }

            connection.Stop();
        }
Пример #57
0
        public void UnsupportedOverloads()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            connection.Start(host).Wait();

            var ex = Assert.Throws<InvalidOperationException>(() => hub.Invoke("UnsupportedOverload", 13177).Wait());

            Assert.Equal("'UnsupportedOverload' method could not be resolved.", ex.GetBaseException().Message);
            connection.Stop();
        }
Пример #58
0
        public void GenericTaskWithContinueWith()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://foo/");

            var hub = connection.CreateProxy("demo");

            connection.Start(host).Wait();

            int result = hub.Invoke<int>("GenericTaskWithContinueWith").Result;

            Assert.Equal(4, result);
            connection.Stop();
        }
Пример #59
0
        public void DynamicInvokeTest()
        {
            var host = new MemoryHost();
            host.MapHubs();
            var connection = new Client.Hubs.HubConnection("http://site/");
            string callback = "!!!CallMeBack!!!";

            var hub = connection.CreateProxy("demo");

            var wh = new ManualResetEvent(false);

            hub.On(callback, () => wh.Set());

            connection.Start(host).Wait();

            hub.Invoke("DynamicInvoke", callback).Wait();

            Assert.True(wh.WaitOne(TimeSpan.FromSeconds(5)));
            connection.Stop();
        }
Пример #60
0
        public void RejoiningGroupsOnlyReceivesGroupsBelongingToHub()
        {
            var logRejoiningGroups = new LogRejoiningGroupsModule();
            var host = new MemoryHost();
            host.HubPipeline.AddModule(logRejoiningGroups);

            host.Configuration.KeepAlive = null;
            host.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(1);
            host.Configuration.HeartBeatInterval = TimeSpan.FromSeconds(1);
            host.MapHubs();

            var connection = new Client.Hubs.HubConnection("http://foo");
            var proxy = connection.CreateProxy("MultGroupHub");
            var proxy2 = connection.CreateProxy("MultGroupHub2");

            connection.Start(host).Wait();

            var user = new User { Name = "tester" };
            proxy.Invoke("login", user).Wait();
            proxy2.Invoke("login", user).Wait();

            // Force Reconnect
            Thread.Sleep(TimeSpan.FromSeconds(3));

            proxy.Invoke("joinRoom", user).Wait();
            proxy2.Invoke("joinRoom", user).Wait();

            Thread.Sleep(TimeSpan.FromSeconds(3));

            Assert.True(logRejoiningGroups.GroupsRejoined["MultGroupHub"].Contains("foo"));
            Assert.True(logRejoiningGroups.GroupsRejoined["MultGroupHub"].Contains("tester"));
            Assert.False(logRejoiningGroups.GroupsRejoined["MultGroupHub"].Contains("foo2"));
            Assert.False(logRejoiningGroups.GroupsRejoined["MultGroupHub"].Contains("tester2"));
            Assert.True(logRejoiningGroups.GroupsRejoined["MultGroupHub2"].Contains("foo2"));
            Assert.True(logRejoiningGroups.GroupsRejoined["MultGroupHub2"].Contains("tester2"));
            Assert.False(logRejoiningGroups.GroupsRejoined["MultGroupHub2"].Contains("foo"));
            Assert.False(logRejoiningGroups.GroupsRejoined["MultGroupHub2"].Contains("tester"));

            connection.Stop();
        }