public async Task InvokeAsync_WhenNotConnectedAfterFailedAttemptsExceeds_ShouldForceDisconnect()
        {
            using (var client1 = new TestClient())
                using (var client2 = new TestClient())
                {
                    var manager     = new OrleansHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <OrleansHubLifetimeManager <MyHub> >(), _fixture.ClientProvider);
                    var connection1 = HubConnectionContextUtils.Create(client1.Connection);
                    var connection2 = HubConnectionContextUtils.Create(client2.Connection);

                    await manager.OnConnectedAsync(connection1);

                    var groupName = "flex";
                    await manager.AddToGroupAsync(connection1.ConnectionId, groupName);

                    await manager.AddToGroupAsync(connection2.ConnectionId, groupName);

                    await manager.SendGroupAsync(groupName, "Hello", new object[] { "World" });

                    var grain            = _fixture.ClientProvider.GetClient().GetGroupGrain("MyHub", groupName);
                    var connectionsCount = await grain.Count();

                    await AssertMessageAsync(client1);

                    Assert.Equal(2, connectionsCount);

                    await manager.SendGroupAsync(groupName, "Hello", new object[] { "World" });

                    await manager.SendGroupAsync(groupName, "Hello", new object[] { "World" });

                    connectionsCount = await grain.Count();

                    Assert.Equal(1, connectionsCount);
                }
        }
        public async Task InvokeGroupAsync_WhenOneDisconnected_ShouldDeliverOthers()
        {
            using (var client1 = new TestClient())
                using (var client2 = new TestClient())
                    using (var client3 = new TestClient())
                    {
                        var manager     = new OrleansHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <OrleansHubLifetimeManager <MyHub> >(), _fixture.ClientProvider);
                        var connection1 = HubConnectionContextUtils.Create(client1.Connection);
                        var connection2 = HubConnectionContextUtils.Create(client2.Connection);
                        var connection3 = HubConnectionContextUtils.Create(client3.Connection);

                        await manager.OnConnectedAsync(connection1);

                        await manager.OnConnectedAsync(connection2);

                        var groupName = "gunit";
                        await manager.AddToGroupAsync(connection1.ConnectionId, groupName);

                        await manager.AddToGroupAsync(connection2.ConnectionId, groupName);

                        await manager.AddToGroupAsync(connection3.ConnectionId, groupName);

                        await manager.SendGroupAsync(groupName, "Hello", new object[] { "World" });

                        await AssertMessageAsync(client1);
                        await AssertMessageAsync(client2);
                    }
        }
        public async Task RemoveGroupAsync_ForConnection_OnDifferentServer_Works()
        {
            var manager1 = new OrleansHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <OrleansHubLifetimeManager <MyHub> >(), this._fixture.ClientProvider);
            var manager2 = new OrleansHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <OrleansHubLifetimeManager <MyHub> >(), this._fixture.ClientProvider);

            using (var client = new TestClient())
            {
                var connection = HubConnectionContextUtils.Create(client.Connection);

                await manager1.OnConnectedAsync(connection);

                await manager1.AddToGroupAsync(connection.ConnectionId, "snoop");

                await manager2.SendGroupAsync("snoop", "Hello", new object[] { "World" });

                await AssertMessageAsync(client);

                await manager2.RemoveFromGroupAsync(connection.ConnectionId, "snoop");

                await manager2.SendGroupAsync("snoop", "Hello", new object[] { "World" });

                Assert.Null(client.TryRead());
            }
        }
        public async Task InvokeGroupAsync_OnServer_WithoutConnection_WritesOutputTo_GroupConnection()
        {
            var manager1 = new OrleansHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <OrleansHubLifetimeManager <MyHub> >(), this._fixture.ClientProvider);
            var manager2 = new OrleansHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <OrleansHubLifetimeManager <MyHub> >(), this._fixture.ClientProvider);

            using (var client = new TestClient())
            {
                var connection = HubConnectionContextUtils.Create(client.Connection);

                await manager1.OnConnectedAsync(connection);

                await manager1.AddToGroupAsync(connection.ConnectionId, "tupac");

                await manager2.SendGroupAsync("tupac", "Hello", new object[] { "World" });

                await AssertMessageAsync(client);
            }
        }
        public async Task InvokeGroupAsync_WritesTo_AllConnections_InGroup_Output()
        {
            using (var client1 = new TestClient())
                using (var client2 = new TestClient())
                {
                    var manager     = new OrleansHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <OrleansHubLifetimeManager <MyHub> >(), this._fixture.ClientProvider);
                    var connection1 = HubConnectionContextUtils.Create(client1.Connection);
                    var connection2 = HubConnectionContextUtils.Create(client2.Connection);

                    await manager.OnConnectedAsync(connection1);

                    await manager.OnConnectedAsync(connection2);

                    await manager.AddToGroupAsync(connection1.ConnectionId, "gunit");

                    await manager.SendGroupAsync("gunit", "Hello", new object[] { "World" });

                    await AssertMessageAsync(client1);

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