[SignalR] Move to generic host (#22602)

This commit is contained in:
Brennan 2020-06-23 10:46:03 -07:00 committed by GitHub
parent 6a4d79cfb8
commit a1c226e4f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 306 additions and 255 deletions

View File

@ -16,7 +16,7 @@
<Reference Include="Microsoft.Extensions.DependencyInjection" /> <Reference Include="Microsoft.Extensions.DependencyInjection" />
<Reference Include="Microsoft.Extensions.FileProviders.Physical" /> <Reference Include="Microsoft.Extensions.FileProviders.Physical" />
<Reference Include="Microsoft.Extensions.FileProviders.Composite" /> <Reference Include="Microsoft.Extensions.FileProviders.Composite" />
<Reference Include="Microsoft.Extensions.Hosting.Abstractions" /> <Reference Include="Microsoft.Extensions.Hosting" />
<Reference Include="Microsoft.Extensions.Logging" /> <Reference Include="Microsoft.Extensions.Logging" />
<Reference Include="Microsoft.Extensions.Options" /> <Reference Include="Microsoft.Extensions.Options" />
</ItemGroup> </ItemGroup>

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<Description>ASP.NET Core hosting infrastructure and startup logic for web applications.</Description> <Description>ASP.NET Core hosting infrastructure and startup logic for web applications.</Description>
@ -26,7 +26,7 @@
<Reference Include="Microsoft.Extensions.DependencyInjection" /> <Reference Include="Microsoft.Extensions.DependencyInjection" />
<Reference Include="Microsoft.Extensions.FileProviders.Physical" /> <Reference Include="Microsoft.Extensions.FileProviders.Physical" />
<Reference Include="Microsoft.Extensions.FileProviders.Composite" /> <Reference Include="Microsoft.Extensions.FileProviders.Composite" />
<Reference Include="Microsoft.Extensions.Hosting.Abstractions" /> <Reference Include="Microsoft.Extensions.Hosting" />
<Reference Include="Microsoft.Extensions.Logging" /> <Reference Include="Microsoft.Extensions.Logging" />
<Reference Include="Microsoft.Extensions.Options" /> <Reference Include="Microsoft.Extensions.Options" />

View File

@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CheckFixedMessage(string protocolName, HttpTransportType transportType, string path) public async Task CheckFixedMessage(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connectionBuilder = new HubConnectionBuilder() var connectionBuilder = new HubConnectionBuilder()
.WithLoggerFactory(LoggerFactory) .WithLoggerFactory(LoggerFactory)
@ -125,7 +125,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
} }
var protocol = HubProtocols["json"]; var protocol = HubProtocols["json"];
using (var server = await StartServer<Startup>(ExpectedError)) await using (var server = await StartServer<Startup>(ExpectedError))
{ {
var connectionBuilder = new HubConnectionBuilder() var connectionBuilder = new HubConnectionBuilder()
.WithLoggerFactory(LoggerFactory) .WithLoggerFactory(LoggerFactory)
@ -155,7 +155,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task ClientCanConnectToServerWithLowerMinimumProtocol() public async Task ClientCanConnectToServerWithLowerMinimumProtocol()
{ {
var protocol = HubProtocols["json"]; var protocol = HubProtocols["json"];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connectionBuilder = new HubConnectionBuilder() var connectionBuilder = new HubConnectionBuilder()
.WithLoggerFactory(LoggerFactory) .WithLoggerFactory(LoggerFactory)
@ -185,7 +185,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanSendAndReceiveMessage(string protocolName, HttpTransportType transportType, string path) public async Task CanSendAndReceiveMessage(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
const string originalMessage = "SignalR"; const string originalMessage = "SignalR";
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
@ -214,7 +214,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanSendNull(string protocolName) public async Task CanSendNull(string protocolName)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, "/default", HttpTransportType.LongPolling, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, "/default", HttpTransportType.LongPolling, protocol, LoggerFactory);
try try
@ -243,7 +243,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanStopAndStartConnection(string protocolName, HttpTransportType transportType, string path) public async Task CanStopAndStartConnection(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
const string originalMessage = "SignalR"; const string originalMessage = "SignalR";
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
@ -275,7 +275,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanAccessConnectionIdFromHubConnection(string protocolName, HttpTransportType transportType, string path) public async Task CanAccessConnectionIdFromHubConnection(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try try
@ -310,7 +310,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanStartConnectionFromClosedEvent(string protocolName, HttpTransportType transportType, string path) public async Task CanStartConnectionFromClosedEvent(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var logger = LoggerFactory.CreateLogger<HubConnectionTests>(); var logger = LoggerFactory.CreateLogger<HubConnectionTests>();
const string originalMessage = "SignalR"; const string originalMessage = "SignalR";
@ -372,7 +372,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task MethodsAreCaseInsensitive(string protocolName, HttpTransportType transportType, string path) public async Task MethodsAreCaseInsensitive(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
const string originalMessage = "SignalR"; const string originalMessage = "SignalR";
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
@ -402,7 +402,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanInvokeFromOnHandler(string protocolName, HttpTransportType transportType, string path) public async Task CanInvokeFromOnHandler(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
const string originalMessage = "SignalR"; const string originalMessage = "SignalR";
@ -442,7 +442,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task StreamAsyncCoreTest(string protocolName, HttpTransportType transportType, string path) public async Task StreamAsyncCoreTest(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try try
@ -477,7 +477,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanStreamToHubWithIAsyncEnumerableMethodArg(string protocolName) public async Task CanStreamToHubWithIAsyncEnumerableMethodArg(string protocolName)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, "/default", HttpTransportType.WebSockets, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, "/default", HttpTransportType.WebSockets, protocol, LoggerFactory);
try try
@ -523,7 +523,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task StreamAsyncTest(string protocolName, HttpTransportType transportType, string path) public async Task StreamAsyncTest(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try try
@ -558,7 +558,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task StreamAsyncDoesNotStartIfTokenAlreadyCanceled(string protocolName, HttpTransportType transportType, string path) public async Task StreamAsyncDoesNotStartIfTokenAlreadyCanceled(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try try
@ -595,7 +595,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task StreamAsyncCanBeCanceled(string protocolName, HttpTransportType transportType, string path) public async Task StreamAsyncCanBeCanceled(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try try
@ -643,7 +643,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
} }
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>(ExpectedErrors)) await using (var server = await StartServer<Startup>(ExpectedErrors))
{ {
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try try
@ -679,7 +679,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanInvokeClientMethodFromServer(string protocolName, HttpTransportType transportType, string path) public async Task CanInvokeClientMethodFromServer(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
const string originalMessage = "SignalR"; const string originalMessage = "SignalR";
@ -713,7 +713,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task InvokeNonExistantClientMethodFromServer(string protocolName, HttpTransportType transportType, string path) public async Task InvokeNonExistantClientMethodFromServer(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
var closeTcs = new TaskCompletionSource(); var closeTcs = new TaskCompletionSource();
@ -755,7 +755,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanStreamClientMethodFromServer(string protocolName, HttpTransportType transportType, string path) public async Task CanStreamClientMethodFromServer(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try try
@ -785,7 +785,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanStreamToAndFromClientInSameInvocation(string protocolName, HttpTransportType transportType, string path) public async Task CanStreamToAndFromClientInSameInvocation(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try try
@ -822,7 +822,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanStreamToServerWithIAsyncEnumerable(string protocolName, HttpTransportType transportType, string path) public async Task CanStreamToServerWithIAsyncEnumerable(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try try
@ -869,7 +869,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanCancelIAsyncEnumerableClientToServerUpload(string protocolName, HttpTransportType transportType, string path) public async Task CanCancelIAsyncEnumerableClientToServerUpload(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try try
@ -922,7 +922,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task StreamAsyncCanBeCanceledThroughGetAsyncEnumerator(string protocolName, HttpTransportType transportType, string path) public async Task StreamAsyncCanBeCanceledThroughGetAsyncEnumerator(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try try
@ -963,7 +963,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanCloseStreamMethodEarly(string protocolName, HttpTransportType transportType, string path) public async Task CanCloseStreamMethodEarly(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try try
@ -1004,7 +1004,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task StreamDoesNotStartIfTokenAlreadyCanceled(string protocolName, HttpTransportType transportType, string path) public async Task StreamDoesNotStartIfTokenAlreadyCanceled(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try try
@ -1039,7 +1039,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
} }
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>(ExpectedErrors)) await using (var server = await StartServer<Startup>(ExpectedErrors))
{ {
var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory);
try try
@ -1067,7 +1067,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task ServerThrowsHubExceptionIfHubMethodCannotBeResolved(string hubProtocolName, HttpTransportType transportType, string hubPath) public async Task ServerThrowsHubExceptionIfHubMethodCannotBeResolved(string hubProtocolName, HttpTransportType transportType, string hubPath)
{ {
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try try
@ -1094,7 +1094,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task ServerThrowsHubExceptionIfHubMethodCannotBeResolvedAndArgumentsPassedIn(string hubProtocolName, HttpTransportType transportType, string hubPath) public async Task ServerThrowsHubExceptionIfHubMethodCannotBeResolvedAndArgumentsPassedIn(string hubProtocolName, HttpTransportType transportType, string hubPath)
{ {
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try try
@ -1121,7 +1121,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task ServerThrowsHubExceptionOnHubMethodArgumentCountMismatch(string hubProtocolName) public async Task ServerThrowsHubExceptionOnHubMethodArgumentCountMismatch(string hubProtocolName)
{ {
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, "/default", HttpTransportType.LongPolling, hubProtocol, LoggerFactory); var connection = CreateHubConnection(server.Url, "/default", HttpTransportType.LongPolling, hubProtocol, LoggerFactory);
try try
@ -1148,7 +1148,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task ServerThrowsHubExceptionOnHubMethodArgumentTypeMismatch(string hubProtocolName, HttpTransportType transportType, string hubPath) public async Task ServerThrowsHubExceptionOnHubMethodArgumentTypeMismatch(string hubProtocolName, HttpTransportType transportType, string hubPath)
{ {
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try try
@ -1175,7 +1175,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task ServerThrowsHubExceptionIfStreamingHubMethodCannotBeResolved(string hubProtocolName, HttpTransportType transportType, string hubPath) public async Task ServerThrowsHubExceptionIfStreamingHubMethodCannotBeResolved(string hubProtocolName, HttpTransportType transportType, string hubPath)
{ {
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try try
@ -1203,7 +1203,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task ServerThrowsHubExceptionOnStreamingHubMethodArgumentCountMismatch(string hubProtocolName, HttpTransportType transportType, string hubPath) public async Task ServerThrowsHubExceptionOnStreamingHubMethodArgumentCountMismatch(string hubProtocolName, HttpTransportType transportType, string hubPath)
{ {
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try try
@ -1231,7 +1231,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task ServerThrowsHubExceptionOnStreamingHubMethodArgumentTypeMismatch(string hubProtocolName, HttpTransportType transportType, string hubPath) public async Task ServerThrowsHubExceptionOnStreamingHubMethodArgumentTypeMismatch(string hubProtocolName, HttpTransportType transportType, string hubPath)
{ {
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try try
@ -1259,7 +1259,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task ServerThrowsHubExceptionIfNonStreamMethodInvokedWithStreamAsync(string hubProtocolName, HttpTransportType transportType, string hubPath) public async Task ServerThrowsHubExceptionIfNonStreamMethodInvokedWithStreamAsync(string hubProtocolName, HttpTransportType transportType, string hubPath)
{ {
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try try
@ -1286,7 +1286,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task ServerThrowsHubExceptionIfStreamMethodInvokedWithInvoke(string hubProtocolName, HttpTransportType transportType, string hubPath) public async Task ServerThrowsHubExceptionIfStreamMethodInvokedWithInvoke(string hubProtocolName, HttpTransportType transportType, string hubPath)
{ {
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try try
@ -1313,7 +1313,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task ServerThrowsHubExceptionIfBuildingAsyncEnumeratorIsNotPossible(string hubProtocolName, HttpTransportType transportType, string hubPath) public async Task ServerThrowsHubExceptionIfBuildingAsyncEnumeratorIsNotPossible(string hubProtocolName, HttpTransportType transportType, string hubPath)
{ {
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
try try
@ -1349,7 +1349,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}; };
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>(write => write.EventId.Name == "FailedWritingMessage")) await using (var server = await StartServer<Startup>(write => write.EventId.Name == "FailedWritingMessage"))
{ {
var connection = CreateHubConnection(server.Url, "/default", HttpTransportType.WebSockets, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, "/default", HttpTransportType.WebSockets, protocol, LoggerFactory);
var closedTcs = new TaskCompletionSource<Exception>(TaskCreationOptions.RunContinuationsAsynchronously); var closedTcs = new TaskCompletionSource<Exception>(TaskCreationOptions.RunContinuationsAsynchronously);
@ -1396,7 +1396,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
}; };
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (var server = await StartServer<Startup>(write => write.EventId.Name == "FailedWritingMessage")) await using (var server = await StartServer<Startup>(write => write.EventId.Name == "FailedWritingMessage"))
{ {
var connection = CreateHubConnection(server.Url, "/default", HttpTransportType.LongPolling, protocol, LoggerFactory); var connection = CreateHubConnection(server.Url, "/default", HttpTransportType.LongPolling, protocol, LoggerFactory);
var closedTcs = new TaskCompletionSource<Exception>(TaskCreationOptions.RunContinuationsAsynchronously); var closedTcs = new TaskCompletionSource<Exception>(TaskCreationOptions.RunContinuationsAsynchronously);
@ -1436,7 +1436,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
var hubProtocol = HubProtocols.First().Value; var hubProtocol = HubProtocols.First().Value;
var transportType = TransportTypes().First().Cast<HttpTransportType>().First(); var transportType = TransportTypes().First().Cast<HttpTransportType>().First();
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory); var connection = CreateHubConnection(server.Url, hubPath, transportType, hubProtocol, LoggerFactory);
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
@ -1453,7 +1453,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(TransportTypes))] [MemberData(nameof(TransportTypes))]
public async Task ClientCanUseJwtBearerTokenForAuthentication(HttpTransportType transportType) public async Task ClientCanUseJwtBearerTokenForAuthentication(HttpTransportType transportType)
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
async Task<string> AccessTokenProvider() async Task<string> AccessTokenProvider()
{ {
@ -1496,7 +1496,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
return writeContext.Exception is HttpRequestException; return writeContext.Exception is HttpRequestException;
} }
using (var server = await StartServer<Startup>(ExpectedErrors)) await using (var server = await StartServer<Startup>(ExpectedErrors))
{ {
var hubConnection = new HubConnectionBuilder() var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(LoggerFactory) .WithLoggerFactory(LoggerFactory)
@ -1518,7 +1518,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(TransportTypes))] [MemberData(nameof(TransportTypes))]
public async Task ClientCanUseJwtBearerTokenForAuthenticationWhenRedirected(HttpTransportType transportType) public async Task ClientCanUseJwtBearerTokenForAuthenticationWhenRedirected(HttpTransportType transportType)
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var hubConnection = new HubConnectionBuilder() var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(LoggerFactory) .WithLoggerFactory(LoggerFactory)
@ -1546,7 +1546,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(TransportTypes))] [MemberData(nameof(TransportTypes))]
public async Task ClientCanSendHeaders(HttpTransportType transportType) public async Task ClientCanSendHeaders(HttpTransportType transportType)
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var hubConnection = new HubConnectionBuilder() var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(LoggerFactory) .WithLoggerFactory(LoggerFactory)
@ -1577,7 +1577,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Fact] [Fact]
public async Task UserAgentIsSet() public async Task UserAgentIsSet()
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var hubConnection = new HubConnectionBuilder() var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(LoggerFactory) .WithLoggerFactory(LoggerFactory)
@ -1619,7 +1619,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Fact] [Fact]
public async Task UserAgentCanBeCleared() public async Task UserAgentCanBeCleared()
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var hubConnection = new HubConnectionBuilder() var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(LoggerFactory) .WithLoggerFactory(LoggerFactory)
@ -1654,7 +1654,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Fact] [Fact]
public async Task UserAgentCanBeSet() public async Task UserAgentCanBeSet()
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var hubConnection = new HubConnectionBuilder() var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(LoggerFactory) .WithLoggerFactory(LoggerFactory)
@ -1690,7 +1690,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[WebSocketsSupportedCondition] [WebSocketsSupportedCondition]
public async Task WebSocketOptionsAreApplied() public async Task WebSocketOptionsAreApplied()
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
// System.Net has a HttpTransportType type which means we need to fully-qualify this rather than 'use' the namespace // 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(); var cookieJar = new System.Net.CookieContainer();
@ -1724,7 +1724,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Fact] [Fact]
public async Task CheckHttpConnectionFeatures() public async Task CheckHttpConnectionFeatures()
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var hubConnection = new HubConnectionBuilder() var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(LoggerFactory) .WithLoggerFactory(LoggerFactory)
@ -1760,7 +1760,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Fact] [Fact]
public async Task UserIdProviderCanAccessHttpContext() public async Task UserIdProviderCanAccessHttpContext()
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var hubConnection = new HubConnectionBuilder() var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(LoggerFactory) .WithLoggerFactory(LoggerFactory)
@ -1791,7 +1791,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Fact] [Fact]
public async Task NegotiationSkipsServerSentEventsWhenUsingBinaryProtocol() public async Task NegotiationSkipsServerSentEventsWhenUsingBinaryProtocol()
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var hubConnectionBuilder = new HubConnectionBuilder() var hubConnectionBuilder = new HubConnectionBuilder()
.WithLoggerFactory(LoggerFactory) .WithLoggerFactory(LoggerFactory)
@ -1821,7 +1821,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Fact] [Fact]
public async Task StopCausesPollToReturnImmediately() public async Task StopCausesPollToReturnImmediately()
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
PollTrackingMessageHandler pollTracker = null; PollTrackingMessageHandler pollTracker = null;
var hubConnection = new HubConnectionBuilder() var hubConnection = new HubConnectionBuilder()
@ -1869,7 +1869,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
writeContext.EventId.Name == "ReconnectingWithError"; writeContext.EventId.Name == "ReconnectingWithError";
} }
using (var server = await StartServer<Startup>(ExpectedErrors)) await using (var server = await StartServer<Startup>(ExpectedErrors))
{ {
var connection = CreateHubConnection( var connection = CreateHubConnection(
server.Url, server.Url,
@ -1931,7 +1931,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
writeContext.EventId.Name == "ReconnectingWithError"; writeContext.EventId.Name == "ReconnectingWithError";
} }
using (var server = await StartServer<Startup>(ExpectedErrors)) await using (var server = await StartServer<Startup>(ExpectedErrors))
{ {
var connection = new HubConnectionBuilder() var connection = new HubConnectionBuilder()
.WithLoggerFactory(LoggerFactory) .WithLoggerFactory(LoggerFactory)
@ -1991,7 +1991,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
writeContext.EventId.Name == "ReconnectingWithError"; writeContext.EventId.Name == "ReconnectingWithError";
} }
using (var server = await StartServer<Startup>(ExpectedErrors)) await using (var server = await StartServer<Startup>(ExpectedErrors))
{ {
var connectionBuilder = new HubConnectionBuilder() var connectionBuilder = new HubConnectionBuilder()
.WithLoggerFactory(LoggerFactory) .WithLoggerFactory(LoggerFactory)

View File

@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(TransportTypes))] [MemberData(nameof(TransportTypes))]
public async Task ClientUsingOldCallWithOriginalProtocol(HttpTransportType transportType) public async Task ClientUsingOldCallWithOriginalProtocol(HttpTransportType transportType)
{ {
using (var server = await StartServer<VersionStartup>()) await using (var server = await StartServer<VersionStartup>())
{ {
var connectionBuilder = new HubConnectionBuilder() var connectionBuilder = new HubConnectionBuilder()
.WithLoggerFactory(LoggerFactory) .WithLoggerFactory(LoggerFactory)
@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(TransportTypes))] [MemberData(nameof(TransportTypes))]
public async Task ClientUsingOldCallWithNewProtocol(HttpTransportType transportType) public async Task ClientUsingOldCallWithNewProtocol(HttpTransportType transportType)
{ {
using (var server = await StartServer<VersionStartup>()) await using (var server = await StartServer<VersionStartup>())
{ {
var connectionBuilder = new HubConnectionBuilder() var connectionBuilder = new HubConnectionBuilder()
.WithLoggerFactory(LoggerFactory) .WithLoggerFactory(LoggerFactory)
@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(TransportTypes))] [MemberData(nameof(TransportTypes))]
public async Task ClientUsingNewCallWithNewProtocol(HttpTransportType transportType) public async Task ClientUsingNewCallWithNewProtocol(HttpTransportType transportType)
{ {
using (var server = await StartServer<VersionStartup>()) await using (var server = await StartServer<VersionStartup>())
{ {
var httpConnectionFactory = new HttpConnectionFactory( var httpConnectionFactory = new HttpConnectionFactory(
Options.Create(new HttpConnectionOptions Options.Create(new HttpConnectionOptions
@ -166,7 +166,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
return writeContext.LoggerName == typeof(HubConnection).FullName; return writeContext.LoggerName == typeof(HubConnection).FullName;
} }
using (var server = await StartServer<VersionStartup>(ExpectedErrors)) await using (var server = await StartServer<VersionStartup>(ExpectedErrors))
{ {
var connectionBuilder = new HubConnectionBuilder() var connectionBuilder = new HubConnectionBuilder()
.WithLoggerFactory(LoggerFactory) .WithLoggerFactory(LoggerFactory)

View File

@ -5,7 +5,9 @@ using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Win32; using Microsoft.Win32;
@ -13,7 +15,7 @@ namespace FunctionalTests
{ {
public class Program public class Program
{ {
public static void Main(string[] args) public static Task Main(string[] args)
{ {
string url = null; string url = null;
for (var i = 0; i < args.Length; i++) for (var i = 0; i < args.Length; i++)
@ -27,65 +29,69 @@ namespace FunctionalTests
} }
} }
var hostBuilder = new WebHostBuilder() var hostBuilder = new HostBuilder()
.ConfigureLogging(factory => .ConfigureWebHost(webHostBuilder =>
{ {
factory.AddConsole(options => webHostBuilder
.ConfigureLogging(factory =>
{ {
options.IncludeScopes = true; factory.AddConsole(options =>
options.TimestampFormat = "[HH:mm:ss] ";
options.UseUtcTimestamp = true;
});
factory.AddDebug();
factory.SetMinimumLevel(LogLevel.Debug);
})
.UseKestrel((builderContext, options) =>
{
options.ConfigureHttpsDefaults(httpsOptions =>
{
bool useRSA = false;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{ {
// Detect Win10+ options.IncludeScopes = true;
var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion"); options.TimestampFormat = "[HH:mm:ss] ";
var major = key.GetValue("CurrentMajorVersionNumber") as int?; options.UseUtcTimestamp = true;
var minor = key.GetValue("CurrentMinorVersionNumber") as int?; });
factory.AddDebug();
factory.SetMinimumLevel(LogLevel.Debug);
})
.UseKestrel((builderContext, options) =>
{
options.ConfigureHttpsDefaults(httpsOptions =>
{
bool useRSA = false;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Detect Win10+
var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
var major = key.GetValue("CurrentMajorVersionNumber") as int?;
var minor = key.GetValue("CurrentMinorVersionNumber") as int?;
if (major.HasValue && minor.HasValue) if (major.HasValue && minor.HasValue)
{
useRSA = true;
}
}
else
{ {
useRSA = true; useRSA = true;
} }
}
else
{
useRSA = true;
}
if (useRSA) if (useRSA)
{ {
// RSA cert, won't work on Windows 8.1 & Windows 2012 R2 using HTTP2, and ECC won't work in some Node environments // RSA cert, won't work on Windows 8.1 & Windows 2012 R2 using HTTP2, and ECC won't work in some Node environments
var certPath = Path.Combine(Directory.GetCurrentDirectory(), "testCert.pfx"); var certPath = Path.Combine(Directory.GetCurrentDirectory(), "testCert.pfx");
httpsOptions.ServerCertificate = new X509Certificate2(certPath, "testPassword"); httpsOptions.ServerCertificate = new X509Certificate2(certPath, "testPassword");
} }
else else
{ {
// ECC cert, works on Windows 8.1 & Windows 2012 R2 using HTTP2 // ECC cert, works on Windows 8.1 & Windows 2012 R2 using HTTP2
var certPath = Path.Combine(Directory.GetCurrentDirectory(), "testCertECC.pfx"); var certPath = Path.Combine(Directory.GetCurrentDirectory(), "testCertECC.pfx");
httpsOptions.ServerCertificate = new X509Certificate2(certPath, "testPassword"); httpsOptions.ServerCertificate = new X509Certificate2(certPath, "testPassword");
} }
}); });
}) })
.UseContentRoot(Directory.GetCurrentDirectory()) .UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration() .UseIISIntegration()
.UseStartup<Startup>(); .UseStartup<Startup>();
if (!string.IsNullOrEmpty(url)) if (!string.IsNullOrEmpty(url))
{ {
Console.WriteLine($"Forcing URL to: {url}"); Console.WriteLine($"Forcing URL to: {url}");
hostBuilder.UseUrls(url); webHostBuilder.UseUrls(url);
} }
});
hostBuilder.Build().Run(); return hostBuilder.Build().RunAsync();
} }
} }
} }

View File

@ -13,11 +13,13 @@ using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Cors.Infrastructure; using Microsoft.AspNetCore.Cors.Infrastructure;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.SignalR.Tests; using Microsoft.AspNetCore.SignalR.Tests;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
@ -305,7 +307,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
[WebSocketsSupportedCondition] [WebSocketsSupportedCondition]
public async Task MapConnectionHandlerWithWebSocketSubProtocolSetsProtocol() public async Task MapConnectionHandlerWithWebSocketSubProtocolSetsProtocol()
{ {
var host = BuildWebHost<MyConnectionHandler>("/socket", using var host = BuildWebHost<MyConnectionHandler>("/socket",
options => options.WebSockets.SubProtocolSelector = subprotocols => options => options.WebSockets.SubProtocolSelector = subprotocols =>
{ {
Assert.Equal(new[] { "protocol1", "protocol2" }, subprotocols.ToArray()); Assert.Equal(new[] { "protocol1", "protocol2" }, subprotocols.ToArray());
@ -314,7 +316,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
await host.StartAsync(); await host.StartAsync();
var feature = host.ServerFeatures.Get<IServerAddressesFeature>(); var feature = host.Services.GetService<IServer>().Features.Get<IServerAddressesFeature>();
var address = feature.Addresses.First().Replace("http", "ws") + "/socket"; var address = feature.Addresses.First().Replace("http", "ws") + "/socket";
var client = new ClientWebSocket(); var client = new ClientWebSocket();
@ -377,44 +379,52 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
} }
} }
private IWebHost BuildWebHost(Action<IEndpointRouteBuilder> configure) private IHost BuildWebHost(Action<IEndpointRouteBuilder> configure)
{ {
return new WebHostBuilder() return new HostBuilder()
.UseKestrel() .ConfigureWebHost(webHostBuilder =>
.ConfigureServices(services =>
{ {
services.AddConnections(); webHostBuilder
.UseKestrel()
.ConfigureServices(services =>
{
services.AddConnections();
})
.Configure(app =>
{
app.UseRouting();
app.UseEndpoints(endpoints => configure(endpoints));
})
.UseUrls("http://127.0.0.1:0");
}) })
.Configure(app =>
{
app.UseRouting();
app.UseEndpoints(endpoints => configure(endpoints));
})
.UseUrls("http://127.0.0.1:0")
.Build(); .Build();
} }
private IWebHost BuildWebHost<TConnectionHandler>(string path, Action<HttpConnectionDispatcherOptions> configureOptions) where TConnectionHandler : ConnectionHandler private IHost BuildWebHost<TConnectionHandler>(string path, Action<HttpConnectionDispatcherOptions> configureOptions) where TConnectionHandler : ConnectionHandler
{ {
return new WebHostBuilder() return new HostBuilder()
.UseUrls("http://127.0.0.1:0") .ConfigureWebHost(webHostBuilder =>
.UseKestrel()
.ConfigureServices(services =>
{ {
services.AddConnections(); webHostBuilder
}) .UseUrls("http://127.0.0.1:0")
.Configure(app => .UseKestrel()
{ .ConfigureServices(services =>
app.UseRouting();
app.UseEndpoints(routes =>
{ {
routes.MapConnectionHandler<TConnectionHandler>(path, configureOptions); services.AddConnections();
})
.Configure(app =>
{
app.UseRouting();
app.UseEndpoints(routes =>
{
routes.MapConnectionHandler<TConnectionHandler>(path, configureOptions);
});
})
.ConfigureLogging(factory =>
{
factory.AddXunit(_output, LogLevel.Trace);
}); });
}) })
.ConfigureLogging(factory =>
{
factory.AddXunit(_output, LogLevel.Trace);
})
.Build(); .Build();
} }
} }

View File

@ -9,16 +9,16 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
namespace Microsoft.AspNetCore.SignalR.Tests namespace Microsoft.AspNetCore.SignalR.Tests
{ {
public abstract class InProcessTestServer : IDisposable public abstract class InProcessTestServer : IAsyncDisposable
{ {
internal abstract event Action<LogRecord> ServerLogged; internal abstract event Action<LogRecord> ServerLogged;
@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
public abstract string Url { get; } public abstract string Url { get; }
public abstract void Dispose(); public abstract ValueTask DisposeAsync();
} }
public class InProcessTestServer<TStartup> : InProcessTestServer public class InProcessTestServer<TStartup> : InProcessTestServer
@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
{ {
private readonly ILoggerFactory _loggerFactory; private readonly ILoggerFactory _loggerFactory;
private readonly ILogger _logger; private readonly ILogger _logger;
private IWebHost _host; private IHost _host;
private IHostApplicationLifetime _lifetime; private IHostApplicationLifetime _lifetime;
private readonly IDisposable _logToken; private readonly IDisposable _logToken;
private readonly IDisposable _extraDisposable; private readonly IDisposable _extraDisposable;
@ -91,15 +91,18 @@ namespace Microsoft.AspNetCore.SignalR.Tests
// We're using 127.0.0.1 instead of localhost to ensure that we use IPV4 across different OSes // We're using 127.0.0.1 instead of localhost to ensure that we use IPV4 across different OSes
var url = "http://127.0.0.1:0"; var url = "http://127.0.0.1:0";
_host = new WebHostBuilder() _host = new HostBuilder()
.ConfigureLogging(builder => builder .ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.ConfigureLogging(builder => builder
.SetMinimumLevel(LogLevel.Trace) .SetMinimumLevel(LogLevel.Trace)
.AddProvider(new ForwardingLoggerProvider(_loggerFactory))) .AddProvider(new ForwardingLoggerProvider(_loggerFactory)))
.UseStartup(typeof(TStartup)) .UseStartup(typeof(TStartup))
.UseKestrel() .UseKestrel()
.UseUrls(url) .UseUrls(url)
.UseContentRoot(Directory.GetCurrentDirectory()) .UseContentRoot(Directory.GetCurrentDirectory());
.Build(); }).Build();
_logger.LogInformation("Starting test server..."); _logger.LogInformation("Starting test server...");
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30)); var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
@ -116,7 +119,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
_logger.LogInformation("Test Server started"); _logger.LogInformation("Test Server started");
// Get the URL from the server // Get the URL from the server
_url = _host.ServerFeatures.Get<IServerAddressesFeature>().Addresses.Single(); _url = _host.Services.GetService<IServer>().Features.Get<IServerAddressesFeature>().Addresses.Single();
_lifetime = _host.Services.GetRequiredService<IHostApplicationLifetime>(); _lifetime = _host.Services.GetRequiredService<IHostApplicationLifetime>();
_lifetime.ApplicationStopped.Register(() => _lifetime.ApplicationStopped.Register(() =>
@ -144,12 +147,19 @@ namespace Microsoft.AspNetCore.SignalR.Tests
return builder.ToString(); return builder.ToString();
} }
public override void Dispose() public override async ValueTask DisposeAsync()
{ {
_extraDisposable?.Dispose(); try
_logger.LogInformation("Shutting down test server"); {
_host.Dispose(); _extraDisposable?.Dispose();
_loggerFactory.Dispose(); _logger.LogInformation("Start shutting down test server");
}
finally
{
await _host.StopAsync();
_host.Dispose();
_loggerFactory.Dispose();
}
} }
private class ForwardingLoggerProvider : ILoggerProvider private class ForwardingLoggerProvider : ILoggerProvider

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> <TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> <TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>

View File

@ -1,29 +1,35 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO; using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace JwtSample namespace JwtSample
{ {
public class Program public class Program
{ {
public static void Main(string[] args) public static Task Main(string[] args)
{ {
new WebHostBuilder() return Host.CreateDefaultBuilder(args)
.ConfigureLogging(factory => .ConfigureWebHost(webHostBuilder =>
{ {
factory.AddConsole(); webHostBuilder
factory.AddFilter("Console", level => level >= LogLevel.Information); .ConfigureLogging(factory =>
factory.AddDebug(); {
factory.AddConsole();
factory.AddFilter("Console", level => level >= LogLevel.Information);
factory.AddDebug();
})
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>();
}) })
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build() .Build()
.Run(); .RunAsync();
} }
} }
} }

View File

@ -3,9 +3,11 @@
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SignalRSamples.Hubs; using SignalRSamples.Hubs;
@ -13,36 +15,40 @@ namespace SignalRSamples
{ {
public class Program public class Program
{ {
public static void Main(string[] args) public static Task Main(string[] args)
{ {
var config = new ConfigurationBuilder() var config = new ConfigurationBuilder()
.AddCommandLine(args) .AddCommandLine(args)
.Build(); .Build();
var host = new WebHostBuilder() var host = Host.CreateDefaultBuilder(args)
.UseConfiguration(config) .ConfigureWebHost(webHostBuilder =>
.UseSetting(WebHostDefaults.PreventHostingStartupKey, "true")
.ConfigureLogging(factory =>
{ {
factory.AddConsole(); webHostBuilder
}) .UseConfiguration(config)
.UseKestrel(options => .UseSetting(WebHostDefaults.PreventHostingStartupKey, "true")
{ .ConfigureLogging((c, factory) =>
// Default port
options.ListenLocalhost(5000);
// Hub bound to TCP end point
options.Listen(IPAddress.Any, 9001, builder =>
{ {
builder.UseHub<Chat>(); factory.AddConfiguration(c.Configuration.GetSection("Logging"));
}); factory.AddConsole();
}) })
.UseContentRoot(Directory.GetCurrentDirectory()) .UseKestrel(options =>
.UseIISIntegration() {
.UseStartup<Startup>() // Default port
.Build(); options.ListenLocalhost(5000);
host.Run(); // Hub bound to TCP end point
options.Listen(IPAddress.Any, 9001, builder =>
{
builder.UseHub<Chat>();
});
})
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>();
}).Build();
return host.RunAsync();
} }
} }
} }

View File

@ -2,29 +2,35 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO; using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace SocialWeather namespace SocialWeather
{ {
public class Program public class Program
{ {
public static void Main(string[] args) public static Task Main(string[] args)
{ {
var host = new WebHostBuilder() var host = Host.CreateDefaultBuilder(args)
.UseSetting(WebHostDefaults.PreventHostingStartupKey, "true") .ConfigureWebHost(webHostBuilder =>
.ConfigureLogging(factory =>
{ {
factory.AddConsole(); webHostBuilder
factory.AddFilter("Console", level => level >= LogLevel.Information); .UseSetting(WebHostDefaults.PreventHostingStartupKey, "true")
.ConfigureLogging(factory =>
{
factory.AddConsole();
factory.AddFilter("Console", level => level >= LogLevel.Information);
})
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>();
}) })
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build(); .Build();
host.Run(); return host.RunAsync();
} }
} }
} }

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> <TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>

View File

@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[Fact] [Fact]
public async Task CanStartAndStopConnectionUsingDefaultTransport() public async Task CanStartAndStopConnectionUsingDefaultTransport()
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var url = server.Url + "/echo"; var url = server.Url + "/echo";
// The test should connect to the server using WebSockets transport on Windows 8 and newer. // The test should connect to the server using WebSockets transport on Windows 8 and newer.
@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
writeContext.EventId.Name == "ErrorStartingTransport"; writeContext.EventId.Name == "ErrorStartingTransport";
} }
using (var server = await StartServer<Startup>(expectedErrorsFilter: ExpectedErrors)) await using (var server = await StartServer<Startup>(expectedErrorsFilter: ExpectedErrors))
{ {
var url = server.Url + "/echo"; var url = server.Url + "/echo";
// The test should connect to the server using WebSockets transport on Windows 8 and newer. // The test should connect to the server using WebSockets transport on Windows 8 and newer.
@ -74,7 +74,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[LogLevel(LogLevel.Trace)] [LogLevel(LogLevel.Trace)]
public async Task CanStartAndStopConnectionUsingGivenTransport(HttpTransportType transportType) public async Task CanStartAndStopConnectionUsingGivenTransport(HttpTransportType transportType)
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var url = server.Url + "/echo"; var url = server.Url + "/echo";
var connection = new HttpConnection(new HttpConnectionOptions { Url = new Uri(url), Transports = transportType, DefaultTransferFormat = TransferFormat.Text }, LoggerFactory); var connection = new HttpConnection(new HttpConnectionOptions { Url = new Uri(url), Transports = transportType, DefaultTransferFormat = TransferFormat.Text }, LoggerFactory);
@ -87,7 +87,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition] [WebSocketsSupportedCondition]
public async Task WebSocketsTest() public async Task WebSocketsTest()
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var logger = LoggerFactory.CreateLogger<EndToEndTests>(); var logger = LoggerFactory.CreateLogger<EndToEndTests>();
@ -125,7 +125,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition] [WebSocketsSupportedCondition]
public async Task WebSocketsReceivesAndSendsPartialFramesTest() public async Task WebSocketsReceivesAndSendsPartialFramesTest()
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var logger = LoggerFactory.CreateLogger<EndToEndTests>(); var logger = LoggerFactory.CreateLogger<EndToEndTests>();
@ -164,7 +164,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition] [WebSocketsSupportedCondition]
public async Task HttpRequestsNotSentWhenWebSocketsTransportRequestedAndSkipNegotiationSet() public async Task HttpRequestsNotSentWhenWebSocketsTransportRequestedAndSkipNegotiationSet()
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var logger = LoggerFactory.CreateLogger<EndToEndTests>(); var logger = LoggerFactory.CreateLogger<EndToEndTests>();
var url = server.Url + "/echo"; var url = server.Url + "/echo";
@ -214,7 +214,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[InlineData(HttpTransportType.ServerSentEvents)] [InlineData(HttpTransportType.ServerSentEvents)]
public async Task HttpConnectionThrowsIfSkipNegotiationSetAndTransportIsNotWebSockets(HttpTransportType transportType) public async Task HttpConnectionThrowsIfSkipNegotiationSetAndTransportIsNotWebSockets(HttpTransportType transportType)
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var logger = LoggerFactory.CreateLogger<EndToEndTests>(); var logger = LoggerFactory.CreateLogger<EndToEndTests>();
var url = server.Url + "/echo"; var url = server.Url + "/echo";
@ -257,7 +257,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[LogLevel(LogLevel.Trace)] [LogLevel(LogLevel.Trace)]
public async Task ConnectionCanSendAndReceiveMessages(HttpTransportType transportType, TransferFormat requestedTransferFormat) public async Task ConnectionCanSendAndReceiveMessages(HttpTransportType transportType, TransferFormat requestedTransferFormat)
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var logger = LoggerFactory.CreateLogger<EndToEndTests>(); var logger = LoggerFactory.CreateLogger<EndToEndTests>();
@ -315,7 +315,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
public async Task ConnectionCanSendAndReceiveDifferentMessageSizesWebSocketsTransport(int length) public async Task ConnectionCanSendAndReceiveDifferentMessageSizesWebSocketsTransport(int length)
{ {
var message = new string('A', length); var message = new string('A', length);
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var logger = LoggerFactory.CreateLogger<EndToEndTests>(); var logger = LoggerFactory.CreateLogger<EndToEndTests>();
@ -379,7 +379,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
writeContext.EventId.Name == "ErrorWithNegotiation"; writeContext.EventId.Name == "ErrorWithNegotiation";
} }
using (var server = await StartServer<Startup>(ExpectedErrors)) await using (var server = await StartServer<Startup>(ExpectedErrors))
{ {
var logger = LoggerFactory.CreateLogger<EndToEndTests>(); var logger = LoggerFactory.CreateLogger<EndToEndTests>();
@ -403,7 +403,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
writeContext.EventId.Name == "ErrorStartingTransport"; writeContext.EventId.Name == "ErrorStartingTransport";
} }
using (var server = await StartServer<Startup>(ExpectedErrors)) await using (var server = await StartServer<Startup>(ExpectedErrors))
{ {
var logger = LoggerFactory.CreateLogger<EndToEndTests>(); var logger = LoggerFactory.CreateLogger<EndToEndTests>();
@ -433,7 +433,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
writeContext.EventId.Name == "ErrorWithNegotiation"; writeContext.EventId.Name == "ErrorWithNegotiation";
} }
using (var server = await StartServer<Startup>(ExpectedErrors)) await using (var server = await StartServer<Startup>(ExpectedErrors))
{ {
var logger = LoggerFactory.CreateLogger<EndToEndTests>(); var logger = LoggerFactory.CreateLogger<EndToEndTests>();
@ -469,7 +469,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
writeContext.EventId.Name == "ErrorWithNegotiation"; writeContext.EventId.Name == "ErrorWithNegotiation";
} }
using (var server = await StartServer<Startup>(ExpectedErrors)) await using (var server = await StartServer<Startup>(ExpectedErrors))
{ {
var logger = LoggerFactory.CreateLogger<EndToEndTests>(); var logger = LoggerFactory.CreateLogger<EndToEndTests>();
@ -539,7 +539,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
private async Task ServerClosesConnectionWithErrorIfHubCannotBeCreated(HttpTransportType transportType) private async Task ServerClosesConnectionWithErrorIfHubCannotBeCreated(HttpTransportType transportType)
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var logger = LoggerFactory.CreateLogger<EndToEndTests>(); var logger = LoggerFactory.CreateLogger<EndToEndTests>();
@ -604,7 +604,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
writeContext.EventId.Name == "ErrorWithNegotiation"; writeContext.EventId.Name == "ErrorWithNegotiation";
} }
using (var server = await StartServer<Startup>(ExpectedErrors)) await using (var server = await StartServer<Startup>(ExpectedErrors))
{ {
var logger = LoggerFactory.CreateLogger<EndToEndTests>(); var logger = LoggerFactory.CreateLogger<EndToEndTests>();
@ -643,7 +643,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
writeContext.EventId.Name == "ErrorWithNegotiation"; writeContext.EventId.Name == "ErrorWithNegotiation";
} }
using (var server = await StartServer<Startup>(ExpectedErrors)) await using (var server = await StartServer<Startup>(ExpectedErrors))
{ {
var logger = LoggerFactory.CreateLogger<EndToEndTests>(); var logger = LoggerFactory.CreateLogger<EndToEndTests>();

View File

@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http.Connections; using Microsoft.AspNetCore.Http.Connections;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.SignalR.Tests namespace Microsoft.AspNetCore.SignalR.Tests
@ -29,9 +30,11 @@ namespace Microsoft.AspNetCore.SignalR.Tests
public void NotAddingSignalRServiceThrows() public void NotAddingSignalRServiceThrows()
{ {
var executedConfigure = false; var executedConfigure = false;
var builder = new WebHostBuilder(); var builder = new HostBuilder();
builder builder.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseKestrel() .UseKestrel()
.ConfigureServices(services => .ConfigureServices(services =>
{ {
@ -54,6 +57,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
"'IServiceCollection.AddSignalR' inside the call to 'ConfigureServices(...)' in the application startup code.", ex.Message); "'IServiceCollection.AddSignalR' inside the call to 'ConfigureServices(...)' in the application startup code.", ex.Message);
}) })
.UseUrls("http://127.0.0.1:0"); .UseUrls("http://127.0.0.1:0");
});
using (var host = builder.Build()) using (var host = builder.Build())
{ {
@ -338,20 +342,24 @@ namespace Microsoft.AspNetCore.SignalR.Tests
{ {
} }
private IWebHost BuildWebHost(Action<IEndpointRouteBuilder> configure) private IHost BuildWebHost(Action<IEndpointRouteBuilder> configure)
{ {
return new WebHostBuilder() return new HostBuilder()
.UseKestrel() .ConfigureWebHost(webHostBuilder =>
.ConfigureServices(services =>
{ {
services.AddSignalR(); webHostBuilder
.UseKestrel()
.ConfigureServices(services =>
{
services.AddSignalR();
})
.Configure(app =>
{
app.UseRouting();
app.UseEndpoints(endpoints => configure(endpoints));
})
.UseUrls("http://127.0.0.1:0");
}) })
.Configure(app =>
{
app.UseRouting();
app.UseEndpoints(endpoints => configure(endpoints));
})
.UseUrls("http://127.0.0.1:0")
.Build(); .Build();
} }
} }

View File

@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition] [WebSocketsSupportedCondition]
public async Task WebSocketsTransportStopsSendAndReceiveLoopsWhenTransportIsStopped() public async Task WebSocketsTransportStopsSendAndReceiveLoopsWhenTransportIsStopped()
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
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"), await webSocketsTransport.StartAsync(new Uri(server.WebSocketsUrl + "/echo"),
@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition] [WebSocketsSupportedCondition]
public async Task WebSocketsTransportSendsUserAgent() public async Task WebSocketsTransportSendsUserAgent()
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
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"), await webSocketsTransport.StartAsync(new Uri(server.WebSocketsUrl + "/httpheader"),
@ -98,7 +98,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition] [WebSocketsSupportedCondition]
public async Task WebSocketsTransportSendsXRequestedWithHeader() public async Task WebSocketsTransportSendsXRequestedWithHeader()
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
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"), await webSocketsTransport.StartAsync(new Uri(server.WebSocketsUrl + "/httpheader"),
@ -121,7 +121,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition] [WebSocketsSupportedCondition]
public async Task WebSocketsTransportStopsWhenConnectionChannelClosed() public async Task WebSocketsTransportStopsWhenConnectionChannelClosed()
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
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"), await webSocketsTransport.StartAsync(new Uri(server.WebSocketsUrl + "/echo"),
@ -137,7 +137,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[InlineData(TransferFormat.Binary)] [InlineData(TransferFormat.Binary)]
public async Task WebSocketsTransportStopsWhenConnectionClosedByTheServer(TransferFormat transferFormat) public async Task WebSocketsTransportStopsWhenConnectionClosedByTheServer(TransferFormat transferFormat)
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
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.StartAsync(new Uri(server.WebSocketsUrl + "/echoAndClose"), transferFormat);
@ -159,7 +159,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[InlineData(TransferFormat.Binary)] [InlineData(TransferFormat.Binary)]
public async Task WebSocketsTransportSetsTransferFormat(TransferFormat transferFormat) public async Task WebSocketsTransportSetsTransferFormat(TransferFormat transferFormat)
{ {
using (var server = await StartServer<Startup>()) await using (var server = await StartServer<Startup>())
{ {
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: LoggerFactory, accessTokenProvider: null); var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: LoggerFactory, accessTokenProvider: null);

View File

@ -6,12 +6,11 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR.Tests; using Microsoft.AspNetCore.SignalR.Tests;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
{ {
public class RedisServerFixture<TStartup> : IAsyncLifetime, IDisposable public class RedisServerFixture<TStartup> : IAsyncLifetime
where TStartup : class where TStartup : class
{ {
public InProcessTestServer<TStartup> FirstServer { get; private set; } public InProcessTestServer<TStartup> FirstServer { get; private set; }
@ -37,13 +36,24 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
Docker.Default.Start(_logger); Docker.Default.Start(_logger);
} }
public Task DisposeAsync() public async Task DisposeAsync()
{ {
return Task.CompletedTask; if (Docker.Default != null)
{
await FirstServer.DisposeAsync();
await SecondServer.DisposeAsync();
Docker.Default.Stop(_logger);
_logToken.Dispose();
}
} }
public async Task InitializeAsync() public async Task InitializeAsync()
{ {
if (Docker.Default == null)
{
return;
}
FirstServer = await StartServer(); FirstServer = await StartServer();
SecondServer = await StartServer(); SecondServer = await StartServer();
} }
@ -60,16 +70,5 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
throw; throw;
} }
} }
public void Dispose()
{
if (Docker.Default != null)
{
FirstServer.Dispose();
SecondServer.Dispose();
Docker.Default.Stop(_logger);
_logToken.Dispose();
}
}
} }
} }