How about this?
This commit is contained in:
parent
05739820d2
commit
585bcc3ee0
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
|||
}
|
||||
|
||||
[Collection(HubConnectionTestsCollection.Name)]
|
||||
public class HubConnectionTests : VerifiableServerLoggedTest<Startup>
|
||||
public class HubConnectionTests : VerifiableServerLoggedTest
|
||||
{
|
||||
private readonly ServerFixture<Startup> _serverFixture;
|
||||
public HubConnectionTests(ServerFixture<Startup> serverFixture, ITestOutputHelper output) : base(serverFixture, output)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,18 @@ using Microsoft.Extensions.Logging.Testing;
|
|||
|
||||
namespace Microsoft.AspNetCore.SignalR.Tests
|
||||
{
|
||||
public class ServerFixture<TStartup> : IDisposable
|
||||
public abstract class ServerFixture : IDisposable
|
||||
{
|
||||
internal abstract event Action<LogRecord> ServerLogged;
|
||||
|
||||
public abstract string WebSocketsUrl { get; }
|
||||
|
||||
public abstract string Url { get; }
|
||||
|
||||
public abstract void Dispose();
|
||||
}
|
||||
|
||||
public class ServerFixture<TStartup> : 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<LogRecord> ServerLogged
|
||||
internal override event Action<LogRecord> 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<IServerAddressesFeature>().Addresses.Single();
|
||||
_url = _host.ServerFeatures.Get<IServerAddressesFeature>().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();
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ using Microsoft.Extensions.Logging;
|
|||
|
||||
namespace Microsoft.AspNetCore.SignalR.Tests
|
||||
{
|
||||
public class ServerLogScope<TStartup> : IDisposable where TStartup : class
|
||||
public class ServerLogScope : IDisposable
|
||||
{
|
||||
private readonly ServerFixture<TStartup> _serverFixture;
|
||||
private readonly ServerFixture _serverFixture;
|
||||
private readonly IDisposable _wrappedDisposable;
|
||||
//private readonly ILogger _logger;
|
||||
|
||||
public ServerLogScope(ServerFixture<TStartup> serverFixture, ILoggerFactory loggerFactory, IDisposable wrappedDisposable)
|
||||
public ServerLogScope(ServerFixture serverFixture, ILoggerFactory loggerFactory, IDisposable wrappedDisposable)
|
||||
{
|
||||
_serverFixture = serverFixture;
|
||||
_wrappedDisposable = wrappedDisposable;
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@ using Xunit.Abstractions;
|
|||
|
||||
namespace Microsoft.AspNetCore.SignalR.Tests
|
||||
{
|
||||
public class VerifiableServerLoggedTest<TStartup> : VerifiableLoggedTest where TStartup : class
|
||||
public class VerifiableServerLoggedTest : VerifiableLoggedTest
|
||||
{
|
||||
public ServerFixture<TStartup> ServerFixture { get; }
|
||||
public ServerFixture ServerFixture { get; }
|
||||
|
||||
public VerifiableServerLoggedTest(ServerFixture<TStartup> 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<WriteContext, bool> expectedErrorsFilter = null)
|
||||
{
|
||||
var disposable = base.StartVerifableLog(out loggerFactory, minLogLevel, testName, expectedErrorsFilter);
|
||||
return new ServerLogScope<TStartup>(ServerFixture, loggerFactory, disposable);
|
||||
return new ServerLogScope(ServerFixture, loggerFactory, disposable);
|
||||
}
|
||||
|
||||
public override IDisposable StartVerifableLog(out ILoggerFactory loggerFactory, string testName = null, Func<WriteContext, bool> expectedErrorsFilter = null)
|
||||
{
|
||||
var disposable = base.StartVerifableLog(out loggerFactory, testName, expectedErrorsFilter);
|
||||
return new ServerLogScope<TStartup>(ServerFixture, loggerFactory, disposable);
|
||||
return new ServerLogScope(ServerFixture, loggerFactory, disposable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
}
|
||||
|
||||
[Collection(EndToEndTestsCollection.Name)]
|
||||
public class EndToEndTests : VerifiableServerLoggedTest<Startup>
|
||||
public class EndToEndTests : VerifiableServerLoggedTest
|
||||
{
|
||||
private readonly ServerFixture<Startup> _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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ using Xunit.Abstractions;
|
|||
namespace Microsoft.AspNetCore.SignalR.Tests
|
||||
{
|
||||
[Collection(EndToEndTestsCollection.Name)]
|
||||
public class WebSocketsTransportTests : VerifiableServerLoggedTest<Startup>
|
||||
public class WebSocketsTransportTests : VerifiableServerLoggedTest
|
||||
{
|
||||
private readonly ServerFixture<Startup> _serverFixture;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue