Пример #1
0
        public async Task StillSubscribedToUserAfterOneOfMultipleConnectionsAssociatedWithUserDisconnects(bool fromManager)
        {
            var hubProxy = new HubProxy <MyHub>(_fixture.TestCluster.Client);

            using (var manager = CreateNewHubLifetimeManager <MyHub>())
                using (var client1 = new TestClient())
                    using (var client2 = new TestClient())
                        using (var client3 = new TestClient())
                        {
                            var connection1 = HubConnectionContextUtils.Create(client1.Connection, userIdentifier: "userA");
                            var connection2 = HubConnectionContextUtils.Create(client2.Connection, userIdentifier: "userA");
                            var connection3 = HubConnectionContextUtils.Create(client3.Connection, userIdentifier: "userB");

                            await manager.OnConnectedAsync(connection1).OrTimeout();

                            await manager.OnConnectedAsync(connection2).OrTimeout();

                            await manager.OnConnectedAsync(connection3).OrTimeout();

                            if (fromManager)
                            {
                                await manager.SendUserAsync("userA", "Hello", new object[] { "World" }).OrTimeout();
                            }
                            else
                            {
                                await hubProxy.SendUserAsync("userA", "Hello", "World").OrTimeout();
                            }

                            await AssertMessageAsync(client1);
                            await AssertMessageAsync(client2);

                            // Disconnect one connection for the user
                            await manager.OnDisconnectedAsync(connection1).OrTimeout();

                            _output.WriteLine("Sending.");
                            if (fromManager)
                            {
                                await manager.SendUserAsync("userA", "Hello", new object[] { "World" }).OrTimeout();
                            }
                            else
                            {
                                await hubProxy.SendUserAsync("userA", "Hello", "World").OrTimeout();
                            }

                            _output.WriteLine("Sent.");
                            await AssertMessageAsync(client2);
                        }
        }
Пример #2
0
        public async Task InvokeUserSendsToAllConnectionsForUser(bool fromManager)
        {
            var hubProxy = new HubProxy <MyHub>(_fixture.TestCluster.Client);

            using (var manager = CreateNewHubLifetimeManager <MyHub>())
                using (var client1 = new TestClient())
                    using (var client2 = new TestClient())
                        using (var client3 = new TestClient())
                        {
                            var connection1 = HubConnectionContextUtils.Create(client1.Connection, userIdentifier: "userA");
                            var connection2 = HubConnectionContextUtils.Create(client2.Connection, userIdentifier: "userA");
                            var connection3 = HubConnectionContextUtils.Create(client3.Connection, userIdentifier: "userB");

                            await manager.OnConnectedAsync(connection1).OrTimeout();

                            await manager.OnConnectedAsync(connection2).OrTimeout();

                            await manager.OnConnectedAsync(connection3).OrTimeout();

                            if (fromManager)
                            {
                                await manager.SendUserAsync("userA", "Hello", new object[] { "World" }).OrTimeout();
                            }
                            else
                            {
                                await hubProxy.SendUserAsync("userA", "Hello", "World").OrTimeout();
                            }

                            await AssertMessageAsync(client1);
                            await AssertMessageAsync(client2);
                        }
        }