示例#1
0
        public async Task BroadcastToExceptSelf()
        {
            var mockReceiver = new StreamingHubBroadcastTestHubReceiverMock();
            var hub          = server.CreateStreamingHubClient <IStreamingHubBroadcastTestHub, IStreamingHubBroadcastTestHubReceiver>(mockReceiver);
            await hub.RegisterConnectionToGroup();

            var mockReceiverOther = new StreamingHubBroadcastTestHubReceiverMock();
            var hubOther          = server.CreateStreamingHubClient <IStreamingHubBroadcastTestHub, IStreamingHubBroadcastTestHubReceiver>(mockReceiverOther);
            await hubOther.RegisterConnectionToGroup();

            Assert.False(mockReceiver.HasCalled);
            Assert.False(mockReceiverOther.HasCalled);

            await hub.CallBroadcastExceptSelfAsync();

            await Task.Delay(10); // NOTE: The receivers may not receive broadcast yet at this point.

            // Target: Other
            Assert.False(mockReceiver.HasCalled);
            Assert.True(mockReceiverOther.HasCalled);
        }
示例#2
0
        public async Task BroadcastTo_Many_3()
        {
            var mockReceiver = new StreamingHubBroadcastTestHubReceiverMock();
            var hub          = server.CreateStreamingHubClient <IStreamingHubBroadcastTestHub, IStreamingHubBroadcastTestHubReceiver>(mockReceiver);
            var connectionId = await hub.RegisterConnectionToGroup();

            var mockReceiverOther = new StreamingHubBroadcastTestHubReceiverMock();
            var hubOther          = server.CreateStreamingHubClient <IStreamingHubBroadcastTestHub, IStreamingHubBroadcastTestHubReceiver>(mockReceiverOther);
            var connectionIdOther = await hubOther.RegisterConnectionToGroup();

            Assert.False(mockReceiver.HasCalled);
            Assert.False(mockReceiverOther.HasCalled);

            await hub.CallBroadcastToManyAsync(new[] { Guid.NewGuid(), connectionId, Guid.NewGuid(), connectionIdOther });

            await Task.Delay(10); // NOTE: The receivers may not receive broadcast yet at this point.

            // Target: Self, Other
            Assert.True(mockReceiver.HasCalled);
            Assert.True(mockReceiverOther.HasCalled);
        }
示例#3
0
        public async Task BroadcastToExceptSelf_2()
        {
            // NOTE: Register `Non-self` target client at first.
            var mockReceiverOther = new StreamingHubBroadcastTestHubReceiverMock();
            var hubOther          = server.CreateStreamingHubClient <IStreamingHubBroadcastTestHub, IStreamingHubBroadcastTestHubReceiver>(mockReceiverOther);
            await hubOther.RegisterConnectionToGroup();

            var mockReceiver = new StreamingHubBroadcastTestHubReceiverMock();
            var hub          = server.CreateStreamingHubClient <IStreamingHubBroadcastTestHub, IStreamingHubBroadcastTestHubReceiver>(mockReceiver);
            await hub.RegisterConnectionToGroup();

            Assert.False(mockReceiver.HasCalled);
            Assert.False(mockReceiverOther.HasCalled);

            await hub.CallBroadcastExceptSelfAsync();

            await Task.Delay(TimeSpan.FromMilliseconds(100)); // NOTE: The receivers may not receive broadcast yet at this point.

            // Target: Other
            Assert.False(mockReceiver.HasCalled);
            Assert.True(mockReceiverOther.HasCalled);
        }