Add logging to HubConnectionHandlerTests (#3286)

This commit is contained in:
BrennanConroy 2018-11-16 10:00:18 -08:00 committed by GitHub
parent 7e96a02975
commit e2a712a1cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 2201 additions and 1964 deletions

View File

@ -30,23 +30,18 @@ using Moq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.AspNetCore.Http.Connections.Tests
{
public class HttpConnectionDispatcherTests : VerifiableLoggedTest
{
public HttpConnectionDispatcherTests(ITestOutputHelper output) : base(output)
{
}
[Fact]
public async Task NegotiateReservesConnectionIdAndReturnsIt()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = new DefaultHttpContext();
var services = new ServiceCollection();
services.AddSingleton<TestConnectionHandler>();
@ -66,10 +61,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task CheckThatThresholdValuesAreEnforced()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = new DefaultHttpContext();
var services = new ServiceCollection();
services.AddSingleton<TestConnectionHandler>();
@ -104,10 +99,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[InlineData(HttpTransportType.ServerSentEvents)]
public async Task CheckThatThresholdValuesAreEnforcedWithSends(HttpTransportType transportType)
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var pipeOptions = new PipeOptions(pauseWriterThreshold: 8, resumeWriterThreshold: 4);
var connection = manager.CreateConnection(pipeOptions, pipeOptions);
connection.TransportType = transportType;
@ -156,10 +151,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[InlineData(HttpTransportType.LongPolling | HttpTransportType.WebSockets)]
public async Task NegotiateReturnsAvailableTransportsAfterFilteringByOptions(HttpTransportType transports)
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = new DefaultHttpContext();
context.Features.Set<IHttpResponseFeature>(new ResponseFeature());
context.Features.Set<IHttpWebSocketFeature>(new TestWebSocketConnectionFeature());
@ -190,10 +185,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[InlineData(HttpTransportType.LongPolling)]
public async Task EndpointsThatAcceptConnectionId404WhenUnknownConnectionIdProvided(HttpTransportType transportType)
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
using (var strm = new MemoryStream())
{
@ -227,10 +222,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task EndpointsThatAcceptConnectionId404WhenUnknownConnectionIdProvidedForPost()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
using (var strm = new MemoryStream())
{
@ -262,10 +257,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task PostNotAllowedForWebSocketConnections()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.WebSockets;
@ -299,10 +294,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task PostReturns404IfConnectionDisposed()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
await connection.DisposeAsync(closeGracefully: false);
@ -337,10 +332,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[InlineData(HttpTransportType.WebSockets)]
public async Task TransportEndingGracefullyWaitsOnApplication(HttpTransportType transportType)
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = transportType;
@ -398,10 +393,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task TransportEndingGracefullyWaitsOnApplicationLongPolling()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
@ -461,10 +456,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[InlineData(HttpTransportType.ServerSentEvents)]
public async Task PostSendsToConnection(HttpTransportType transportType)
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = transportType;
@ -510,10 +505,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[InlineData(HttpTransportType.ServerSentEvents)]
public async Task PostSendsToConnectionInParallel(HttpTransportType transportType)
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = transportType;
@ -595,10 +590,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task HttpContextFeatureForLongpollingWorksBetweenPolls()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
@ -692,10 +687,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[InlineData(HttpTransportType.LongPolling)]
public async Task EndpointsThatRequireConnectionId400WhenNoConnectionIdProvided(HttpTransportType transportType)
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
using (var strm = new MemoryStream())
{
var context = new DefaultHttpContext();
@ -726,10 +721,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[InlineData(HttpTransportType.ServerSentEvents)]
public async Task IOExceptionWhenReadingRequestReturns400Response(HttpTransportType transportType)
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = transportType;
@ -762,10 +757,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task EndpointsThatRequireConnectionId400WhenNoConnectionIdProvidedForPost()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
using (var strm = new MemoryStream())
{
var context = new DefaultHttpContext();
@ -794,9 +789,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[InlineData(HttpTransportType.ServerSentEvents, 404)]
public async Task EndPointThatOnlySupportsLongPollingRejectsOtherTransports(HttpTransportType transportType, int status)
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
await CheckTransportSupported(HttpTransportType.LongPolling, transportType, status, loggerFactory);
await CheckTransportSupported(HttpTransportType.LongPolling, transportType, status, LoggerFactory);
}
}
@ -806,9 +801,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[InlineData(HttpTransportType.LongPolling, 404)]
public async Task EndPointThatOnlySupportsSSERejectsOtherTransports(HttpTransportType transportType, int status)
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
await CheckTransportSupported(HttpTransportType.ServerSentEvents, transportType, status, loggerFactory);
await CheckTransportSupported(HttpTransportType.ServerSentEvents, transportType, status, LoggerFactory);
}
}
@ -818,9 +813,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[InlineData(HttpTransportType.LongPolling, 404)]
public async Task EndPointThatOnlySupportsWebSockesRejectsOtherTransports(HttpTransportType transportType, int status)
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
await CheckTransportSupported(HttpTransportType.WebSockets, transportType, status, loggerFactory);
await CheckTransportSupported(HttpTransportType.WebSockets, transportType, status, LoggerFactory);
}
}
@ -828,22 +823,22 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[InlineData(HttpTransportType.LongPolling, 404)]
public async Task EndPointThatOnlySupportsWebSocketsAndSSERejectsLongPolling(HttpTransportType transportType, int status)
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
await CheckTransportSupported(HttpTransportType.WebSockets | HttpTransportType.ServerSentEvents, transportType, status, loggerFactory);
await CheckTransportSupported(HttpTransportType.WebSockets | HttpTransportType.ServerSentEvents, transportType, status, LoggerFactory);
}
}
[Fact]
public async Task CompletedEndPointEndsConnection()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.ServerSentEvents;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = MakeRequest("/foo", connection);
SetTransport(context, HttpTransportType.ServerSentEvents);
@ -871,13 +866,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
writeContext.EventId.Name == "FailedDispose";
}
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug, expectedErrorsFilter: ExpectedErrors))
using (StartVerifiableLog(expectedErrorsFilter: ExpectedErrors))
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.ServerSentEvents;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = MakeRequest("/foo", connection);
SetTransport(context, HttpTransportType.ServerSentEvents);
@ -898,13 +893,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task CompletedEndPointEndsLongPollingConnection()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = MakeRequest("/foo", connection);
@ -929,13 +924,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task LongPollingTimeoutSets200StatusCode()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = MakeRequest("/foo", connection);
@ -953,15 +948,16 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
}
[Fact]
[LogLevel(LogLevel.Trace)]
public async Task WebSocketTransportTimesOutWhenCloseFrameNotReceived()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.WebSockets;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = MakeRequest("/foo", connection);
SetTransport(context, HttpTransportType.WebSockets);
@ -985,13 +981,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[InlineData(HttpTransportType.ServerSentEvents)]
public async Task RequestToActiveConnectionId409ForStreamingTransports(HttpTransportType transportType)
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = transportType;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context1 = MakeRequest("/foo", connection);
var context2 = MakeRequest("/foo", connection);
@ -1028,13 +1024,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task RequestToActiveConnectionIdKillsPreviousConnectionLongPolling()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context1 = MakeRequest("/foo", connection);
var context2 = MakeRequest("/foo", connection);
@ -1069,14 +1065,14 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[InlineData(HttpTransportType.LongPolling)]
public async Task RequestToDisposedConnectionIdReturns404(HttpTransportType transportType)
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = transportType;
connection.Status = HttpConnectionStatus.Disposed;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = MakeRequest("/foo", connection);
SetTransport(context, transportType);
@ -1097,13 +1093,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task ConnectionStateSetToInactiveAfterPoll()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = MakeRequest("/foo", connection);
@ -1132,13 +1128,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task BlockingConnectionWorksWithStreamingConnections()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.ServerSentEvents;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = MakeRequest("/foo", connection);
SetTransport(context, HttpTransportType.ServerSentEvents);
@ -1167,13 +1163,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task BlockingConnectionWorksWithLongPollingConnection()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = MakeRequest("/foo", connection);
@ -1208,13 +1204,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task AttemptingToPollWhileAlreadyPollingReplacesTheCurrentPoll()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var services = new ServiceCollection();
services.AddSingleton<TestConnectionHandler>();
@ -1253,13 +1249,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[InlineData(HttpTransportType.WebSockets, TransferFormat.Binary | TransferFormat.Text)]
public async Task TransferModeSet(HttpTransportType transportType, TransferFormat? expectedTransferFormats)
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = transportType;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = MakeRequest("/foo", connection);
SetTransport(context, transportType);
@ -1285,12 +1281,12 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task UnauthorizedConnectionFailsToStartEndPoint()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = new DefaultHttpContext();
var services = new ServiceCollection();
services.AddOptions();
@ -1331,12 +1327,12 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task AuthenticatedUserWithoutPermissionCausesForbidden()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = new DefaultHttpContext();
var services = new ServiceCollection();
services.AddOptions();
@ -1379,12 +1375,12 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task AuthorizedConnectionCanConnectToEndPoint()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = new DefaultHttpContext();
context.Features.Set<IHttpResponseFeature>(new ResponseFeature());
var services = new ServiceCollection();
@ -1439,12 +1435,12 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task AllPoliciesRequiredForAuthorizedEndPoint()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = new DefaultHttpContext();
context.Features.Set<IHttpResponseFeature>(new ResponseFeature());
var services = new ServiceCollection();
@ -1526,12 +1522,12 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task AuthorizedConnectionWithAcceptedSchemesCanConnectToEndPoint()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = new DefaultHttpContext();
context.Features.Set<IHttpResponseFeature>(new ResponseFeature());
var services = new ServiceCollection();
@ -1589,12 +1585,12 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task AuthorizedConnectionWithRejectedSchemesFailsToConnectToEndPoint()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = new DefaultHttpContext();
var services = new ServiceCollection();
services.AddOptions();
@ -1643,13 +1639,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task SetsInherentKeepAliveFeatureOnFirstLongPollingRequest()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = MakeRequest("/foo", connection);
@ -1675,13 +1671,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[InlineData(HttpTransportType.WebSockets)]
public async Task DeleteEndpointRejectsRequestToTerminateNonLongPollingTransport(HttpTransportType transportType)
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = transportType;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = MakeRequest("/foo", connection);
SetTransport(context, transportType);
@ -1716,13 +1712,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task DeleteEndpointGracefullyTerminatesLongPolling()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = MakeRequest("/foo", connection);
@ -1767,13 +1763,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task DeleteEndpointGracefullyTerminatesLongPollingEvenWhenBetweenPolls()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = MakeRequest("/foo", connection);
@ -1815,10 +1811,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task NegotiateDoesNotReturnWebSocketsWhenNotAvailable()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var context = new DefaultHttpContext();
context.Features.Set<IHttpResponseFeature>(new ResponseFeature());
var services = new ServiceCollection();
@ -1857,14 +1853,14 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task WriteThatIsDisposedBeforeCompleteReturns404()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var pipeOptions = new PipeOptions(pauseWriterThreshold: 13, resumeWriterThreshold: 10);
var connection = manager.CreateConnection(pipeOptions, pipeOptions);
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var services = new ServiceCollection();
services.AddSingleton<TestConnectionHandler>();
@ -1915,14 +1911,14 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task CanDisposeWhileWriteLockIsBlockedOnBackpressureAndResponseReturns404()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var pipeOptions = new PipeOptions(pauseWriterThreshold: 13, resumeWriterThreshold: 10);
var connection = manager.CreateConnection(pipeOptions, pipeOptions);
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var services = new ServiceCollection();
services.AddSingleton<TestConnectionHandler>();
@ -1968,14 +1964,14 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task LongPollingCanPollIfWritePipeHasBackpressure()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var pipeOptions = new PipeOptions(pauseWriterThreshold: 13, resumeWriterThreshold: 10);
var connection = manager.CreateConnection(pipeOptions, pipeOptions);
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var services = new ServiceCollection();
services.AddSingleton<TestConnectionHandler>();
@ -2028,13 +2024,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
writeContext.EventId.Name == "FailedDispose");
}
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug, expectedErrorsFilter: ExpectedErrors))
using (StartVerifiableLog(expectedErrorsFilter: ExpectedErrors))
{
var manager = CreateConnectionManager(loggerFactory);
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();
connection.TransportType = HttpTransportType.LongPolling;
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
var dispatcher = new HttpConnectionDispatcher(manager, LoggerFactory);
var services = new ServiceCollection();
services.AddSingleton<TestConnectionHandler>();

View File

@ -10,23 +10,17 @@ using Microsoft.AspNetCore.Http.Connections.Internal;
using Microsoft.AspNetCore.SignalR.Tests;
using Microsoft.Extensions.Logging;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.AspNetCore.Http.Connections.Tests
{
public class HttpConnectionManagerTests : VerifiableLoggedTest
{
public HttpConnectionManagerTests(ITestOutputHelper output)
: base(output)
{
}
[Fact]
public void NewConnectionsHaveConnectionId()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var connectionManager = CreateConnectionManager(loggerFactory);
var connectionManager = CreateConnectionManager(LoggerFactory);
var connection = connectionManager.CreateConnection();
Assert.NotNull(connection.ConnectionId);
@ -52,13 +46,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[InlineData(ConnectionStates.CloseGracefully | ConnectionStates.ApplicationFaulted | ConnectionStates.TransportNotFaulted)]
public async Task DisposingConnectionsClosesBothSidesOfThePipe(ConnectionStates states)
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var closeGracefully = (states & ConnectionStates.CloseGracefully) != 0;
var applicationFaulted = (states & ConnectionStates.ApplicationFaulted) != 0;
var transportFaulted = (states & ConnectionStates.TransportFaulted) != 0;
var connectionManager = CreateConnectionManager(loggerFactory);
var connectionManager = CreateConnectionManager(LoggerFactory);
var connection = connectionManager.CreateConnection();
if (applicationFaulted)
@ -123,9 +117,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public void NewConnectionsCanBeRetrieved()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var connectionManager = CreateConnectionManager(loggerFactory);
var connectionManager = CreateConnectionManager(LoggerFactory);
var connection = connectionManager.CreateConnection();
Assert.NotNull(connection.ConnectionId);
@ -138,9 +132,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public void AddNewConnection()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var connectionManager = CreateConnectionManager(loggerFactory);
var connectionManager = CreateConnectionManager(LoggerFactory);
var connection = connectionManager.CreateConnection(PipeOptions.Default, PipeOptions.Default);
var transport = connection.Transport;
@ -157,9 +151,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public void RemoveConnection()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var connectionManager = CreateConnectionManager(loggerFactory);
var connectionManager = CreateConnectionManager(LoggerFactory);
var connection = connectionManager.CreateConnection(PipeOptions.Default, PipeOptions.Default);
var transport = connection.Transport;
@ -179,9 +173,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task CloseConnectionsEndsAllPendingConnections()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var connectionManager = CreateConnectionManager(loggerFactory);
var connectionManager = CreateConnectionManager(LoggerFactory);
var connection = connectionManager.CreateConnection(PipeOptions.Default, PipeOptions.Default);
connection.ApplicationTask = Task.Run(async () =>
@ -227,9 +221,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task DisposingConnectionMultipleTimesWaitsOnConnectionClose()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var connectionManager = CreateConnectionManager(loggerFactory);
var connectionManager = CreateConnectionManager(LoggerFactory);
var connection = connectionManager.CreateConnection(PipeOptions.Default, PipeOptions.Default);
var tcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
@ -250,9 +244,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task DisposingConnectionMultipleGetsExceptionFromTransportOrApp()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var connectionManager = CreateConnectionManager(loggerFactory);
var connectionManager = CreateConnectionManager(LoggerFactory);
var connection = connectionManager.CreateConnection(PipeOptions.Default, PipeOptions.Default);
var tcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
@ -277,9 +271,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task DisposingConnectionMultipleGetsCancellation()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var connectionManager = CreateConnectionManager(loggerFactory);
var connectionManager = CreateConnectionManager(LoggerFactory);
var connection = connectionManager.CreateConnection(PipeOptions.Default, PipeOptions.Default);
var tcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
@ -301,9 +295,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task DisposeInactiveConnection()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var connectionManager = CreateConnectionManager(loggerFactory);
var connectionManager = CreateConnectionManager(LoggerFactory);
var connection = connectionManager.CreateConnection(PipeOptions.Default, PipeOptions.Default);
Assert.NotNull(connection.ConnectionId);
@ -317,9 +311,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task DisposeInactiveConnectionWithNoPipes()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var connectionManager = CreateConnectionManager(loggerFactory);
var connectionManager = CreateConnectionManager(LoggerFactory);
var connection = connectionManager.CreateConnection();
Assert.NotNull(connection.ConnectionId);
@ -334,10 +328,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task ApplicationLifetimeIsHookedUp()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var appLifetime = new TestApplicationLifetime();
var connectionManager = CreateConnectionManager(loggerFactory, appLifetime);
var connectionManager = CreateConnectionManager(LoggerFactory, appLifetime);
var tcs = new TaskCompletionSource<object>();
appLifetime.Start();
@ -360,12 +354,12 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task ApplicationLifetimeCanStartBeforeHttpConnectionManagerInitialized()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var appLifetime = new TestApplicationLifetime();
appLifetime.Start();
var connectionManager = CreateConnectionManager(loggerFactory, appLifetime);
var connectionManager = CreateConnectionManager(LoggerFactory, appLifetime);
var tcs = new TaskCompletionSource<object>();
var connection = connectionManager.CreateConnection(PipeOptions.Default, PipeOptions.Default);

View File

@ -10,30 +10,23 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Http.Connections.Internal.Transports;
using Microsoft.AspNetCore.SignalR.Tests;
using Microsoft.Extensions.Logging;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.AspNetCore.Http.Connections.Tests
{
public class LongPollingTests : VerifiableLoggedTest
{
public LongPollingTests(ITestOutputHelper output)
: base(output)
{
}
[Fact]
public async Task Set204StatusCodeWhenChannelComplete()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var pair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);
var connection = new DefaultConnectionContext("foo", pair.Transport, pair.Application);
var context = new DefaultHttpContext();
var poll = new LongPollingTransport(CancellationToken.None, connection.Application.Input, loggerFactory);
var poll = new LongPollingTransport(CancellationToken.None, connection.Application.Input, LoggerFactory);
connection.Transport.Output.Complete();
@ -46,14 +39,14 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task Set200StatusCodeWhenTimeoutTokenFires()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var pair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);
var connection = new DefaultConnectionContext("foo", pair.Transport, pair.Application);
var context = new DefaultHttpContext();
var timeoutToken = new CancellationToken(true);
var poll = new LongPollingTransport(timeoutToken, connection.Application.Input, loggerFactory);
var poll = new LongPollingTransport(timeoutToken, connection.Application.Input, LoggerFactory);
using (var cts = CancellationTokenSource.CreateLinkedTokenSource(timeoutToken, context.RequestAborted))
{
@ -68,13 +61,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task FrameSentAsSingleResponse()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var pair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);
var connection = new DefaultConnectionContext("foo", pair.Transport, pair.Application);
var context = new DefaultHttpContext();
var poll = new LongPollingTransport(CancellationToken.None, connection.Application.Input, loggerFactory);
var poll = new LongPollingTransport(CancellationToken.None, connection.Application.Input, LoggerFactory);
var ms = new MemoryStream();
context.Response.Body = ms;
@ -91,13 +84,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task MultipleFramesSentAsSingleResponse()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var pair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);
var connection = new DefaultConnectionContext("foo", pair.Transport, pair.Application);
var context = new DefaultHttpContext();
var poll = new LongPollingTransport(CancellationToken.None, connection.Application.Input, loggerFactory);
var poll = new LongPollingTransport(CancellationToken.None, connection.Application.Input, LoggerFactory);
var ms = new MemoryStream();
context.Response.Body = ms;

View File

@ -6,33 +6,25 @@ using System.IO.Pipelines;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Http.Connections.Internal.Transports;
using Microsoft.Extensions.Logging;
using Xunit;
using Microsoft.AspNetCore.SignalR.Tests;
using Xunit.Abstractions;
namespace Microsoft.AspNetCore.Http.Connections.Tests
{
public class ServerSentEventsTests : VerifiableLoggedTest
{
public ServerSentEventsTests(ITestOutputHelper output)
: base(output)
{
}
[Fact]
public async Task SSESetsContentType()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var pair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);
var connection = new DefaultConnectionContext("foo", pair.Transport, pair.Application);
var context = new DefaultHttpContext();
var sse = new ServerSentEventsTransport(connection.Application.Input, connectionId: string.Empty, loggerFactory);
var sse = new ServerSentEventsTransport(connection.Application.Input, connectionId: string.Empty, LoggerFactory);
connection.Transport.Output.Complete();
@ -46,7 +38,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task SSETurnsResponseBufferingOff()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var pair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);
var connection = new DefaultConnectionContext("foo", pair.Transport, pair.Application);
@ -54,7 +46,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
var feature = new HttpBufferingFeature();
context.Features.Set<IHttpBufferingFeature>(feature);
var sse = new ServerSentEventsTransport(connection.Application.Input, connectionId: connection.ConnectionId, loggerFactory);
var sse = new ServerSentEventsTransport(connection.Application.Input, connectionId: connection.ConnectionId, LoggerFactory);
connection.Transport.Output.Complete();
@ -67,7 +59,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task SSEWritesMessages()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var pair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, new PipeOptions(readerScheduler: PipeScheduler.Inline));
var connection = new DefaultConnectionContext("foo", pair.Transport, pair.Application);
@ -75,7 +67,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
var ms = new MemoryStream();
context.Response.Body = ms;
var sse = new ServerSentEventsTransport(connection.Application.Input, connectionId: string.Empty, loggerFactory);
var sse = new ServerSentEventsTransport(connection.Application.Input, connectionId: string.Empty, LoggerFactory);
var task = sse.ProcessRequestAsync(context, context.RequestAborted);
@ -89,7 +81,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task SSEWritesVeryLargeMessages()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var pair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, new PipeOptions(readerScheduler: PipeScheduler.Inline));
var connection = new DefaultConnectionContext("foo", pair.Transport, pair.Application);
@ -97,7 +89,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
var ms = new MemoryStream();
context.Response.Body = ms;
var sse = new ServerSentEventsTransport(connection.Application.Input, connectionId: string.Empty, loggerFactory);
var sse = new ServerSentEventsTransport(connection.Application.Input, connectionId: string.Empty, LoggerFactory);
var task = sse.ProcessRequestAsync(context, context.RequestAborted);
@ -117,13 +109,13 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[InlineData("Hello\r\nWorld", ":\r\ndata: Hello\r\ndata: World\r\n\r\n")]
public async Task SSEAddsAppropriateFraming(string message, string expected)
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var pair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);
var connection = new DefaultConnectionContext("foo", pair.Transport, pair.Application);
var context = new DefaultHttpContext();
var sse = new ServerSentEventsTransport(connection.Application.Input, connectionId: string.Empty, loggerFactory);
var sse = new ServerSentEventsTransport(connection.Application.Input, connectionId: string.Empty, LoggerFactory);
var ms = new MemoryStream();
context.Response.Body = ms;

View File

@ -15,35 +15,28 @@ using Microsoft.AspNetCore.Http.Connections.Internal.Transports;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.SignalR.Tests;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Microsoft.Net.Http.Headers;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.AspNetCore.Http.Connections.Tests
{
public class WebSocketsTests : VerifiableLoggedTest
{
public WebSocketsTests(ITestOutputHelper output)
: base(output)
{
}
// Using nameof with WebSocketMessageType because it is a GACed type and xunit can't serialize it
[Theory]
[InlineData(nameof(WebSocketMessageType.Text))]
[InlineData(nameof(WebSocketMessageType.Binary))]
public async Task ReceivedFramesAreWrittenToChannel(string webSocketMessageType)
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var pair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);
var connection = new HttpConnectionContext("foo", pair.Transport, pair.Application, loggerFactory.CreateLogger("HttpConnectionContext1"));
var connection = new HttpConnectionContext("foo", pair.Transport, pair.Application, LoggerFactory.CreateLogger("HttpConnectionContext1"));
using (var feature = new TestWebSocketConnectionFeature())
{
var connectionContext = new HttpConnectionContext(string.Empty, null, null, loggerFactory.CreateLogger("HttpConnectionContext2"));
var ws = new WebSocketsTransport(new WebSocketOptions(), connection.Application, connectionContext, loggerFactory);
var connectionContext = new HttpConnectionContext(string.Empty, null, null, LoggerFactory.CreateLogger("HttpConnectionContext2"));
var ws = new WebSocketsTransport(new WebSocketOptions(), connection.Application, connectionContext, LoggerFactory);
// Give the server socket to the transport and run it
var transport = ws.ProcessSocketAsync(await feature.AcceptAsync());
@ -83,16 +76,16 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[InlineData(TransferFormat.Binary, nameof(WebSocketMessageType.Binary))]
public async Task WebSocketTransportSetsMessageTypeBasedOnTransferFormatFeature(TransferFormat transferFormat, string expectedMessageType)
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var pair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);
var connection = new HttpConnectionContext("foo", pair.Transport, pair.Application, loggerFactory.CreateLogger("HttpConnectionContext1"));
var connection = new HttpConnectionContext("foo", pair.Transport, pair.Application, LoggerFactory.CreateLogger("HttpConnectionContext1"));
using (var feature = new TestWebSocketConnectionFeature())
{
var connectionContext = new HttpConnectionContext(string.Empty, null, null, loggerFactory.CreateLogger("HttpConnectionContext2"));
var connectionContext = new HttpConnectionContext(string.Empty, null, null, LoggerFactory.CreateLogger("HttpConnectionContext2"));
connectionContext.ActiveFormat = transferFormat;
var ws = new WebSocketsTransport(new WebSocketOptions(), connection.Application, connectionContext, loggerFactory);
var ws = new WebSocketsTransport(new WebSocketOptions(), connection.Application, connectionContext, LoggerFactory);
// Give the server socket to the transport and run it
var transport = ws.ProcessSocketAsync(await feature.AcceptAsync());
@ -120,10 +113,10 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task TransportCommunicatesErrorToApplicationWhenClientDisconnectsAbnormally()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var pair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);
var connection = new HttpConnectionContext("foo", pair.Transport, pair.Application, loggerFactory.CreateLogger("HttpConnectionContext1"));
var connection = new HttpConnectionContext("foo", pair.Transport, pair.Application, LoggerFactory.CreateLogger("HttpConnectionContext1"));
using (var feature = new TestWebSocketConnectionFeature())
{
@ -146,8 +139,8 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
}
}
var connectionContext = new HttpConnectionContext(string.Empty, null, null, loggerFactory.CreateLogger("HttpConnectionContext2"));
var ws = new WebSocketsTransport(new WebSocketOptions(), connection.Application, connectionContext, loggerFactory);
var connectionContext = new HttpConnectionContext(string.Empty, null, null, LoggerFactory.CreateLogger("HttpConnectionContext2"));
var ws = new WebSocketsTransport(new WebSocketOptions(), connection.Application, connectionContext, LoggerFactory);
// Give the server socket to the transport and run it
var transport = ws.ProcessSocketAsync(await feature.AcceptAsync());
@ -173,7 +166,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task ClientReceivesInternalServerErrorWhenTheApplicationFails()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var pair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);
var connection = new HttpConnectionContext("foo", pair.Transport, pair.Application);
@ -181,7 +174,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
using (var feature = new TestWebSocketConnectionFeature())
{
var connectionContext = new HttpConnectionContext(string.Empty, null, null);
var ws = new WebSocketsTransport(new WebSocketOptions(), connection.Application, connectionContext, loggerFactory);
var ws = new WebSocketsTransport(new WebSocketOptions(), connection.Application, connectionContext, LoggerFactory);
// Give the server socket to the transport and run it
var transport = ws.ProcessSocketAsync(await feature.AcceptAsync());
@ -205,7 +198,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task TransportClosesOnCloseTimeoutIfClientDoesNotSendCloseFrame()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var pair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);
var connection = new HttpConnectionContext("foo", pair.Transport, pair.Application);
@ -218,7 +211,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
};
var connectionContext = new HttpConnectionContext(string.Empty, null, null);
var ws = new WebSocketsTransport(options, connection.Application, connectionContext, loggerFactory);
var ws = new WebSocketsTransport(options, connection.Application, connectionContext, LoggerFactory);
var serverSocket = await feature.AcceptAsync();
// Give the server socket to the transport and run it
@ -240,7 +233,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task TransportFailsOnTimeoutWithErrorWhenApplicationFailsAndClientDoesNotSendCloseFrame()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var pair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);
var connection = new HttpConnectionContext("foo", pair.Transport, pair.Application);
@ -253,7 +246,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
};
var connectionContext = new HttpConnectionContext(string.Empty, null, null);
var ws = new WebSocketsTransport(options, connection.Application, connectionContext, loggerFactory);
var ws = new WebSocketsTransport(options, connection.Application, connectionContext, LoggerFactory);
var serverSocket = await feature.AcceptAsync();
// Give the server socket to the transport and run it
@ -275,7 +268,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task ServerGracefullyClosesWhenApplicationEndsThenClientSendsCloseFrame()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var pair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);
var connection = new HttpConnectionContext("foo", pair.Transport, pair.Application);
@ -289,7 +282,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
};
var connectionContext = new HttpConnectionContext(string.Empty, null, null);
var ws = new WebSocketsTransport(options, connection.Application, connectionContext, loggerFactory);
var ws = new WebSocketsTransport(options, connection.Application, connectionContext, LoggerFactory);
var serverSocket = await feature.AcceptAsync();
// Give the server socket to the transport and run it
@ -315,7 +308,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[Fact]
public async Task ServerGracefullyClosesWhenClientSendsCloseFrameThenApplicationEnds()
{
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var pair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);
var connection = new HttpConnectionContext("foo", pair.Transport, pair.Application);
@ -329,7 +322,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
};
var connectionContext = new HttpConnectionContext(string.Empty, null, null);
var ws = new WebSocketsTransport(options, connection.Application, connectionContext, loggerFactory);
var ws = new WebSocketsTransport(options, connection.Application, connectionContext, LoggerFactory);
var serverSocket = await feature.AcceptAsync();
// Give the server socket to the transport and run it
@ -358,7 +351,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
const string ExpectedSubProtocol = "expected";
var providedSubProtocols = new[] {"provided1", "provided2"};
using (StartVerifiableLog(out var loggerFactory, LogLevel.Debug))
using (StartVerifiableLog())
{
var pair = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);
var connection = new HttpConnectionContext("foo", pair.Transport, pair.Application);
@ -376,7 +369,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
};
var connectionContext = new HttpConnectionContext(string.Empty, null, null);
var ws = new WebSocketsTransport(options, connection.Application, connectionContext, loggerFactory);
var ws = new WebSocketsTransport(options, connection.Application, connectionContext, LoggerFactory);
// Create an HttpContext
var context = new DefaultHttpContext();

View File

@ -18,7 +18,6 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
{
@ -32,12 +31,6 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
{
private const string DefaultHubDispatcherLoggerName = "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher";
// Pass null for server fixture as tests should provide their own
// This is to prevent logs from previous tests affecting running tests
public HubConnectionTests(ITestOutputHelper output) : base(output)
{
}
private HubConnection CreateHubConnection(
string url,
string path = null,
@ -72,11 +65,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CheckFixedMessage(string protocolName, HttpTransportType transportType, string path)
{
var protocol = HubProtocols[protocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(CheckFixedMessage)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
using (StartServer<Startup>(out var server))
{
var connectionBuilder = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory)
.WithUrl(fixture.Url + path, transportType);
.WithLoggerFactory(LoggerFactory)
.WithUrl(server.Url + path, transportType);
connectionBuilder.Services.AddSingleton(protocol);
var connection = connectionBuilder.Build();
@ -91,7 +84,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -106,10 +99,10 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanSendAndReceiveMessage(string protocolName, HttpTransportType transportType, string path)
{
var protocol = HubProtocols[protocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(CanSendAndReceiveMessage)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
using (StartServer<Startup>(out var server))
{
const string originalMessage = "SignalR";
var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try
{
await connection.StartAsync().OrTimeout();
@ -120,7 +113,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -132,13 +125,14 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Theory]
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
[LogLevel(LogLevel.Trace)]
public async Task CanStopAndStartConnection(string protocolName, HttpTransportType transportType, string path)
{
var protocol = HubProtocols[protocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, LogLevel.Trace, $"{nameof(CanStopAndStartConnection)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
using (StartServer<Startup>(out var server))
{
const string originalMessage = "SignalR";
var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try
{
await connection.StartAsync().OrTimeout();
@ -151,7 +145,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -163,15 +157,16 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Theory]
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
[LogLevel(LogLevel.Trace)]
public async Task CanStartConnectionFromClosedEvent(string protocolName, HttpTransportType transportType, string path)
{
var protocol = HubProtocols[protocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, LogLevel.Trace, $"{nameof(CanStartConnectionFromClosedEvent)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
using (StartServer<Startup>(out var server))
{
var logger = loggerFactory.CreateLogger<HubConnectionTests>();
var logger = LoggerFactory.CreateLogger<HubConnectionTests>();
const string originalMessage = "SignalR";
var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
var restartTcs = new TaskCompletionSource<object>();
connection.Closed += async e =>
{
@ -213,7 +208,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -228,10 +223,10 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task MethodsAreCaseInsensitive(string protocolName, HttpTransportType transportType, string path)
{
var protocol = HubProtocols[protocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(MethodsAreCaseInsensitive)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
using (StartServer<Startup>(out var server))
{
const string originalMessage = "SignalR";
var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try
{
await connection.StartAsync().OrTimeout();
@ -242,7 +237,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -254,14 +249,15 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Theory]
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
[LogLevel(LogLevel.Trace)]
public async Task CanInvokeClientMethodFromServer(string protocolName, HttpTransportType transportType, string path)
{
var protocol = HubProtocols[protocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, LogLevel.Trace, $"{nameof(CanInvokeClientMethodFromServer)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
using (StartServer<Startup>(out var server))
{
const string originalMessage = "SignalR";
var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try
{
await connection.StartAsync().OrTimeout();
@ -275,7 +271,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -287,12 +283,13 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Theory]
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
[LogLevel(LogLevel.Trace)]
public async Task InvokeNonExistantClientMethodFromServer(string protocolName, HttpTransportType transportType, string path)
{
var protocol = HubProtocols[protocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, LogLevel.Trace, $"{nameof(InvokeNonExistantClientMethodFromServer)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
using (StartServer<Startup>(out var server))
{
var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
var closeTcs = new TaskCompletionSource<object>();
connection.Closed += e =>
{
@ -316,7 +313,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} during test: {Message}", ex.GetType().Name, ex.Message);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} during test: {Message}", ex.GetType().Name, ex.Message);
throw;
}
finally
@ -328,12 +325,13 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Theory]
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
[LogLevel(LogLevel.Trace)]
public async Task CanStreamClientMethodFromServer(string protocolName, HttpTransportType transportType, string path)
{
var protocol = HubProtocols[protocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, LogLevel.Trace, $"{nameof(CanStreamClientMethodFromServer)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
using (StartServer<Startup>(out var server))
{
var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try
{
await connection.StartAsync().OrTimeout();
@ -345,7 +343,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -357,6 +355,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Theory]
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
[LogLevel(LogLevel.Trace)]
public async Task CanCloseStreamMethodEarly(string protocolName, HttpTransportType transportType, string path)
{
bool ExpectedErrors(WriteContext writeContext)
@ -368,9 +367,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
var protocol = HubProtocols[protocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, LogLevel.Trace, $"{nameof(CanCloseStreamMethodEarly)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}", ExpectedErrors))
using (StartServer<Startup>(out var server, ExpectedErrors))
{
var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try
{
await connection.StartAsync().OrTimeout();
@ -393,7 +392,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -405,12 +404,13 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Theory]
[MemberData(nameof(HubProtocolsAndTransportsAndHubPaths))]
[LogLevel(LogLevel.Trace)]
public async Task StreamDoesNotStartIfTokenAlreadyCanceled(string protocolName, HttpTransportType transportType, string path)
{
var protocol = HubProtocols[protocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, LogLevel.Trace, $"{nameof(StreamDoesNotStartIfTokenAlreadyCanceled)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
using (StartServer<Startup>(out var server))
{
var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try
{
await connection.StartAsync().OrTimeout();
@ -422,7 +422,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -443,9 +443,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
var protocol = HubProtocols[protocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ExceptionFromStreamingSentToClient)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
using (StartServer<Startup>(out var server, ExpectedErrors))
{
var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try
{
await connection.StartAsync().OrTimeout();
@ -456,7 +456,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -477,9 +477,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionIfHubMethodCannotBeResolved)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
using (StartServer<Startup>(out var server, ExpectedErrors))
{
var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try
{
await connection.StartAsync().OrTimeout();
@ -489,7 +489,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -510,9 +510,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionIfHubMethodCannotBeResolvedAndArgumentsPassedIn)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
using (StartServer<Startup>(out var server, ExpectedErrors))
{
var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try
{
await connection.StartAsync().OrTimeout();
@ -522,7 +522,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -543,9 +543,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionOnHubMethodArgumentCountMismatch)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
using (StartServer<Startup>(out var server, ExpectedErrors))
{
var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try
{
await connection.StartAsync().OrTimeout();
@ -555,7 +555,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -576,9 +576,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionOnHubMethodArgumentTypeMismatch)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
using (StartServer<Startup>(out var server, ExpectedErrors))
{
var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try
{
await connection.StartAsync().OrTimeout();
@ -588,7 +588,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -609,9 +609,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionIfStreamingHubMethodCannotBeResolved)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
using (StartServer<Startup>(out var server, ExpectedErrors))
{
var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try
{
await connection.StartAsync().OrTimeout();
@ -622,7 +622,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -643,9 +643,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionOnStreamingHubMethodArgumentCountMismatch)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
using (StartServer<Startup>(out var server, ExpectedErrors))
{
var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try
{
await connection.StartAsync().OrTimeout();
@ -656,7 +656,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -677,9 +677,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionOnStreamingHubMethodArgumentTypeMismatch)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
using (StartServer<Startup>(out var server, ExpectedErrors))
{
var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try
{
await connection.StartAsync().OrTimeout();
@ -690,7 +690,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -711,9 +711,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionIfNonStreamMethodInvokedWithStreamAsync)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
using (StartServer<Startup>(out var server, ExpectedErrors))
{
var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try
{
await connection.StartAsync().OrTimeout();
@ -723,7 +723,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -744,9 +744,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionIfStreamMethodInvokedWithInvoke)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
using (StartServer<Startup>(out var server, ExpectedErrors))
{
var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try
{
await connection.StartAsync().OrTimeout();
@ -756,7 +756,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -777,9 +777,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
var hubProtocol = HubProtocols[hubProtocolName];
using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionIfBuildingAsyncEnumeratorIsNotPossible)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
using (StartServer<Startup>(out var server, ExpectedErrors))
{
var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try
{
await connection.StartAsync().OrTimeout();
@ -789,7 +789,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -803,18 +803,18 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(TransportTypes))]
public async Task ClientCanUseJwtBearerTokenForAuthentication(HttpTransportType transportType)
{
using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ClientCanUseJwtBearerTokenForAuthentication)}_{transportType}"))
using (StartServer<Startup>(out var server))
{
async Task<string> AccessTokenProvider()
{
var httpResponse = await new HttpClient().GetAsync(fixture.Url + "/generateJwtToken");
var httpResponse = await new HttpClient().GetAsync(server.Url + "/generateJwtToken");
httpResponse.EnsureSuccessStatusCode();
return await httpResponse.Content.ReadAsStringAsync();
};
var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory)
.WithUrl(fixture.Url + "/authorizedhub", transportType, options =>
.WithLoggerFactory(LoggerFactory)
.WithUrl(server.Url + "/authorizedhub", transportType, options =>
{
options.AccessTokenProvider = AccessTokenProvider;
})
@ -827,7 +827,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -841,11 +841,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(TransportTypes))]
public async Task ClientCanUseJwtBearerTokenForAuthenticationWhenRedirected(HttpTransportType transportType)
{
using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ClientCanUseJwtBearerTokenForAuthenticationWhenRedirected)}_{transportType}"))
using (StartServer<Startup>(out var server))
{
var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory)
.WithUrl(fixture.Url + "/redirect", transportType)
.WithLoggerFactory(LoggerFactory)
.WithUrl(server.Url + "/redirect", transportType)
.Build();
try
{
@ -855,7 +855,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -869,11 +869,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(TransportTypes))]
public async Task ClientCanSendHeaders(HttpTransportType transportType)
{
using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ClientCanSendHeaders)}_{transportType}"))
using (StartServer<Startup>(out var server))
{
var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory)
.WithUrl(fixture.Url + "/default", transportType, options =>
.WithLoggerFactory(LoggerFactory)
.WithUrl(server.Url + "/default", transportType, options =>
{
options.Headers["X-test"] = "42";
options.Headers["X-42"] = "test";
@ -887,7 +887,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -901,15 +901,15 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[WebSocketsSupportedCondition]
public async Task WebSocketOptionsAreApplied()
{
using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(WebSocketOptionsAreApplied)}"))
using (StartServer<Startup>(out var server))
{
// System.Net has a HttpTransportType type which means we need to fully-qualify this rather than 'use' the namespace
var cookieJar = new System.Net.CookieContainer();
cookieJar.Add(new System.Net.Cookie("Foo", "Bar", "/", new Uri(fixture.Url).Host));
cookieJar.Add(new System.Net.Cookie("Foo", "Bar", "/", new Uri(server.Url).Host));
var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory)
.WithUrl(fixture.Url + "/default", HttpTransportType.WebSockets, options =>
.WithLoggerFactory(LoggerFactory)
.WithUrl(server.Url + "/default", HttpTransportType.WebSockets, options =>
{
options.WebSocketConfiguration = o => o.Cookies = cookieJar;
})
@ -922,7 +922,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -935,11 +935,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Fact]
public async Task CheckHttpConnectionFeatures()
{
using (StartServer<Startup>(out var loggerFactory, out var fixture))
using (StartServer<Startup>(out var server))
{
var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory)
.WithUrl(fixture.Url + "/default")
.WithLoggerFactory(LoggerFactory)
.WithUrl(server.Url + "/default")
.Build();
try
{
@ -958,7 +958,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -971,11 +971,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Fact]
public async Task UserIdProviderCanAccessHttpContext()
{
using (StartServer<Startup>(out var loggerFactory, out var fixture))
using (StartServer<Startup>(out var server))
{
var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory)
.WithUrl(fixture.Url + "/default", options =>
.WithLoggerFactory(LoggerFactory)
.WithUrl(server.Url + "/default", options =>
{
options.Headers.Add(HeaderUserIdProvider.HeaderName, "SuperAdmin");
})
@ -989,7 +989,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -1002,12 +1002,12 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Fact]
public async Task NegotiationSkipsServerSentEventsWhenUsingBinaryProtocol()
{
using (StartServer<Startup>(out var loggerFactory, out var fixture))
using (StartServer<Startup>(out var server))
{
var hubConnectionBuilder = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory)
.WithLoggerFactory(LoggerFactory)
.AddMessagePackProtocol()
.WithUrl(fixture.Url + "/default-nowebsockets");
.WithUrl(server.Url + "/default-nowebsockets");
var hubConnection = hubConnectionBuilder.Build();
try
@ -1019,7 +1019,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -1032,12 +1032,12 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Fact]
public async Task StopCausesPollToReturnImmediately()
{
using (StartServer<Startup>(out var loggerFactory, out var fixture))
using (StartServer<Startup>(out var server))
{
PollTrackingMessageHandler pollTracker = null;
var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory)
.WithUrl(fixture.Url + "/default", options =>
.WithLoggerFactory(LoggerFactory)
.WithUrl(server.Url + "/default", options =>
{
options.Transports = HttpTransportType.LongPolling;
options.HttpMessageHandlerFactory = handler =>

View File

@ -19,7 +19,6 @@ using Microsoft.Extensions.Logging.Testing;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
{
@ -31,18 +30,14 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Collection(HubProtocolVersionTestsCollection.Name)]
public class HubProtocolVersionTests : FunctionalTestBase
{
public HubProtocolVersionTests(ITestOutputHelper output) : base(output)
{
}
[Theory]
[MemberData(nameof(TransportTypes))]
public async Task ClientUsingOldCallWithOriginalProtocol(HttpTransportType transportType)
{
using (StartServer<VersionStartup>(out var loggerFactory, out var server, $"{nameof(ClientUsingOldCallWithOriginalProtocol)}_{transportType}"))
using (StartServer<VersionStartup>(out var server))
{
var connectionBuilder = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory)
.WithLoggerFactory(LoggerFactory)
.WithUrl(server.Url + "/version", transportType);
var connection = connectionBuilder.Build();
@ -57,7 +52,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -71,10 +66,10 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(TransportTypes))]
public async Task ClientUsingOldCallWithNewProtocol(HttpTransportType transportType)
{
using (StartServer<VersionStartup>(out var loggerFactory, out var server, $"{nameof(ClientUsingOldCallWithNewProtocol)}_{transportType}"))
using (StartServer<VersionStartup>(out var server))
{
var connectionBuilder = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory)
.WithLoggerFactory(LoggerFactory)
.WithUrl(server.Url + "/version", transportType);
connectionBuilder.Services.AddSingleton<IHubProtocol>(new VersionedJsonHubProtocol(1000));
@ -90,7 +85,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -104,19 +99,19 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(TransportTypes))]
public async Task ClientUsingNewCallWithNewProtocol(HttpTransportType transportType)
{
using (StartServer<VersionStartup>(out var loggerFactory, out var server, $"{nameof(ClientUsingNewCallWithNewProtocol)}_{transportType}"))
using (StartServer<VersionStartup>(out var server))
{
var httpConnectionFactory = new HttpConnectionFactory(Options.Create(new HttpConnectionOptions
{
Url = new Uri(server.Url + "/version"),
Transports = transportType
}), loggerFactory);
}), LoggerFactory);
var tcs = new TaskCompletionSource<object>();
var proxyConnectionFactory = new ProxyConnectionFactory(httpConnectionFactory);
var connectionBuilder = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory);
.WithLoggerFactory(LoggerFactory);
connectionBuilder.Services.AddSingleton<IHubProtocol>(new VersionedJsonHubProtocol(1000));
connectionBuilder.Services.AddSingleton<IConnectionFactory>(proxyConnectionFactory);
@ -147,7 +142,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally
@ -159,6 +154,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Theory]
[MemberData(nameof(TransportTypes))]
[LogLevel(LogLevel.Trace)]
public async Task ClientWithUnsupportedProtocolVersionDoesNotConnect(HttpTransportType transportType)
{
bool ExpectedErrors(WriteContext writeContext)
@ -166,10 +162,10 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
return writeContext.LoggerName == typeof(HubConnection).FullName;
}
using (StartServer<VersionStartup>(out var loggerFactory, out var server, LogLevel.Trace, $"{nameof(ClientWithUnsupportedProtocolVersionDoesNotConnect)}_{transportType}", expectedErrorsFilter: ExpectedErrors))
using (StartServer<VersionStartup>(out var server, ExpectedErrors))
{
var connectionBuilder = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory)
.WithLoggerFactory(LoggerFactory)
.WithUrl(server.Url + "/version", transportType);
connectionBuilder.Services.AddSingleton<IHubProtocol>(new VersionedJsonHubProtocol(int.MaxValue));
@ -183,7 +179,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}
catch (Exception ex)
{
loggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
LoggerFactory.CreateLogger<HubConnectionTests>().LogError(ex, "{ExceptionType} from test", ex.GetType().FullName);
throw;
}
finally

View File

@ -13,7 +13,6 @@ using Microsoft.AspNetCore.Http.Connections.Client.Internal;
using Microsoft.AspNetCore.SignalR.Tests;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.AspNetCore.SignalR.Client.Tests
{
@ -21,16 +20,12 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
{
public class ConnectionLifecycle : VerifiableLoggedTest
{
public ConnectionLifecycle(ITestOutputHelper output) : base(output)
{
}
[Fact]
public async Task CanStartStartedConnection()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
await WithConnectionAsync(CreateConnection(loggerFactory: loggerFactory), async (connection) =>
await WithConnectionAsync(CreateConnection(loggerFactory: LoggerFactory), async (connection) =>
{
await connection.StartAsync(TransferFormat.Text).OrTimeout();
await connection.StartAsync(TransferFormat.Text).OrTimeout();
@ -41,10 +36,10 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
[Fact]
public async Task CanStartStartingConnection()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
await WithConnectionAsync(
CreateConnection(loggerFactory: loggerFactory, transport: new TestTransport(onTransportStart: SyncPoint.Create(out var syncPoint))),
CreateConnection(loggerFactory: LoggerFactory, transport: new TestTransport(onTransportStart: SyncPoint.Create(out var syncPoint))),
async (connection) =>
{
var firstStart = connection.StartAsync(TransferFormat.Text).OrTimeout();
@ -61,10 +56,10 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
[Fact]
public async Task CannotStartConnectionOnceDisposed()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
await WithConnectionAsync(
CreateConnection(loggerFactory: loggerFactory),
CreateConnection(loggerFactory: LoggerFactory),
async (connection) =>
{
await connection.StartAsync(TransferFormat.Text).OrTimeout();
@ -89,7 +84,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
writeContext.EventId.Name == "ErrorStartingTransport";
}
using (StartVerifiableLog(out var loggerFactory, expectedErrorsFilter: ExpectedErrors))
using (StartVerifiableLog(expectedErrorsFilter: ExpectedErrors))
{
var startCounter = 0;
var expected = new Exception("Transport failed to start");
@ -119,7 +114,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
await WithConnectionAsync(
CreateConnection(
loggerFactory: loggerFactory,
loggerFactory: LoggerFactory,
transportType: HttpTransports.All,
transport: new TestTransport(onTransportStart: OnTransportStart)),
async (connection) =>
@ -140,7 +135,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
writeContext.EventId.Name == "ErrorStartingTransport";
}
using (StartVerifiableLog(out var loggerFactory, expectedErrorsFilter: ExpectedErrors))
using (StartVerifiableLog(expectedErrorsFilter: ExpectedErrors))
{
var startCounter = 0;
var availableTransports = 3;
@ -153,7 +148,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
await WithConnectionAsync(
CreateConnection(
loggerFactory: loggerFactory,
loggerFactory: LoggerFactory,
transportType: HttpTransports.All,
transport: new TestTransport(onTransportStart: OnTransportStart)),
async (connection) =>
@ -175,10 +170,10 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
[Fact]
public async Task CanDisposeUnstartedConnection()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
await WithConnectionAsync(
CreateConnection(loggerFactory: loggerFactory),
CreateConnection(loggerFactory: LoggerFactory),
async (connection) =>
{
await connection.DisposeAsync();
@ -190,11 +185,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
[Fact]
public async Task CanDisposeStartingConnection()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
await WithConnectionAsync(
CreateConnection(
loggerFactory: loggerFactory,
loggerFactory: LoggerFactory,
transport: new TestTransport(
onTransportStart: SyncPoint.Create(out var transportStart),
onTransportStop: SyncPoint.Create(out var transportStop))),
@ -224,11 +219,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
[Fact]
public async Task CanDisposeDisposingConnection()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
await WithConnectionAsync(
CreateConnection(
loggerFactory: loggerFactory,
loggerFactory: LoggerFactory,
transport: new TestTransport(onTransportStop: SyncPoint.Create(out var transportStop))),
async (connection) =>
{
@ -289,7 +284,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
writeContext.EventId.Name == "ErrorSending";
}
using (StartVerifiableLog(out var loggerFactory, expectedErrorsFilter: ExpectedErrors))
using (StartVerifiableLog(expectedErrorsFilter: ExpectedErrors))
{
var httpHandler = new TestHttpMessageHandler();
@ -311,7 +306,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
});
await WithConnectionAsync(
CreateConnection(httpHandler, loggerFactory),
CreateConnection(httpHandler, LoggerFactory),
async (connection) =>
{
await connection.StartAsync(TransferFormat.Text).OrTimeout();
@ -348,7 +343,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
[Fact]
public async Task SSEWaitsForResponseToStart()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var httpHandler = new TestHttpMessageHandler();
@ -362,7 +357,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
var sse = new ServerSentEventsTransport(new HttpClient(httpHandler));
await WithConnectionAsync(
CreateConnection(httpHandler, loggerFactory: loggerFactory, transport: sse),
CreateConnection(httpHandler, loggerFactory: LoggerFactory, transport: sse),
async (connection) =>
{
var startTask = connection.StartAsync(TransferFormat.Text).OrTimeout();

View File

@ -15,7 +15,6 @@ using Microsoft.AspNetCore.Http.Connections.Client;
using Microsoft.AspNetCore.Http.Connections.Client.Internal;
using Microsoft.AspNetCore.SignalR.Tests;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.AspNetCore.SignalR.Client.Tests
{
@ -23,10 +22,6 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
{
public class Transport : VerifiableLoggedTest
{
public Transport(ITestOutputHelper output) : base(output)
{
}
[Theory]
[InlineData(HttpTransportType.LongPolling)]
[InlineData(HttpTransportType.ServerSentEvents)]
@ -81,7 +76,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
[InlineData(HttpTransportType.ServerSentEvents, false)]
public async Task HttpConnectionSetsInherentKeepAliveFeature(HttpTransportType transportType, bool expectedValue)
{
using (StartVerifiableLog(out var loggerFactory, testName: $"HttpConnectionSetsInherentKeepAliveFeature_{transportType}_{expectedValue}"))
using (StartVerifiableLog())
{
var testHttpHandler = new TestHttpMessageHandler(autoNegotiate: false);
@ -90,7 +85,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
testHttpHandler.OnRequest((request, next, token) => Task.FromResult(ResponseUtils.CreateResponse(HttpStatusCode.NoContent)));
await WithConnectionAsync(
CreateConnection(testHttpHandler, transportType: transportType, loggerFactory: loggerFactory),
CreateConnection(testHttpHandler, transportType: transportType, loggerFactory: LoggerFactory),
async (connection) =>
{
await connection.StartAsync(TransferFormat.Text).OrTimeout();

View File

@ -16,16 +16,11 @@ using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Logging.Testing;
using Moq;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.AspNetCore.SignalR.Client.Tests
{
public partial class HttpConnectionTests : VerifiableLoggedTest
{
public HttpConnectionTests(ITestOutputHelper output) : base(output)
{
}
[Fact]
public void CannotCreateConnectionWithNullUrl()
{

View File

@ -13,17 +13,11 @@ 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 : VerifiableLoggedTest
{
public HubConnectionTests(ITestOutputHelper output)
: base(output)
{
}
[Fact]
public async Task InvokeThrowsIfSerializingMessageFails()
{
@ -123,11 +117,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
[Fact]
public async Task ServerTimeoutIsDisabledWhenUsingTransportWithInherentKeepAlive()
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var testConnection = new TestConnection();
testConnection.Features.Set<IConnectionInherentKeepAliveFeature>(new TestKeepAliveFeature() { HasInherentKeepAlive = true });
var hubConnection = CreateHubConnection(testConnection, loggerFactory: loggerFactory);
var hubConnection = CreateHubConnection(testConnection, loggerFactory: LoggerFactory);
hubConnection.ServerTimeout = TimeSpan.FromMilliseconds(1);
await hubConnection.StartAsync().OrTimeout();
@ -148,6 +142,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
}
[Fact]
[LogLevel(LogLevel.Trace)]
public async Task PendingInvocationsAreTerminatedIfServerTimeoutIntervalElapsesWithNoMessages()
{
bool ExpectedErrors(WriteContext writeContext)
@ -156,9 +151,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
writeContext.EventId.Name == "ShutdownWithError";
}
using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace, expectedErrorsFilter: ExpectedErrors))
using (StartVerifiableLog(expectedErrorsFilter: ExpectedErrors))
{
var hubConnection = CreateHubConnection(new TestConnection(), loggerFactory: loggerFactory);
var hubConnection = CreateHubConnection(new TestConnection(), loggerFactory: LoggerFactory);
hubConnection.ServerTimeout = TimeSpan.FromMilliseconds(2000);
await hubConnection.StartAsync().OrTimeout();

View File

@ -8,20 +8,15 @@ using System.IO.Pipelines;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Http.Connections.Client;
using Microsoft.AspNetCore.Http.Connections.Client.Internal;
using Microsoft.AspNetCore.SignalR.Tests;
using Moq;
using Moq.Protected;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.AspNetCore.SignalR.Client.Tests
{
@ -29,10 +24,6 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
{
private static readonly Uri TestUri = new Uri("http://example.com/?id=1234");
public LongPollingTransportTests(ITestOutputHelper output) : base(output)
{
}
[Fact]
public async Task LongPollingTransportStopsPollAndSendLoopsWhenTransportStopped()
{
@ -258,11 +249,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
}
});
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
using (var httpClient = new HttpClient(mockHttpHandler.Object))
{
var longPollingTransport = new LongPollingTransport(httpClient, loggerFactory);
var longPollingTransport = new LongPollingTransport(httpClient, LoggerFactory);
await longPollingTransport.StartAsync(TestUri, TransferFormat.Binary).OrTimeout();

View File

@ -6,28 +6,20 @@ using System.IO;
using System.IO.Pipelines;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Http.Connections.Client;
using Microsoft.AspNetCore.Http.Connections.Client.Internal;
using Microsoft.AspNetCore.SignalR.Tests;
using Microsoft.Extensions.Logging.Testing;
using Moq;
using Moq.Protected;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.AspNetCore.SignalR.Client.Tests
{
public class ServerSentEventsTransportTests : VerifiableLoggedTest
{
public ServerSentEventsTransportTests(ITestOutputHelper output) : base(output)
{
}
[Fact]
public async Task CanStartStopSSETransport()
{
@ -55,9 +47,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
try
{
using (var httpClient = new HttpClient(mockHttpHandler.Object))
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var sseTransport = new ServerSentEventsTransport(httpClient, loggerFactory);
var sseTransport = new ServerSentEventsTransport(httpClient, LoggerFactory);
await sseTransport.StartAsync(
new Uri("http://fakeuri.org"), TransferFormat.Text).OrTimeout();
@ -98,9 +90,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
});
using (var httpClient = new HttpClient(mockHttpHandler.Object))
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var sseTransport = new ServerSentEventsTransport(httpClient, loggerFactory);
var sseTransport = new ServerSentEventsTransport(httpClient, LoggerFactory);
Task transportActiveTask;
try
@ -146,9 +138,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
});
using (var httpClient = new HttpClient(mockHttpHandler.Object))
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var sseTransport = new ServerSentEventsTransport(httpClient, loggerFactory);
var sseTransport = new ServerSentEventsTransport(httpClient, LoggerFactory);
await sseTransport.StartAsync(
new Uri("http://fakeuri.org"), TransferFormat.Text).OrTimeout();
@ -236,9 +228,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
});
using (var httpClient = new HttpClient(mockHttpHandler.Object))
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var sseTransport = new ServerSentEventsTransport(httpClient, loggerFactory);
var sseTransport = new ServerSentEventsTransport(httpClient, LoggerFactory);
await sseTransport.StartAsync(
new Uri("http://fakeuri.org"), TransferFormat.Text).OrTimeout();
@ -263,9 +255,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
});
using (var httpClient = new HttpClient(mockHttpHandler.Object))
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var sseTransport = new ServerSentEventsTransport(httpClient, loggerFactory);
var sseTransport = new ServerSentEventsTransport(httpClient, LoggerFactory);
await sseTransport.StartAsync(
new Uri("http://fakeuri.org"), TransferFormat.Text).OrTimeout();
@ -317,9 +309,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
});
using (var httpClient = new HttpClient(mockHttpHandler.Object))
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var sseTransport = new ServerSentEventsTransport(httpClient, loggerFactory);
var sseTransport = new ServerSentEventsTransport(httpClient, LoggerFactory);
await sseTransport.StartAsync(
new Uri("http://fakeuri.org"), TransferFormat.Text).OrTimeout();
@ -352,9 +344,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
});
using (var httpClient = new HttpClient(mockHttpHandler.Object))
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var sseTransport = new ServerSentEventsTransport(httpClient, loggerFactory);
var sseTransport = new ServerSentEventsTransport(httpClient, LoggerFactory);
var ex = await Assert.ThrowsAsync<ArgumentException>(() => sseTransport.StartAsync(new Uri("http://fakeuri.org"), TransferFormat.Binary).OrTimeout());
@ -379,9 +371,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
});
using (var httpClient = new HttpClient(mockHttpHandler.Object))
using (StartVerifiableLog(out var loggerFactory, $"{nameof(SSETransportThrowsForInvalidTransferFormat)}_{transferFormat}"))
using (StartVerifiableLog())
{
var sseTransport = new ServerSentEventsTransport(httpClient, loggerFactory);
var sseTransport = new ServerSentEventsTransport(httpClient, LoggerFactory);
var exception = await Assert.ThrowsAsync<ArgumentException>(() =>
sseTransport.StartAsync(new Uri("http://fakeuri.org"), transferFormat));

View File

@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
{
private readonly RedisServerFixture<Startup> _serverFixture;
public RedisEndToEndTests(RedisServerFixture<Startup> serverFixture, ITestOutputHelper output) : base(output)
public RedisEndToEndTests(RedisServerFixture<Startup> serverFixture)
{
if (serverFixture == null)
{
@ -43,12 +43,11 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
[MemberData(nameof(TransportTypesAndProtocolTypes))]
public async Task HubConnectionCanSendAndReceiveMessages(HttpTransportType transportType, string protocolName)
{
using (StartVerifiableLog(out var loggerFactory, testName:
$"{nameof(HubConnectionCanSendAndReceiveMessages)}_{transportType.ToString()}_{protocolName}"))
using (StartVerifiableLog())
{
var protocol = HubProtocolHelpers.GetHubProtocol(protocolName);
var connection = CreateConnection(_serverFixture.FirstServer.Url + "/echo", transportType, protocol, loggerFactory);
var connection = CreateConnection(_serverFixture.FirstServer.Url + "/echo", transportType, protocol, LoggerFactory);
await connection.StartAsync().OrTimeout();
var str = await connection.InvokeAsync<string>("Echo", "Hello, World!").OrTimeout();
@ -64,13 +63,12 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
[MemberData(nameof(TransportTypesAndProtocolTypes))]
public async Task HubConnectionCanSendAndReceiveGroupMessages(HttpTransportType transportType, string protocolName)
{
using (StartVerifiableLog(out var loggerFactory, testName:
$"{nameof(HubConnectionCanSendAndReceiveGroupMessages)}_{transportType.ToString()}_{protocolName}"))
using (StartVerifiableLog())
{
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 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));
@ -97,13 +95,12 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
[MemberData(nameof(TransportTypesAndProtocolTypes))]
public async Task CanSendAndReceiveUserMessagesFromMultipleConnectionsWithSameUser(HttpTransportType transportType, string protocolName)
{
using (StartVerifiableLog(out var loggerFactory, testName:
$"{nameof(CanSendAndReceiveUserMessagesFromMultipleConnectionsWithSameUser)}_{transportType.ToString()}_{protocolName}"))
using (StartVerifiableLog())
{
var protocol = HubProtocolHelpers.GetHubProtocol(protocolName);
var connection = CreateConnection(_serverFixture.FirstServer.Url + "/echo", transportType, protocol, loggerFactory, userName: "userA");
var secondConnection = CreateConnection(_serverFixture.SecondServer.Url + "/echo", transportType, protocol, loggerFactory, userName: "userA");
var connection = CreateConnection(_serverFixture.FirstServer.Url + "/echo", transportType, protocol, LoggerFactory, userName: "userA");
var secondConnection = CreateConnection(_serverFixture.SecondServer.Url + "/echo", transportType, protocol, LoggerFactory, userName: "userA");
var tcs = new TaskCompletionSource<string>();
connection.On<string>("Echo", message => tcs.TrySetResult(message));
@ -130,13 +127,12 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
// 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}"))
using (StartVerifiableLog())
{
var protocol = HubProtocolHelpers.GetHubProtocol(protocolName);
var firstConnection = CreateConnection(_serverFixture.FirstServer.Url + "/echo", transportType, protocol, loggerFactory, userName: "userA");
var secondConnection = CreateConnection(_serverFixture.SecondServer.Url + "/echo", transportType, protocol, loggerFactory, userName: "userA");
var firstConnection = CreateConnection(_serverFixture.FirstServer.Url + "/echo", transportType, protocol, LoggerFactory, userName: "userA");
var secondConnection = CreateConnection(_serverFixture.SecondServer.Url + "/echo", transportType, protocol, LoggerFactory, userName: "userA");
var tcs = new TaskCompletionSource<string>();
firstConnection.On<string>("Echo", message => tcs.TrySetResult(message));

View File

@ -12,7 +12,6 @@ using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
{
@ -28,7 +27,7 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
{
private readonly RedisServerFixture<Startup> _serverFixture;
public RedisEndToEndTests(RedisServerFixture<Startup> serverFixture, ITestOutputHelper output) : base(output)
public RedisEndToEndTests(RedisServerFixture<Startup> serverFixture)
{
if (serverFixture == null)
{
@ -43,12 +42,11 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
[MemberData(nameof(TransportTypesAndProtocolTypes))]
public async Task HubConnectionCanSendAndReceiveMessages(HttpTransportType transportType, string protocolName)
{
using (StartVerifiableLog(out var loggerFactory, testName:
$"{nameof(HubConnectionCanSendAndReceiveMessages)}_{transportType.ToString()}_{protocolName}"))
using (StartVerifiableLog())
{
var protocol = HubProtocolHelpers.GetHubProtocol(protocolName);
var connection = CreateConnection(_serverFixture.FirstServer.Url + "/echo", transportType, protocol, loggerFactory);
var connection = CreateConnection(_serverFixture.FirstServer.Url + "/echo", transportType, protocol, LoggerFactory);
await connection.StartAsync().OrTimeout();
var str = await connection.InvokeAsync<string>("Echo", "Hello, World!").OrTimeout();
@ -64,13 +62,12 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
[MemberData(nameof(TransportTypesAndProtocolTypes))]
public async Task HubConnectionCanSendAndReceiveGroupMessages(HttpTransportType transportType, string protocolName)
{
using (StartVerifiableLog(out var loggerFactory, testName:
$"{nameof(HubConnectionCanSendAndReceiveGroupMessages)}_{transportType.ToString()}_{protocolName}"))
using (StartVerifiableLog())
{
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 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));
@ -97,13 +94,12 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
[MemberData(nameof(TransportTypesAndProtocolTypes))]
public async Task CanSendAndReceiveUserMessagesFromMultipleConnectionsWithSameUser(HttpTransportType transportType, string protocolName)
{
using (StartVerifiableLog(out var loggerFactory, testName:
$"{nameof(CanSendAndReceiveUserMessagesFromMultipleConnectionsWithSameUser)}_{transportType.ToString()}_{protocolName}"))
using (StartVerifiableLog())
{
var protocol = HubProtocolHelpers.GetHubProtocol(protocolName);
var connection = CreateConnection(_serverFixture.FirstServer.Url + "/echo", transportType, protocol, loggerFactory, userName: "userA");
var secondConnection = CreateConnection(_serverFixture.SecondServer.Url + "/echo", transportType, protocol, loggerFactory, userName: "userA");
var connection = CreateConnection(_serverFixture.FirstServer.Url + "/echo", transportType, protocol, LoggerFactory, userName: "userA");
var secondConnection = CreateConnection(_serverFixture.SecondServer.Url + "/echo", transportType, protocol, LoggerFactory, userName: "userA");
var tcs = new TaskCompletionSource<string>();
connection.On<string>("Echo", message => tcs.TrySetResult(message));
@ -130,13 +126,12 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
// 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}"))
using (StartVerifiableLog())
{
var protocol = HubProtocolHelpers.GetHubProtocol(protocolName);
var firstConnection = CreateConnection(_serverFixture.FirstServer.Url + "/echo", transportType, protocol, loggerFactory, userName: "userA");
var secondConnection = CreateConnection(_serverFixture.SecondServer.Url + "/echo", transportType, protocol, loggerFactory, userName: "userA");
var firstConnection = CreateConnection(_serverFixture.FirstServer.Url + "/echo", transportType, protocol, LoggerFactory, userName: "userA");
var secondConnection = CreateConnection(_serverFixture.SecondServer.Url + "/echo", transportType, protocol, LoggerFactory, userName: "userA");
var tcs = new TaskCompletionSource<string>();
firstConnection.On<string>("Echo", message => tcs.TrySetResult(message));

View File

@ -3,10 +3,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Xunit.Abstractions;
namespace Microsoft.AspNetCore.SignalR.Tests
{
@ -14,7 +11,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
{
private readonly Func<WriteContext, bool> _globalExpectedErrorsFilter;
public FunctionalTestBase(ITestOutputHelper output) : base(output)
public FunctionalTestBase()
{
// Suppress errors globally here
_globalExpectedErrorsFilter = (writeContext) => false;
@ -38,17 +35,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests
};
}
public IDisposable StartServer<T>(out ILoggerFactory loggerFactory, out InProcessTestServer<T> testServer, LogLevel minLogLevel, [CallerMemberName] string testName = null, Func<WriteContext, bool> expectedErrorsFilter = null) where T : class
public IDisposable StartServer<T>(out InProcessTestServer<T> testServer, Func<WriteContext, bool> expectedErrorsFilter = null) where T : class
{
var disposable = base.StartVerifiableLog(out loggerFactory, minLogLevel, testName, ResolveExpectedErrorsFilter(expectedErrorsFilter));
testServer = new InProcessTestServer<T>(loggerFactory);
return new MultiDisposable(testServer, disposable);
}
public IDisposable StartServer<T>(out ILoggerFactory loggerFactory, out InProcessTestServer<T> testServer, [CallerMemberName] string testName = null, Func<WriteContext, bool> expectedErrorsFilter = null) where T : class
{
var disposable = base.StartVerifiableLog(out loggerFactory, testName, ResolveExpectedErrorsFilter(expectedErrorsFilter));
testServer = new InProcessTestServer<T>(loggerFactory);
var disposable = base.StartVerifiableLog(ResolveExpectedErrorsFilter(expectedErrorsFilter));
testServer = new InProcessTestServer<T>(LoggerFactory);
return new MultiDisposable(testServer, disposable);
}

View File

@ -2,37 +2,20 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Runtime.CompilerServices;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Xunit.Abstractions;
namespace Microsoft.AspNetCore.SignalR.Tests
{
public class VerifiableLoggedTest : LoggedTest
{
public VerifiableLoggedTest(ITestOutputHelper output) : base(output)
public virtual IDisposable StartVerifiableLog(Func<WriteContext, bool> expectedErrorsFilter = null)
{
return CreateScope(expectedErrorsFilter);
}
public virtual IDisposable StartVerifiableLog(out ILoggerFactory loggerFactory, [CallerMemberName] string testName = null, Func<WriteContext, bool> expectedErrorsFilter = null)
private VerifyNoErrorsScope CreateScope(Func<WriteContext, bool> expectedErrorsFilter = null)
{
var disposable = StartLog(out loggerFactory, testName);
return CreateScope(ref loggerFactory, disposable, expectedErrorsFilter);
}
public virtual IDisposable StartVerifiableLog(out ILoggerFactory loggerFactory, LogLevel minLogLevel, [CallerMemberName] string testName = null, Func<WriteContext, bool> expectedErrorsFilter = null)
{
var disposable = StartLog(out loggerFactory, minLogLevel, testName);
return CreateScope(ref loggerFactory, disposable, expectedErrorsFilter);
}
private VerifyNoErrorsScope CreateScope(ref ILoggerFactory loggerFactory, IDisposable wrappedDisposable = null, Func<WriteContext, bool> expectedErrorsFilter = null)
{
loggerFactory = new WrappingLoggerFactory(loggerFactory ?? new LoggerFactory());
return new VerifyNoErrorsScope(loggerFactory, wrappedDisposable, expectedErrorsFilter);
return new VerifyNoErrorsScope(LoggerFactory, wrappedDisposable: null, expectedErrorsFilter);
}
}
}

View File

@ -2,9 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;

View File

@ -21,7 +21,6 @@ using Microsoft.Extensions.Logging.Testing;
using Moq;
using Moq.Protected;
using Xunit;
using Xunit.Abstractions;
using HttpConnectionOptions = Microsoft.AspNetCore.Http.Connections.Client.HttpConnectionOptions;
namespace Microsoft.AspNetCore.SignalR.Tests
@ -34,19 +33,15 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[Collection(EndToEndTestsCollection.Name)]
public class EndToEndTests : FunctionalTestBase
{
public EndToEndTests(ITestOutputHelper output) : base(output)
{
}
[Fact]
public async Task CanStartAndStopConnectionUsingDefaultTransport()
{
using (StartServer<Startup>(out var loggerFactory, out var server))
using (StartServer<Startup>(out var server))
{
var url = server.Url + "/echo";
// The test should connect to the server using WebSockets transport on Windows 8 and newer.
// On Windows 7/2008R2 it should use ServerSentEvents transport to connect to the server.
var connection = new HttpConnection(new Uri(url), HttpTransports.All, loggerFactory);
var connection = new HttpConnection(new Uri(url), HttpTransports.All, LoggerFactory);
await connection.StartAsync(TransferFormat.Binary).OrTimeout();
await connection.DisposeAsync().OrTimeout();
}
@ -61,14 +56,14 @@ namespace Microsoft.AspNetCore.SignalR.Tests
writeContext.EventId.Name == "ErrorStartingTransport";
}
using (StartServer<Startup>(out var loggerFactory, out var server, expectedErrorsFilter: ExpectedErrors))
using (StartServer<Startup>(out var server, expectedErrorsFilter: ExpectedErrors))
{
var url = server.Url + "/echo";
// The test should connect to the server using WebSockets transport on Windows 8 and newer.
// On Windows 7/2008R2 it should use ServerSentEvents transport to connect to the server.
// The test logic lives in the TestTransportFactory and FakeTransport.
var connection = new HttpConnection(new HttpConnectionOptions { Url = new Uri(url) }, loggerFactory, new TestTransportFactory());
var connection = new HttpConnection(new HttpConnectionOptions { Url = new Uri(url) }, LoggerFactory, new TestTransportFactory());
await connection.StartAsync(TransferFormat.Text).OrTimeout();
await connection.DisposeAsync().OrTimeout();
}
@ -76,12 +71,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[Theory]
[MemberData(nameof(TransportTypes))]
[LogLevel(LogLevel.Trace)]
public async Task CanStartAndStopConnectionUsingGivenTransport(HttpTransportType transportType)
{
using (StartServer<Startup>(out var loggerFactory, out var server, minLogLevel: LogLevel.Trace, testName: $"CanStartAndStopConnectionUsingGivenTransport_{transportType}"))
using (StartServer<Startup>(out var server))
{
var url = server.Url + "/echo";
var connection = new HttpConnection(new Uri(url), transportType, loggerFactory);
var connection = new HttpConnection(new Uri(url), transportType, LoggerFactory);
await connection.StartAsync(TransferFormat.Text).OrTimeout();
await connection.DisposeAsync().OrTimeout();
}
@ -91,9 +87,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition]
public async Task WebSocketsTest()
{
using (StartServer<Startup>(out var loggerFactory, out var server))
using (StartServer<Startup>(out var server))
{
var logger = loggerFactory.CreateLogger<EndToEndTests>();
var logger = LoggerFactory.CreateLogger<EndToEndTests>();
const string message = "Hello, World!";
using (var ws = new ClientWebSocket())
@ -129,9 +125,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition]
public async Task WebSocketsReceivesAndSendsPartialFramesTest()
{
using (StartServer<Startup>(out var loggerFactory, out var server))
using (StartServer<Startup>(out var server))
{
var logger = loggerFactory.CreateLogger<EndToEndTests>();
var logger = LoggerFactory.CreateLogger<EndToEndTests>();
const string message = "Hello, World!";
using (var ws = new ClientWebSocket())
@ -168,9 +164,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition]
public async Task HttpRequestsNotSentWhenWebSocketsTransportRequestedAndSkipNegotiationSet()
{
using (StartServer<Startup>(out var loggerFactory, out var server))
using (StartServer<Startup>(out var server))
{
var logger = loggerFactory.CreateLogger<EndToEndTests>();
var logger = LoggerFactory.CreateLogger<EndToEndTests>();
var url = server.Url + "/echo";
var mockHttpHandler = new Mock<HttpMessageHandler>();
@ -187,7 +183,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
HttpMessageHandlerFactory = (httpMessageHandler) => mockHttpHandler.Object
};
var connection = new HttpConnection(httpOptions, loggerFactory);
var connection = new HttpConnection(httpOptions, LoggerFactory);
try
{
@ -218,9 +214,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[InlineData(HttpTransportType.ServerSentEvents)]
public async Task HttpConnectionThrowsIfSkipNegotiationSetAndTransportIsNotWebSockets(HttpTransportType transportType)
{
using (StartServer<Startup>(out var loggerFactory, out var server))
using (StartServer<Startup>(out var server))
{
var logger = loggerFactory.CreateLogger<EndToEndTests>();
var logger = LoggerFactory.CreateLogger<EndToEndTests>();
var url = server.Url + "/echo";
var mockHttpHandler = new Mock<HttpMessageHandler>();
@ -237,7 +233,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
HttpMessageHandlerFactory = (httpMessageHandler) => mockHttpHandler.Object
};
var connection = new HttpConnection(httpOptions, loggerFactory);
var connection = new HttpConnection(httpOptions, LoggerFactory);
try
{
@ -258,16 +254,17 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[Theory]
[MemberData(nameof(TransportTypesAndTransferFormats))]
[LogLevel(LogLevel.Trace)]
public async Task ConnectionCanSendAndReceiveMessages(HttpTransportType transportType, TransferFormat requestedTransferFormat)
{
using (StartServer<Startup>(out var loggerFactory, out var server, minLogLevel: LogLevel.Trace, testName: $"ConnectionCanSendAndReceiveMessages_{transportType.ToString()}_{requestedTransferFormat.ToString()}"))
using (StartServer<Startup>(out var server))
{
var logger = loggerFactory.CreateLogger<EndToEndTests>();
var logger = LoggerFactory.CreateLogger<EndToEndTests>();
const string message = "Major Key";
var url = server.Url + "/echo";
var connection = new HttpConnection(new Uri(url), transportType, loggerFactory);
var connection = new HttpConnection(new Uri(url), transportType, LoggerFactory);
try
{
logger.LogInformation("Starting connection to {url}", url);
@ -310,26 +307,20 @@ namespace Microsoft.AspNetCore.SignalR.Tests
}
}
public static IEnumerable<object[]> MessageSizesData
{
get
{
yield return new object[] { new string('A', 5 * 4096) };
yield return new object[] { new string('A', 1000 * 4096 + 32) };
}
}
[ConditionalTheory]
[WebSocketsSupportedCondition]
[MemberData(nameof(MessageSizesData))]
public async Task ConnectionCanSendAndReceiveDifferentMessageSizesWebSocketsTransport(string message)
[InlineData(5 * 4096)]
[InlineData(1000 * 4096 + 32)]
[LogLevel(LogLevel.Trace)]
public async Task ConnectionCanSendAndReceiveDifferentMessageSizesWebSocketsTransport(int length)
{
using (StartServer<Startup>(out var loggerFactory, out var server, LogLevel.Trace, testName: $"ConnectionCanSendAndReceiveDifferentMessageSizesWebSocketsTransport_{message.Length}"))
var message = new string('A', length);
using (StartServer<Startup>(out var server))
{
var logger = loggerFactory.CreateLogger<EndToEndTests>();
var logger = LoggerFactory.CreateLogger<EndToEndTests>();
var url = server.Url + "/echo";
var connection = new HttpConnection(new Uri(url), HttpTransportType.WebSockets, loggerFactory);
var connection = new HttpConnection(new Uri(url), HttpTransportType.WebSockets, LoggerFactory);
try
{
@ -364,6 +355,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[ConditionalFact]
[WebSocketsSupportedCondition]
[LogLevel(LogLevel.Trace)]
public async Task UnauthorizedWebSocketsConnectionDoesNotConnect()
{
bool ExpectedErrors(WriteContext writeContext)
@ -372,12 +364,12 @@ namespace Microsoft.AspNetCore.SignalR.Tests
writeContext.EventId.Name == "ErrorWithNegotiation";
}
using (StartServer<Startup>(out var loggerFactory, out var server, LogLevel.Trace, expectedErrorsFilter: ExpectedErrors))
using (StartServer<Startup>(out var server, ExpectedErrors))
{
var logger = loggerFactory.CreateLogger<EndToEndTests>();
var logger = LoggerFactory.CreateLogger<EndToEndTests>();
var url = server.Url + "/auth";
var connection = new HttpConnection(new Uri(url), HttpTransportType.WebSockets, loggerFactory);
var connection = new HttpConnection(new Uri(url), HttpTransportType.WebSockets, LoggerFactory);
var exception = await Assert.ThrowsAsync<HttpRequestException>(() => connection.StartAsync(TransferFormat.Binary).OrTimeout());
@ -387,6 +379,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[ConditionalFact]
[WebSocketsSupportedCondition]
[LogLevel(LogLevel.Trace)]
public async Task UnauthorizedDirectWebSocketsConnectionDoesNotConnect()
{
bool ExpectedErrors(WriteContext writeContext)
@ -395,9 +388,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
writeContext.EventId.Name == "ErrorStartingTransport";
}
using (StartServer<Startup>(out var loggerFactory, out var server, LogLevel.Trace, expectedErrorsFilter: ExpectedErrors))
using (StartServer<Startup>(out var server, ExpectedErrors))
{
var logger = loggerFactory.CreateLogger<EndToEndTests>();
var logger = LoggerFactory.CreateLogger<EndToEndTests>();
var url = server.Url + "/auth";
var options = new HttpConnectionOptions
@ -407,7 +400,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
SkipNegotiation = true
};
var connection = new HttpConnection(options, loggerFactory);
var connection = new HttpConnection(options, LoggerFactory);
await Assert.ThrowsAsync<WebSocketException>(() => connection.StartAsync(TransferFormat.Binary).OrTimeout());
}
@ -416,6 +409,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[Theory]
[InlineData(HttpTransportType.LongPolling)]
[InlineData(HttpTransportType.ServerSentEvents)]
[LogLevel(LogLevel.Trace)]
public async Task UnauthorizedConnectionDoesNotConnect(HttpTransportType transportType)
{
bool ExpectedErrors(WriteContext writeContext)
@ -424,12 +418,12 @@ namespace Microsoft.AspNetCore.SignalR.Tests
writeContext.EventId.Name == "ErrorWithNegotiation";
}
using (StartServer<Startup>(out var loggerFactory, out var server, LogLevel.Trace, testName: $"{nameof(UnauthorizedConnectionDoesNotConnect)}_{transportType}", expectedErrorsFilter: ExpectedErrors))
using (StartServer<Startup>(out var server, ExpectedErrors))
{
var logger = loggerFactory.CreateLogger<EndToEndTests>();
var logger = LoggerFactory.CreateLogger<EndToEndTests>();
var url = server.Url + "/auth";
var connection = new HttpConnection(new Uri(url), transportType, loggerFactory);
var connection = new HttpConnection(new Uri(url), transportType, LoggerFactory);
try
{
@ -481,13 +475,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests
private async Task ServerClosesConnectionWithErrorIfHubCannotBeCreated(HttpTransportType transportType)
{
using (StartServer<Startup>(out var loggerFactory, out var server, testName: $"ConnectionCanSendAndReceiveMessages_{transportType.ToString()}"))
using (StartServer<Startup>(out var server))
{
var logger = loggerFactory.CreateLogger<EndToEndTests>();
var logger = LoggerFactory.CreateLogger<EndToEndTests>();
var url = server.Url + "/uncreatable";
var connection = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory)
.WithLoggerFactory(LoggerFactory)
.WithUrl(url, transportType)
.Build();
try

View File

@ -4,6 +4,8 @@
using System;
using Microsoft.AspNetCore.SignalR.Protocol;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Xunit;
namespace Microsoft.AspNetCore.SignalR.Tests
@ -50,7 +52,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
}
}
public static IServiceProvider CreateServiceProvider(Action<ServiceCollection> addServices = null)
public static IServiceProvider CreateServiceProvider(Action<ServiceCollection> addServices = null, ILoggerFactory loggerFactory = null)
{
var services = new ServiceCollection();
services.AddOptions()
@ -61,12 +63,17 @@ namespace Microsoft.AspNetCore.SignalR.Tests
addServices?.Invoke(services);
if (loggerFactory != null)
{
services.AddSingleton(loggerFactory);
}
return services.BuildServiceProvider();
}
public static Connections.ConnectionHandler GetHubConnectionHandler(Type hubType)
public static Connections.ConnectionHandler GetHubConnectionHandler(Type hubType, ILoggerFactory loggerFactory = null)
{
var serviceProvider = CreateServiceProvider();
var serviceProvider = CreateServiceProvider(null, loggerFactory);
return (Connections.ConnectionHandler)serviceProvider.GetService(GetConnectionHandlerType(hubType));
}
}

View File

@ -15,17 +15,12 @@ using Microsoft.AspNetCore.Http.Connections.Client.Internal;
using Microsoft.AspNetCore.Testing.xunit;
using Moq;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.AspNetCore.SignalR.Tests
{
[Collection(EndToEndTestsCollection.Name)]
public class WebSocketsTransportTests : FunctionalTestBase
{
public WebSocketsTransportTests(ITestOutputHelper output) : base(output)
{
}
[ConditionalFact]
[WebSocketsSupportedCondition]
public void HttpOptionsSetOntoWebSocketOptions()
@ -57,9 +52,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition]
public async Task WebSocketsTransportStopsSendAndReceiveLoopsWhenTransportIsStopped()
{
using (StartServer<Startup>(out var loggerFactory, out var server))
using (StartServer<Startup>(out var server))
{
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: loggerFactory, accessTokenProvider: null);
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: LoggerFactory, accessTokenProvider: null);
await webSocketsTransport.StartAsync(new Uri(server.WebSocketsUrl + "/echo"),
TransferFormat.Binary).OrTimeout();
await webSocketsTransport.StopAsync().OrTimeout();
@ -71,9 +66,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition]
public async Task WebSocketsTransportSendsUserAgent()
{
using (StartServer<Startup>(out var loggerFactory, out var server))
using (StartServer<Startup>(out var server))
{
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: loggerFactory, accessTokenProvider: null);
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: LoggerFactory, accessTokenProvider: null);
await webSocketsTransport.StartAsync(new Uri(server.WebSocketsUrl + "/httpheader"),
TransferFormat.Binary).OrTimeout();
@ -99,9 +94,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition]
public async Task WebSocketsTransportSendsXRequestedWithHeader()
{
using (StartServer<Startup>(out var loggerFactory, out var server))
using (StartServer<Startup>(out var server))
{
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: loggerFactory, accessTokenProvider: null);
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: LoggerFactory, accessTokenProvider: null);
await webSocketsTransport.StartAsync(new Uri(server.WebSocketsUrl + "/httpheader"),
TransferFormat.Binary).OrTimeout();
@ -122,9 +117,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition]
public async Task WebSocketsTransportStopsWhenConnectionChannelClosed()
{
using (StartServer<Startup>(out var loggerFactory, out var server))
using (StartServer<Startup>(out var server))
{
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: loggerFactory, accessTokenProvider: null);
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: LoggerFactory, accessTokenProvider: null);
await webSocketsTransport.StartAsync(new Uri(server.WebSocketsUrl + "/echo"),
TransferFormat.Binary);
webSocketsTransport.Output.Complete();
@ -138,9 +133,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[InlineData(TransferFormat.Binary)]
public async Task WebSocketsTransportStopsWhenConnectionClosedByTheServer(TransferFormat transferFormat)
{
using (StartServer<Startup>(out var loggerFactory, out var server))
using (StartServer<Startup>(out var server))
{
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: loggerFactory, accessTokenProvider: null);
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: LoggerFactory, accessTokenProvider: null);
await webSocketsTransport.StartAsync(new Uri(server.WebSocketsUrl + "/echoAndClose"), transferFormat);
await webSocketsTransport.Output.WriteAsync(new byte[] { 0x42 });
@ -160,9 +155,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[InlineData(TransferFormat.Binary)]
public async Task WebSocketsTransportSetsTransferFormat(TransferFormat transferFormat)
{
using (StartServer<Startup>(out var loggerFactory, out var server))
using (StartServer<Startup>(out var server))
{
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: loggerFactory, accessTokenProvider: null);
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: LoggerFactory, accessTokenProvider: null);
await webSocketsTransport.StartAsync(new Uri(server.WebSocketsUrl + "/echo"),
transferFormat).OrTimeout();
@ -178,9 +173,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition]
public async Task WebSocketsTransportThrowsForInvalidTransferFormat(TransferFormat transferFormat)
{
using (StartVerifiableLog(out var loggerFactory))
using (StartVerifiableLog())
{
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: loggerFactory, accessTokenProvider: null);
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, LoggerFactory, accessTokenProvider: null);
var exception = await Assert.ThrowsAsync<ArgumentException>(() =>
webSocketsTransport.StartAsync(new Uri("http://fakeuri.org"), transferFormat));