Пример #1
0
        public async Task InvokeAllAsyncDoesNotWriteToDisconnectedConnectionsOutput()
        {
            using (var client1 = new TestClient())
                using (var client2 = new TestClient())
                {
                    var manager = new RedisHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <RedisHubLifetimeManager <MyHub> >(),
                                                                      Options.Create(new RedisOptions()
                    {
                        Factory = t => new TestConnectionMultiplexer()
                    }));
                    var connection1 = HubConnectionContextUtils.Create(client1.Connection);
                    var connection2 = HubConnectionContextUtils.Create(client2.Connection);

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

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

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

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

                    await AssertMessageAsync(client1);

                    await connection1.DisposeAsync().OrTimeout();

                    await connection2.DisposeAsync().OrTimeout();

                    Assert.Null(client2.TryRead());
                }
        }
        public async Task InvokeAllAsyncDoesNotWriteToDisconnectedConnectionsOutput()
        {
            using (var client1 = new TestClient())
                using (var client2 = new TestClient())
                {
                    var output1 = Channel.CreateUnbounded <HubMessage>();
                    var output2 = Channel.CreateUnbounded <HubMessage>();

                    var manager = new RedisHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <RedisHubLifetimeManager <MyHub> >(),
                                                                      Options.Create(new RedisOptions()
                    {
                        Factory = t => new TestConnectionMultiplexer()
                    }));
                    var connection1 = new HubConnectionContext(output1, client1.Connection);
                    var connection2 = new HubConnectionContext(output2, client2.Connection);

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

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

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

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

                    AssertMessage(output1);

                    Assert.False(output2.In.TryRead(out var item));
                }
        }
Пример #3
0
        public async Task DisconnectConnectionRemovesConnectionFromGroup()
        {
            var manager = new RedisHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <RedisHubLifetimeManager <MyHub> >(),
                                                              Options.Create(new RedisOptions()
            {
                Factory = t => new TestConnectionMultiplexer()
            }));

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

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

                await manager.AddGroupAsync(connection.ConnectionId, "name").OrTimeout();

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

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

                await connection.DisposeAsync().OrTimeout();

                Assert.Null(client.TryRead());
            }
        }
        public async Task DisconnectConnectionRemovesConnectionFromGroup()
        {
            var manager = new RedisHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <RedisHubLifetimeManager <MyHub> >(),
                                                              Options.Create(new RedisOptions()
            {
                Factory = t => new TestConnectionMultiplexer()
            }));

            using (var client = new TestClient())
            {
                var output = Channel.CreateUnbounded <HubMessage>();

                var connection = new HubConnectionContext(output, client.Connection);

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

                await manager.AddGroupAsync(connection.ConnectionId, "name").OrTimeout();

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

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

                Assert.False(output.In.TryRead(out var item));
            }
        }