public async Task SendToUsersFromOutsideOfHub()
        {
            using (var host = new MemoryHost())
            {
                IHubContext <IBasicClient> hubContext = HubFacts.InitializeUserByQuerystring(host);

                var wh1 = new AsyncManualResetEvent();
                var wh2 = new AsyncManualResetEvent();

                var connection1 = HubFacts.GetUserConnection("myuser");
                var connection2 = HubFacts.GetUserConnection("myuser2");

                using (connection1)
                    using (connection2)
                    {
                        var proxy1 = connection1.CreateHubProxy("SendToSome");
                        var proxy2 = connection2.CreateHubProxy("SendToSome");

                        await connection1.Start(host);

                        await connection2.Start(host);

                        proxy1.On("send", wh1.Set);
                        proxy2.On("send", wh2.Set);

                        hubContext.Clients.Users(new List <string> {
                            "myuser", "myuser2"
                        }).send();

                        Assert.True(await wh1.WaitAsync(TimeSpan.FromSeconds(10)));
                        Assert.True(await wh2.WaitAsync(TimeSpan.FromSeconds(10)));
                    }
            }
        }
Ejemplo n.º 2
0
        public async Task SendToUsersFromOutsideOfHub()
        {
            using (var host = new MemoryHost())
            {
                IHubContext <IBasicClient> hubContext = HubFacts.InitializeUserByQuerystring(host);

                var wh1 = new TaskCompletionSource <object>();
                var wh2 = new TaskCompletionSource <object>();

                var connection1 = HubFacts.GetUserConnection("myuser");
                var connection2 = HubFacts.GetUserConnection("myuser2");

                using (connection1)
                    using (connection2)
                    {
                        var proxy1 = connection1.CreateHubProxy("SendToSome");
                        var proxy2 = connection2.CreateHubProxy("SendToSome");

                        await connection1.Start(host);

                        await connection2.Start(host);

                        proxy1.On("send", () => wh1.TrySetResult(null));
                        proxy2.On("send", () => wh2.TrySetResult(null));

                        hubContext.Clients.Users(new List <string> {
                            "myuser", "myuser2"
                        }).send();

                        await wh1.Task.OrTimeout(TimeSpan.FromSeconds(10));

                        await wh2.Task.OrTimeout(TimeSpan.FromSeconds(10));
                    }
            }
        }
        public async Task SendToUserFromOutsideOfHub()
        {
            using (var host = new MemoryHost())
            {
                IHubContext <IBasicClient> hubContext = HubFacts.InitializeUserByQuerystring(host);

                var wh = new AsyncManualResetEvent();

                using (var connection = HubFacts.GetUserConnection("myuser"))
                {
                    var hub = connection.CreateHubProxy("SendToSome");

                    await connection.Start(host);

                    hub.On("send", wh.Set);

                    hubContext.Clients.User("myuser").send();

                    Assert.True(await wh.WaitAsync(TimeSpan.FromSeconds(10)));
                }
            }
        }
Ejemplo n.º 4
0
        public async Task SendToUserFromOutsideOfHub()
        {
            using (var host = new MemoryHost())
            {
                IHubContext <IBasicClient> hubContext = HubFacts.InitializeUserByQuerystring(host);

                var wh = new TaskCompletionSource <object>();

                using (var connection = HubFacts.GetUserConnection("myuser"))
                {
                    var hub = connection.CreateHubProxy("SendToSome");

                    await connection.Start(host);

                    hub.On("send", () => wh.TrySetResult(null));

                    hubContext.Clients.User("myuser").send();

                    await wh.Task.OrTimeout(TimeSpan.FromSeconds(10));
                }
            }
        }