コード例 #1
0
        public async Task SendGroupAsyncWritesToAllConnectionsInGroupsOutput(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())
                    {
                        var connection1 = HubConnectionContextUtils.Create(client1.Connection);
                        var connection2 = HubConnectionContextUtils.Create(client2.Connection);

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

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

                        if (fromManager)
                        {
                            await manager.AddToGroupAsync(connection1.ConnectionId, "group").OrTimeout();

                            await manager.AddToGroupAsync(connection2.ConnectionId, "group2").OrTimeout();

                            await manager.SendGroupsAsync(new[] { "group", "group2" }, "Hello", new object[] { "World" }).OrTimeout();
                        }
                        else
                        {
                            await hubProxy.AddToGroupAsync(connection1.ConnectionId, "group").OrTimeout();

                            await hubProxy.AddToGroupAsync(connection2.ConnectionId, "group2").OrTimeout();

                            await hubProxy.SendGroupsAsync(new[] { "group", "group2" }, "Hello", "World").OrTimeout();
                        }

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