コード例 #1
0
        public async Task InvokeAllAsyncWithMultipleServersWritesToAllConnectionsOutput()
        {
            var manager1 = new RedisHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <RedisHubLifetimeManager <MyHub> >(),
                                                               Options.Create(new RedisOptions()
            {
                Factory = t => new TestConnectionMultiplexer()
            }));
            var manager2 = new RedisHubLifetimeManager <MyHub>(new LoggerFactory().CreateLogger <RedisHubLifetimeManager <MyHub> >(),
                                                               Options.Create(new RedisOptions()
            {
                Factory = t => new TestConnectionMultiplexer()
            }));

            using (var client1 = new TestClient())
                using (var client2 = new TestClient())
                {
                    var connection1 = HubConnectionContextUtils.Create(client1.Connection);
                    var connection2 = HubConnectionContextUtils.Create(client2.Connection);

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

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

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

                    await AssertMessageAsync(client1);
                    await AssertMessageAsync(client2);
                }
        }
コード例 #2
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());
                }
        }
コード例 #3
0
        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));
                }
        }