コード例 #1
0
ファイル: RedisEndToEnd.cs プロジェクト: staneee/SignalR
        public async Task CanSendAndReceiveUserMessagesWhenOneConnectionWithUserDisconnects(HttpTransportType transportType, string protocolName)
        {
            // Regression test:
            // When multiple connections from the same user were connected and one left, it used to unsubscribe from the user channel
            // Now we keep track of users connections and only unsubscribe when no users are listening
            using (StartVerifiableLog(out var loggerFactory, testName:
                                      $"{nameof(CanSendAndReceiveUserMessagesWhenOneConnectionWithUserDisconnects)}_{transportType.ToString()}_{protocolName}"))
            {
                var protocol = HubProtocolHelpers.GetHubProtocol(protocolName);

                var firstConnection  = CreateConnection(_serverFixture.FirstServer.Url + "/echo", transportType, protocol, loggerFactory, userName: "******");
                var secondConnection = CreateConnection(_serverFixture.SecondServer.Url + "/echo", transportType, protocol, loggerFactory, userName: "******");

                var tcs = new TaskCompletionSource <string>();
                firstConnection.On <string>("Echo", message => tcs.TrySetResult(message));

                await secondConnection.StartAsync().OrTimeout();

                await firstConnection.StartAsync().OrTimeout();

                await secondConnection.DisposeAsync().OrTimeout();

                await firstConnection.InvokeAsync("EchoUser", "userA", "Hello, World!").OrTimeout();

                Assert.Equal("Hello, World!", await tcs.Task.OrTimeout());

                await firstConnection.DisposeAsync().OrTimeout();
            }
        }
コード例 #2
0
ファイル: RedisEndToEnd.cs プロジェクト: staneee/SignalR
        public async Task HubConnectionCanSendAndReceiveGroupMessages(HttpTransportType transportType, string protocolName)
        {
            using (StartVerifiableLog(out var loggerFactory, testName:
                                      $"{nameof(HubConnectionCanSendAndReceiveGroupMessages)}_{transportType.ToString()}_{protocolName}"))
            {
                var protocol = HubProtocolHelpers.GetHubProtocol(protocolName);

                var connection       = CreateConnection(_serverFixture.FirstServer.Url + "/echo", transportType, protocol, loggerFactory);
                var secondConnection = CreateConnection(_serverFixture.SecondServer.Url + "/echo", transportType, protocol, loggerFactory);

                var tcs = new TaskCompletionSource <string>();
                connection.On <string>("Echo", message => tcs.TrySetResult(message));
                var tcs2 = new TaskCompletionSource <string>();
                secondConnection.On <string>("Echo", message => tcs2.TrySetResult(message));

                var groupName = $"TestGroup_{transportType}_{protocolName}_{Guid.NewGuid()}";

                await secondConnection.StartAsync().OrTimeout();

                await connection.StartAsync().OrTimeout();

                await connection.InvokeAsync("AddSelfToGroup", groupName).OrTimeout();

                await secondConnection.InvokeAsync("AddSelfToGroup", groupName).OrTimeout();

                await connection.InvokeAsync("EchoGroup", groupName, "Hello, World!").OrTimeout();

                Assert.Equal("Hello, World!", await tcs.Task.OrTimeout());
                Assert.Equal("Hello, World!", await tcs2.Task.OrTimeout());

                await connection.DisposeAsync().OrTimeout();
            }
        }
コード例 #3
0
ファイル: RedisEndToEnd.cs プロジェクト: staneee/SignalR
        public async Task CanSendAndReceiveUserMessagesFromMultipleConnectionsWithSameUser(HttpTransportType transportType, string protocolName)
        {
            using (StartVerifiableLog(out var loggerFactory, testName:
                                      $"{nameof(CanSendAndReceiveUserMessagesFromMultipleConnectionsWithSameUser)}_{transportType.ToString()}_{protocolName}"))
            {
                var protocol = HubProtocolHelpers.GetHubProtocol(protocolName);

                var connection       = CreateConnection(_serverFixture.FirstServer.Url + "/echo", transportType, protocol, loggerFactory, userName: "******");
                var secondConnection = CreateConnection(_serverFixture.SecondServer.Url + "/echo", transportType, protocol, loggerFactory, userName: "******");

                var tcs = new TaskCompletionSource <string>();
                connection.On <string>("Echo", message => tcs.TrySetResult(message));
                var tcs2 = new TaskCompletionSource <string>();
                secondConnection.On <string>("Echo", message => tcs2.TrySetResult(message));

                await secondConnection.StartAsync().OrTimeout();

                await connection.StartAsync().OrTimeout();

                await connection.InvokeAsync("EchoUser", "userA", "Hello, World!").OrTimeout();

                Assert.Equal("Hello, World!", await tcs.Task.OrTimeout());
                Assert.Equal("Hello, World!", await tcs2.Task.OrTimeout());

                await connection.DisposeAsync().OrTimeout();

                await secondConnection.DisposeAsync().OrTimeout();
            }
        }
コード例 #4
0
        public void DefaultHubProtocolResolverTestsCanCreateAllProtocols(string protocolName)
        {
            var protocol = HubProtocolHelpers.GetHubProtocol(protocolName);

            var resolver = new DefaultHubProtocolResolver(HubProtocolHelpers.AllProtocols, NullLogger <DefaultHubProtocolResolver> .Instance);

            Assert.IsType(
                protocol.GetType(),
                resolver.GetProtocol(protocol.Name, HubProtocolHelpers.AllProtocolNames));
        }
コード例 #5
0
        public void DefaultHubProtocolResolverCreatesProtocolswhenSupoortedProtocolsIsNull(string protocolName)
        {
            var protocol = HubProtocolHelpers.GetHubProtocol(protocolName);

            List <string> supportedProtocols = null;
            var           resolver           = new DefaultHubProtocolResolver(HubProtocolHelpers.AllProtocols, NullLogger <DefaultHubProtocolResolver> .Instance);

            Assert.IsType(
                protocol.GetType(),
                resolver.GetProtocol(protocol.Name, supportedProtocols));
        }
コード例 #6
0
        public async Task HubConnectionCanSendAndReceiveMessages(HttpTransportType transportType, string protocolName)
        {
            using (StartVerifiableLog())
            {
                var protocol = HubProtocolHelpers.GetHubProtocol(protocolName);

                var connection = CreateConnection(_serverFixture.FirstServer.Url + "/echo", transportType, protocol, LoggerFactory);

                await connection.StartAsync().DefaultTimeout();

                var str = await connection.InvokeAsync <string>("Echo", "Hello, World!").DefaultTimeout();

                Assert.Equal("Hello, World!", str);

                await connection.DisposeAsync().DefaultTimeout();
            }
        }
コード例 #7
0
        public async Task HubConnectionCanSendAndReceiveMessages(HttpTransportType transportType, string protocolName)
        {
            using (StartLog(out var loggerFactory, testName:
                            $"{nameof(HubConnectionCanSendAndReceiveMessages)}_{transportType.ToString()}_{protocolName}"))
            {
                var protocol = HubProtocolHelpers.GetHubProtocol(protocolName);

                var connection = CreateConnection(_serverFixture.FirstServer.Url + "/echo", transportType, protocol, loggerFactory);

                await connection.StartAsync().OrTimeout();

                var str = await connection.InvokeAsync <string>("Echo", "Hello, World!").OrTimeout();

                Assert.Equal("Hello, World!", str);

                await connection.DisposeAsync().OrTimeout();
            }
        }