diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.Helpers.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.Helpers.cs index a1db517c24..76cf7959ca 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.Helpers.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.Helpers.cs @@ -1,12 +1,13 @@ using Microsoft.AspNetCore.SignalR.Protocol; using Microsoft.AspNetCore.SignalR.Tests; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.SignalR.Client.Tests { public partial class HubConnectionTests { - private static HubConnection CreateHubConnection(TestConnection connection, IHubProtocol protocol = null) + private static HubConnection CreateHubConnection(TestConnection connection, IHubProtocol protocol = null, ILoggerFactory loggerFactory = null) { var builder = new HubConnectionBuilder(); @@ -16,6 +17,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests builder.Services.AddSingleton(delegateConnectionFactory); + if (loggerFactory != null) + { + builder.WithLoggerFactory(loggerFactory); + } + if (protocol != null) { builder.Services.AddSingleton(protocol); diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs index b2c4535142..5f8abfe00b 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs @@ -8,13 +8,21 @@ using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.SignalR.Protocol; using Microsoft.AspNetCore.SignalR.Tests; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Testing; using Moq; using Xunit; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.SignalR.Client.Tests { - public partial class HubConnectionTests + public partial class HubConnectionTests : LoggedTest { + public HubConnectionTests(ITestOutputHelper output) + : base(output) + { + } + [Fact] public async Task InvokeThrowsIfSerializingMessageFails() { @@ -112,16 +120,19 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests [Fact] public async Task PendingInvocationsAreTerminatedIfServerTimeoutIntervalElapsesWithNoMessages() { - var hubConnection = CreateHubConnection(new TestConnection()); - hubConnection.ServerTimeout = TimeSpan.FromMilliseconds(500); + using (StartLog(out var loggerFactory, LogLevel.Trace)) + { + var hubConnection = CreateHubConnection(new TestConnection(), loggerFactory: loggerFactory); + hubConnection.ServerTimeout = TimeSpan.FromMilliseconds(2000); - await hubConnection.StartAsync().OrTimeout(); + await hubConnection.StartAsync().OrTimeout(); - // Start an invocation (but we won't complete it) - var invokeTask = hubConnection.InvokeAsync("Method").OrTimeout(); + // Start an invocation (but we won't complete it) + var invokeTask = hubConnection.InvokeAsync("Method").OrTimeout(); - var exception = await Assert.ThrowsAsync(() => invokeTask); - Assert.Equal("Server timeout (500.00ms) elapsed without receiving a message from the server.", exception.Message); + var exception = await Assert.ThrowsAsync(() => invokeTask); + Assert.Equal("Server timeout (2000.00ms) elapsed without receiving a message from the server.", exception.Message); + } } // Moq really doesn't handle out parameters well, so to make these tests work I added a manual mock -anurse