public async Task StillSubscribedToUserAfterOneOfMultipleConnectionsAssociatedWithUserDisconnects()
        {
            using (var client1 = new TestClient())
                using (var client2 = new TestClient())
                    using (var client3 = new TestClient())
                    {
                        MassTransitHubLifetimeManager <MyHub> manager = BackplaneHarness.HubLifetimeManager;

                        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(Harness.TestTimeout);

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

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

                        await manager.SendUserAsync("userA", "Hello", new object[] { "World" }).OrTimeout(Harness.TestTimeout);
                        await AssertMessageAsync(client1);
                        await AssertMessageAsync(client2);

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

                        await manager.SendUserAsync("userA", "Hello", new object[] { "World" }).OrTimeout(Harness.TestTimeout);
                        await AssertMessageAsync(client2);
                    }
        }
        public async Task SendAllAsyncDoesNotWriteToDisconnectedConnectionsOutput()
        {
            using (var client1 = new TestClient())
                using (var client2 = new TestClient())
                {
                    MassTransitHubLifetimeManager <MyHub> manager = BackplaneHarness.HubLifetimeManager;

                    var connection1 = HubConnectionContextUtils.Create(client1.Connection);
                    var connection2 = HubConnectionContextUtils.Create(client2.Connection);

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

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

                    await manager.OnDisconnectedAsync(connection2).OrTimeout(Harness.TestTimeout);

                    await manager.SendAllAsync("Hello", new object[] { "World" }).OrTimeout(Harness.TestTimeout);

                    Assert.IsTrue(BackplaneHarness.All.Consumed.Select <All <MyHub> >().Any());

                    var message = client1.TryRead() as InvocationMessage;
                    Assert.NotNull(message);
                    Assert.AreEqual("Hello", message.Target);
                    Assert.AreEqual(1, message.Arguments.Length);
                    Assert.AreEqual("World", (string)message.Arguments[0]);

                    Assert.Null(client2.TryRead());
                }
        }
        public async Task DisconnectConnectionRemovesConnectionFromGroup()
        {
            using (var client = new TestClient())
            {
                MassTransitHubLifetimeManager <MyHub> manager = BackplaneHarness.HubLifetimeManager;

                var connection = HubConnectionContextUtils.Create(client.Connection);

                await manager.OnConnectedAsync(connection).OrTimeout(Harness.TestTimeout);

                await manager.AddToGroupAsync(connection.ConnectionId, "name").OrTimeout(Harness.TestTimeout);

                await Task.Delay(2000);

                await manager.OnDisconnectedAsync(connection).OrTimeout(Harness.TestTimeout);

                await Task.Delay(2000);

                await manager.SendGroupAsync("name", "Hello", new object[] { "World" }).OrTimeout(Harness.TestTimeout);

                await Task.Delay(2000);

                Assert.Null(client.TryRead());
            }
        }
        public async Task InvokeAllAsyncWithMultipleServersDoesNotWriteToDisconnectedConnectionsOutput()
        {
            using (var client1 = new TestClient())
                using (var client2 = new TestClient())
                {
                    MassTransitHubLifetimeManager <MyHub> manager1 = Backplane1Harness.HubLifetimeManager;
                    MassTransitHubLifetimeManager <MyHub> manager2 = Backplane2Harness.HubLifetimeManager;

                    var connection1 = HubConnectionContextUtils.Create(client1.Connection);
                    var connection2 = HubConnectionContextUtils.Create(client2.Connection);

                    await manager1.OnConnectedAsync(connection1).OrTimeout(Harness.TestTimeout);

                    await manager2.OnConnectedAsync(connection2).OrTimeout(Harness.TestTimeout);

                    await manager2.OnDisconnectedAsync(connection2).OrTimeout(Harness.TestTimeout);

                    await manager2.SendAllAsync("Hello", new object[] { "World" }).OrTimeout(Harness.TestTimeout);

                    await AssertMessageAsync(client1);

                    Assert.Null(client2.TryRead());
                }
        }