From 585bcc3ee0dbaa0801b877b46c6d14b4105f1558 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Sun, 15 Apr 2018 19:02:56 +1200 Subject: [PATCH] How about this? --- .../HubConnectionTests.cs | 2 +- .../ServerFixture.cs | 24 ++++++++++++++----- .../ServerLogScope.cs | 6 ++--- .../VerifiableServerLoggedTest.cs | 10 ++++---- .../EndToEndTests.cs | 6 ++++- .../WebSocketsTransportTests.cs | 2 +- 6 files changed, 33 insertions(+), 17 deletions(-) diff --git a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs index b198d664ff..922c80a7eb 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests } [Collection(HubConnectionTestsCollection.Name)] - public class HubConnectionTests : VerifiableServerLoggedTest + public class HubConnectionTests : VerifiableServerLoggedTest { private readonly ServerFixture _serverFixture; public HubConnectionTests(ServerFixture serverFixture, ITestOutputHelper output) : base(serverFixture, output) diff --git a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/ServerFixture.cs b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/ServerFixture.cs index 31330b9181..79e7bc89e4 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/ServerFixture.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/ServerFixture.cs @@ -18,7 +18,18 @@ using Microsoft.Extensions.Logging.Testing; namespace Microsoft.AspNetCore.SignalR.Tests { - public class ServerFixture : IDisposable + public abstract class ServerFixture : IDisposable + { + internal abstract event Action ServerLogged; + + public abstract string WebSocketsUrl { get; } + + public abstract string Url { get; } + + public abstract void Dispose(); + } + + public class ServerFixture : ServerFixture where TStartup : class { private readonly ILoggerFactory _loggerFactory; @@ -28,16 +39,17 @@ namespace Microsoft.AspNetCore.SignalR.Tests private readonly IDisposable _logToken; private readonly LogSinkProvider _logSinkProvider; + private string _url; - internal event Action ServerLogged + internal override event Action ServerLogged { add => _logSinkProvider.RecordLogged += value; remove => _logSinkProvider.RecordLogged -= value; } - public string WebSocketsUrl => Url.Replace("http", "ws"); + public override string WebSocketsUrl => Url.Replace("http", "ws"); - public string Url { get; private set; } + public override string Url => _url; public ServerFixture() : this(loggerFactory: null) { @@ -98,7 +110,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests _logger.LogInformation("Test Server started"); // Get the URL from the server - Url = _host.ServerFeatures.Get().Addresses.Single(); + _url = _host.ServerFeatures.Get().Addresses.Single(); _lifetime.ApplicationStopped.Register(() => { @@ -125,7 +137,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests return builder.ToString(); } - public void Dispose() + public override void Dispose() { _logger.LogInformation("Shutting down test server"); _host.Dispose(); diff --git a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/ServerLogScope.cs b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/ServerLogScope.cs index 85ff860600..5faf9674d9 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/ServerLogScope.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/ServerLogScope.cs @@ -6,13 +6,13 @@ using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.SignalR.Tests { - public class ServerLogScope : IDisposable where TStartup : class + public class ServerLogScope : IDisposable { - private readonly ServerFixture _serverFixture; + private readonly ServerFixture _serverFixture; private readonly IDisposable _wrappedDisposable; //private readonly ILogger _logger; - public ServerLogScope(ServerFixture serverFixture, ILoggerFactory loggerFactory, IDisposable wrappedDisposable) + public ServerLogScope(ServerFixture serverFixture, ILoggerFactory loggerFactory, IDisposable wrappedDisposable) { _serverFixture = serverFixture; _wrappedDisposable = wrappedDisposable; diff --git a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/VerifiableServerLoggedTest.cs b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/VerifiableServerLoggedTest.cs index e92eb61d70..44059b3616 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/VerifiableServerLoggedTest.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/VerifiableServerLoggedTest.cs @@ -8,11 +8,11 @@ using Xunit.Abstractions; namespace Microsoft.AspNetCore.SignalR.Tests { - public class VerifiableServerLoggedTest : VerifiableLoggedTest where TStartup : class + public class VerifiableServerLoggedTest : VerifiableLoggedTest { - public ServerFixture ServerFixture { get; } + public ServerFixture ServerFixture { get; } - public VerifiableServerLoggedTest(ServerFixture serverFixture, ITestOutputHelper output) : base(output) + public VerifiableServerLoggedTest(ServerFixture serverFixture, ITestOutputHelper output) : base(output) { ServerFixture = serverFixture; } @@ -20,13 +20,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests public override IDisposable StartVerifableLog(out ILoggerFactory loggerFactory, LogLevel minLogLevel, string testName = null, Func expectedErrorsFilter = null) { var disposable = base.StartVerifableLog(out loggerFactory, minLogLevel, testName, expectedErrorsFilter); - return new ServerLogScope(ServerFixture, loggerFactory, disposable); + return new ServerLogScope(ServerFixture, loggerFactory, disposable); } public override IDisposable StartVerifableLog(out ILoggerFactory loggerFactory, string testName = null, Func expectedErrorsFilter = null) { var disposable = base.StartVerifableLog(out loggerFactory, testName, expectedErrorsFilter); - return new ServerLogScope(ServerFixture, loggerFactory, disposable); + return new ServerLogScope(ServerFixture, loggerFactory, disposable); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs index 168e2e77d8..6aa8e679c2 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests } [Collection(EndToEndTestsCollection.Name)] - public class EndToEndTests : VerifiableServerLoggedTest + public class EndToEndTests : VerifiableServerLoggedTest { private readonly ServerFixture _serverFixture; @@ -44,6 +44,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests { throw new ArgumentNullException(nameof(serverFixture)); } + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } _serverFixture = serverFixture; } diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs index 4f7aaae831..f83452da37 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs @@ -22,7 +22,7 @@ using Xunit.Abstractions; namespace Microsoft.AspNetCore.SignalR.Tests { [Collection(EndToEndTestsCollection.Name)] - public class WebSocketsTransportTests : VerifiableServerLoggedTest + public class WebSocketsTransportTests : VerifiableServerLoggedTest { private readonly ServerFixture _serverFixture;