diff --git a/src/Analyzers/Analyzers/src/StartupFacts.cs b/src/Analyzers/Analyzers/src/StartupFacts.cs index 221e3ff4c4d3..f5f833429a69 100644 --- a/src/Analyzers/Analyzers/src/StartupFacts.cs +++ b/src/Analyzers/Analyzers/src/StartupFacts.cs @@ -138,6 +138,8 @@ public static bool IsSignalRConfigureMethodGesture(IMethodSymbol symbol) throw new ArgumentNullException(nameof(symbol)); } + // UseSignalR has been removed in 5.0, but we should probably still check for it in this analyzer in case the user + // installs it into a pre-5.0 app. if (string.Equals(symbol.Name, SymbolNames.SignalRAppBuilderExtensions.UseSignalRMethodName, StringComparison.Ordinal) || string.Equals(symbol.Name, SymbolNames.HubEndpointRouteBuilderExtensions.MapHubMethodName, StringComparison.Ordinal) || string.Equals(symbol.Name, SymbolNames.ComponentEndpointRouteBuilderExtensions.MapBlazorHubMethodName, StringComparison.Ordinal)) diff --git a/src/Analyzers/Analyzers/test/CompilationFeatureDetectorTest.cs b/src/Analyzers/Analyzers/test/CompilationFeatureDetectorTest.cs index 0669c7646462..9fcc0ff16750 100644 --- a/src/Analyzers/Analyzers/test/CompilationFeatureDetectorTest.cs +++ b/src/Analyzers/Analyzers/test/CompilationFeatureDetectorTest.cs @@ -29,7 +29,6 @@ public async Task DetectFeaturesAsync_FindsNoFeatures() } [Theory] - [InlineData(nameof(StartupWithUseSignalR))] [InlineData(nameof(StartupWithMapHub))] [InlineData(nameof(StartupWithMapBlazorHub))] public async Task DetectFeaturesAsync_FindsSignalR(string source) diff --git a/src/Analyzers/Analyzers/test/TestFiles/CompilationFeatureDetectorTest/StartupWithUseSignalR.cs b/src/Analyzers/Analyzers/test/TestFiles/CompilationFeatureDetectorTest/StartupWithUseSignalR.cs deleted file mode 100644 index aa65f832580a..000000000000 --- a/src/Analyzers/Analyzers/test/TestFiles/CompilationFeatureDetectorTest/StartupWithUseSignalR.cs +++ /dev/null @@ -1,20 +0,0 @@ -// 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. - -using Microsoft.AspNetCore.Builder; - -namespace Microsoft.AspNetCore.Analyzers.TestFiles.CompilationFeatureDetectorTest -{ - public class StartupWithUseSignalR - { - public void Configure(IApplicationBuilder app) - { -#pragma warning disable CS0618 // Type or member is obsolete - app.UseSignalR(routes => - { - - }); -#pragma warning restore CS0618 // Type or member is obsolete - } - } -} diff --git a/src/SignalR/common/Http.Connections/ref/Microsoft.AspNetCore.Http.Connections.netcoreapp.cs b/src/SignalR/common/Http.Connections/ref/Microsoft.AspNetCore.Http.Connections.netcoreapp.cs index 9f70e9da9c1f..130b8a4a42d6 100644 --- a/src/SignalR/common/Http.Connections/ref/Microsoft.AspNetCore.Http.Connections.netcoreapp.cs +++ b/src/SignalR/common/Http.Connections/ref/Microsoft.AspNetCore.Http.Connections.netcoreapp.cs @@ -15,11 +15,6 @@ public static partial class ConnectionEndpointRouteBuilderExtensions public static Microsoft.AspNetCore.Builder.ConnectionEndpointRouteBuilder MapConnections(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern, Microsoft.AspNetCore.Http.Connections.HttpConnectionDispatcherOptions options, System.Action configure) { throw null; } public static Microsoft.AspNetCore.Builder.ConnectionEndpointRouteBuilder MapConnections(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern, System.Action configure) { throw null; } } - public static partial class ConnectionsAppBuilderExtensions - { - [System.ObsoleteAttribute("This method is obsolete and will be removed in a future version. The recommended alternative is to use MapConnections or MapConnectionHandler inside Microsoft.AspNetCore.Builder.UseEndpoints(...).")] - public static Microsoft.AspNetCore.Builder.IApplicationBuilder UseConnections(this Microsoft.AspNetCore.Builder.IApplicationBuilder app, System.Action configure) { throw null; } - } } namespace Microsoft.AspNetCore.Http.Connections { @@ -34,15 +29,6 @@ public partial class ConnectionOptionsSetup : Microsoft.Extensions.Options.IConf public ConnectionOptionsSetup() { } public void Configure(Microsoft.AspNetCore.Http.Connections.ConnectionOptions options) { } } - [System.ObsoleteAttribute("This class is obsolete and will be removed in a future version. The recommended alternative is to use MapConnection and MapConnectionHandler inside Microsoft.AspNetCore.Builder.UseEndpoints(...).")] - public partial class ConnectionsRouteBuilder - { - internal ConnectionsRouteBuilder() { } - public void MapConnectionHandler(Microsoft.AspNetCore.Http.PathString path) where TConnectionHandler : Microsoft.AspNetCore.Connections.ConnectionHandler { } - public void MapConnectionHandler(Microsoft.AspNetCore.Http.PathString path, System.Action configureOptions) where TConnectionHandler : Microsoft.AspNetCore.Connections.ConnectionHandler { } - public void MapConnections(Microsoft.AspNetCore.Http.PathString path, Microsoft.AspNetCore.Http.Connections.HttpConnectionDispatcherOptions options, System.Action configure) { } - public void MapConnections(Microsoft.AspNetCore.Http.PathString path, System.Action configure) { } - } public static partial class HttpConnectionContextExtensions { public static Microsoft.AspNetCore.Http.HttpContext GetHttpContext(this Microsoft.AspNetCore.Connections.ConnectionContext connection) { throw null; } diff --git a/src/SignalR/common/Http.Connections/src/ConnectionsAppBuilderExtensions.cs b/src/SignalR/common/Http.Connections/src/ConnectionsAppBuilderExtensions.cs deleted file mode 100644 index 05227d6f3963..000000000000 --- a/src/SignalR/common/Http.Connections/src/ConnectionsAppBuilderExtensions.cs +++ /dev/null @@ -1,42 +0,0 @@ -// 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. - -using System; -using Microsoft.AspNetCore.Http.Connections; - -namespace Microsoft.AspNetCore.Builder -{ - /// - /// Extension methods for . - /// - public static class ConnectionsAppBuilderExtensions - { - /// - /// Adds support for ASP.NET Core Connection Handlers to the request execution pipeline. - /// - /// This method is obsolete and will be removed in a future version. - /// The recommended alternative is to use MapConnections or MapConnectionHandler<TConnectionHandler> inside Microsoft.AspNetCore.Builder.UseEndpoints(...). - /// - /// - /// The . - /// A callback to configure connection routes. - /// The same instance of the for chaining. - [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to use MapConnections or MapConnectionHandler inside Microsoft.AspNetCore.Builder.UseEndpoints(...).")] - public static IApplicationBuilder UseConnections(this IApplicationBuilder app, Action configure) - { - if (configure == null) - { - throw new ArgumentNullException(nameof(configure)); - } - - app.UseWebSockets(); - app.UseRouting(); - app.UseAuthorization(); - app.UseEndpoints(endpoints => - { - configure(new ConnectionsRouteBuilder(endpoints)); - }); - return app; - } - } -} diff --git a/src/SignalR/common/Http.Connections/src/ConnectionsRouteBuilder.cs b/src/SignalR/common/Http.Connections/src/ConnectionsRouteBuilder.cs deleted file mode 100644 index b76d5688f065..000000000000 --- a/src/SignalR/common/Http.Connections/src/ConnectionsRouteBuilder.cs +++ /dev/null @@ -1,62 +0,0 @@ -// 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. - -using System; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Connections; -using Microsoft.AspNetCore.Routing; - -namespace Microsoft.AspNetCore.Http.Connections -{ - /// - /// Maps routes to ASP.NET Core Connection Handlers. - /// - /// This class is obsolete and will be removed in a future version. - /// The recommended alternative is to use MapConnection and MapConnectionHandler<TConnectionHandler> inside Microsoft.AspNetCore.Builder.UseEndpoints(...). - /// - /// - [Obsolete("This class is obsolete and will be removed in a future version. The recommended alternative is to use MapConnection and MapConnectionHandler inside Microsoft.AspNetCore.Builder.UseEndpoints(...).")] - public class ConnectionsRouteBuilder - { - private readonly IEndpointRouteBuilder _endpoints; - - internal ConnectionsRouteBuilder(IEndpointRouteBuilder endpoints) - { - _endpoints = endpoints; - } - - /// - /// Maps incoming requests with the specified path to the provided connection pipeline. - /// - /// The request path. - /// A callback to configure the connection. - public void MapConnections(PathString path, Action configure) => - MapConnections(path, new HttpConnectionDispatcherOptions(), configure); - - /// - /// Maps incoming requests with the specified path to the provided connection pipeline. - /// - /// The request path. - /// Options used to configure the connection. - /// A callback to configure the connection. - public void MapConnections(PathString path, HttpConnectionDispatcherOptions options, Action configure) => - _endpoints.MapConnections(path, options, configure); - - /// - /// Maps incoming requests with the specified path to the provided connection pipeline. - /// - /// The type. - /// The request path. - public void MapConnectionHandler(PathString path) where TConnectionHandler : ConnectionHandler => - MapConnectionHandler(path, configureOptions: null); - - /// - /// Maps incoming requests with the specified path to the provided connection pipeline. - /// - /// The type. - /// The request path. - /// A callback to configure dispatcher options. - public void MapConnectionHandler(PathString path, Action configureOptions) where TConnectionHandler : ConnectionHandler => - _endpoints.MapConnectionHandler(path, configureOptions); - } -} diff --git a/src/SignalR/common/Http.Connections/test/MapConnectionHandlerTests.cs b/src/SignalR/common/Http.Connections/test/MapConnectionHandlerTests.cs index 68e086c560c2..d603c0d0830c 100644 --- a/src/SignalR/common/Http.Connections/test/MapConnectionHandlerTests.cs +++ b/src/SignalR/common/Http.Connections/test/MapConnectionHandlerTests.cs @@ -150,10 +150,10 @@ public void MapConnectionHandlerFindsAttributesFromEndPointAndOptions() public void MapConnectionHandlerEndPointRoutingFindsAttributesOnHub() { var authCount = 0; - using (var host = BuildWebHostWithEndPointRouting(routes => routes.MapConnectionHandler("/path", options => + using (var host = BuildWebHost("/path", options => { authCount += options.AuthorizationData.Count; - }))) + })) { host.Start(); @@ -179,11 +179,11 @@ public void MapConnectionHandlerEndPointRoutingFindsAttributesOnHub() public void MapConnectionHandlerEndPointRoutingFindsAttributesFromOptions() { var authCount = 0; - using (var host = BuildWebHostWithEndPointRouting(routes => routes.MapConnectionHandler("/path", options => + using (var host = BuildWebHost("/path", options => { authCount += options.AuthorizationData.Count; options.AuthorizationData.Add(new AuthorizeAttribute()); - }))) + })) { host.Start(); @@ -215,7 +215,7 @@ void ConfigureRoutes(IEndpointRouteBuilder endpoints) .RequireAuthorization(new AuthorizeAttribute("Foo")); } - using (var host = BuildWebHostWithEndPointRouting(ConfigureRoutes)) + using (var host = BuildWebHost(ConfigureRoutes)) { host.Start(); @@ -253,7 +253,7 @@ void ConfigureRoutes(IEndpointRouteBuilder endpoints) endpoints.MapConnectionHandler("/path"); } - using (var host = BuildWebHostWithEndPointRouting(ConfigureRoutes)) + using (var host = BuildWebHost(ConfigureRoutes)) { host.Start(); @@ -281,7 +281,7 @@ void ConfigureRoutes(IEndpointRouteBuilder endpoints) endpoints.MapConnectionHandler("/path"); } - using (var host = BuildWebHostWithEndPointRouting(ConfigureRoutes)) + using (var host = BuildWebHost(ConfigureRoutes)) { host.Start(); @@ -308,7 +308,7 @@ public async Task MapConnectionHandlerWithWebSocketSubProtocolSetsProtocol() var host = BuildWebHost("/socket", options => options.WebSockets.SubProtocolSelector = subprotocols => { - Assert.Equal(new [] { "protocol1", "protocol2" }, subprotocols.ToArray()); + Assert.Equal(new[] { "protocol1", "protocol2" }, subprotocols.ToArray()); return "protocol1"; }); @@ -377,7 +377,7 @@ public override Task OnConnectedAsync(ConnectionContext connection) } } - private IWebHost BuildWebHostWithEndPointRouting(Action configure) + private IWebHost BuildWebHost(Action configure) { return new WebHostBuilder() .UseKestrel() @@ -405,12 +405,11 @@ private IWebHost BuildWebHost(string path, Action { -#pragma warning disable CS0618 // Type or member is obsolete - app.UseConnections(routes => + app.UseRouting(); + app.UseEndpoints(routes => { routes.MapConnectionHandler(path, configureOptions); }); -#pragma warning restore CS0618 // Type or member is obsolete }) .ConfigureLogging(factory => { diff --git a/src/SignalR/server/SignalR/ref/Microsoft.AspNetCore.SignalR.netcoreapp.cs b/src/SignalR/server/SignalR/ref/Microsoft.AspNetCore.SignalR.netcoreapp.cs index 0021c03cbd8c..de595a611b0d 100644 --- a/src/SignalR/server/SignalR/ref/Microsoft.AspNetCore.SignalR.netcoreapp.cs +++ b/src/SignalR/server/SignalR/ref/Microsoft.AspNetCore.SignalR.netcoreapp.cs @@ -16,11 +16,6 @@ public static partial class HubEndpointRouteBuilderExtensions public partial interface IHubEndpointConventionBuilder : Microsoft.AspNetCore.Builder.IEndpointConventionBuilder { } - public static partial class SignalRAppBuilderExtensions - { - [System.ObsoleteAttribute("This method is obsolete and will be removed in a future version. The recommended alternative is to use MapHub inside Microsoft.AspNetCore.Builder.UseEndpoints(...).")] - public static Microsoft.AspNetCore.Builder.IApplicationBuilder UseSignalR(this Microsoft.AspNetCore.Builder.IApplicationBuilder app, System.Action configure) { throw null; } - } } namespace Microsoft.AspNetCore.SignalR { @@ -29,13 +24,6 @@ public static partial class GetHttpContextExtensions public static Microsoft.AspNetCore.Http.HttpContext GetHttpContext(this Microsoft.AspNetCore.SignalR.HubCallerContext connection) { throw null; } public static Microsoft.AspNetCore.Http.HttpContext GetHttpContext(this Microsoft.AspNetCore.SignalR.HubConnectionContext connection) { throw null; } } - [System.ObsoleteAttribute("This class is obsolete and will be removed in a future version. The recommended alternative is to use MapHub inside Microsoft.AspNetCore.Builder.UseEndpoints(...).")] - public partial class HubRouteBuilder - { - public HubRouteBuilder(Microsoft.AspNetCore.Http.Connections.ConnectionsRouteBuilder routes) { } - public void MapHub(Microsoft.AspNetCore.Http.PathString path) where THub : Microsoft.AspNetCore.SignalR.Hub { } - public void MapHub(Microsoft.AspNetCore.Http.PathString path, System.Action configureOptions) where THub : Microsoft.AspNetCore.SignalR.Hub { } - } } namespace Microsoft.Extensions.DependencyInjection { diff --git a/src/SignalR/server/SignalR/src/HubRouteBuilder.cs b/src/SignalR/server/SignalR/src/HubRouteBuilder.cs deleted file mode 100644 index cf9f694bb355..000000000000 --- a/src/SignalR/server/SignalR/src/HubRouteBuilder.cs +++ /dev/null @@ -1,82 +0,0 @@ -// 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. - -using System; -using System.Reflection; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Connections; -using Microsoft.AspNetCore.Routing; - -namespace Microsoft.AspNetCore.SignalR -{ - /// - /// Maps incoming requests to types. - /// - /// This class is obsolete and will be removed in a future version. - /// The recommended alternative is to use MapHub<THub> inside Microsoft.AspNetCore.Builder.UseEndpoints(...). - /// - /// - [Obsolete("This class is obsolete and will be removed in a future version. The recommended alternative is to use MapHub inside Microsoft.AspNetCore.Builder.UseEndpoints(...).")] - public class HubRouteBuilder - { - private readonly ConnectionsRouteBuilder _routes; - private readonly IEndpointRouteBuilder _endpoints; - - /// - /// Initializes a new instance of the class. - /// - /// The routes builder. - public HubRouteBuilder(ConnectionsRouteBuilder routes) - { - _routes = routes; - } - - internal HubRouteBuilder(IEndpointRouteBuilder endpoints) - { - _endpoints = endpoints; - } - - /// - /// Maps incoming requests with the specified path to the specified type. - /// - /// The type to map requests to. - /// The request path. - public void MapHub(PathString path) where THub : Hub - { - MapHub(path, configureOptions: null); - } - - /// - /// Maps incoming requests with the specified path to the specified type. - /// - /// The type to map requests to. - /// The request path. - /// A callback to configure dispatcher options. - public void MapHub(PathString path, Action configureOptions) where THub : Hub - { - // This will be null if someone is manually using the HubRouteBuilder(ConnectionsRouteBuilder routes) constructor - // SignalR itself will only use the IEndpointRouteBuilder overload - if (_endpoints != null) - { - _endpoints.MapHub(path, configureOptions); - return; - } - - // find auth attributes - var authorizeAttributes = typeof(THub).GetCustomAttributes(inherit: true); - var options = new HttpConnectionDispatcherOptions(); - foreach (var attribute in authorizeAttributes) - { - options.AuthorizationData.Add(attribute); - } - configureOptions?.Invoke(options); - - _routes.MapConnections(path, options, builder => - { - builder.UseHub(); - }); - } - } -} diff --git a/src/SignalR/server/SignalR/src/SignalRAppBuilderExtensions.cs b/src/SignalR/server/SignalR/src/SignalRAppBuilderExtensions.cs deleted file mode 100644 index e01870193a52..000000000000 --- a/src/SignalR/server/SignalR/src/SignalRAppBuilderExtensions.cs +++ /dev/null @@ -1,46 +0,0 @@ -// 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. - -using System; -using Microsoft.AspNetCore.SignalR; -using Microsoft.Extensions.DependencyInjection; - -namespace Microsoft.AspNetCore.Builder -{ - /// - /// Extension methods for . - /// - public static class SignalRAppBuilderExtensions - { - /// - /// Adds SignalR to the request execution pipeline. - /// - /// This method is obsolete and will be removed in a future version. - /// The recommended alternative is to use MapHub<THub> inside Microsoft.AspNetCore.Builder.UseEndpoints(...). - /// - /// - /// The . - /// A callback to configure hub routes. - /// The same instance of the for chaining. - [Obsolete("This method is obsolete and will be removed in a future version. The recommended alternative is to use MapHub inside Microsoft.AspNetCore.Builder.UseEndpoints(...).")] - public static IApplicationBuilder UseSignalR(this IApplicationBuilder app, Action configure) - { - var marker = app.ApplicationServices.GetService(); - if (marker == null) - { - throw new InvalidOperationException("Unable to find the required services. Please add all the required services by calling " + - "'IServiceCollection.AddSignalR' inside the call to 'ConfigureServices(...)' in the application startup code."); - } - - app.UseWebSockets(); - app.UseRouting(); - app.UseAuthorization(); - app.UseEndpoints(endpoints => - { - configure(new HubRouteBuilder(endpoints)); - }); - - return app; - } - } -} diff --git a/src/SignalR/server/SignalR/test/EndToEndTests.cs b/src/SignalR/server/SignalR/test/EndToEndTests.cs index e2b22a2d6e45..c9f85fefbd11 100644 --- a/src/SignalR/server/SignalR/test/EndToEndTests.cs +++ b/src/SignalR/server/SignalR/test/EndToEndTests.cs @@ -579,45 +579,6 @@ private async Task ServerClosesConnectionWithErrorIfHubCannotBeCreated(HttpTrans } } - [Fact] - [LogLevel(LogLevel.Trace)] - public async Task UnauthorizedHubConnectionDoesNotConnectWithEndpoints() - { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == typeof(HttpConnection).FullName && - writeContext.EventId.Name == "ErrorWithNegotiation"; - } - - using (var server = await StartServer(ExpectedErrors)) - { - var logger = LoggerFactory.CreateLogger(); - - var url = server.Url + "/authHubEndpoints"; - var connection = new HubConnectionBuilder() - .WithLoggerFactory(LoggerFactory) - .WithUrl(url, HttpTransportType.LongPolling) - .Build(); - - try - { - logger.LogInformation("Starting connection to {url}", url); - await connection.StartAsync().OrTimeout(); - Assert.True(false); - } - catch (Exception ex) - { - Assert.Equal("Response status code does not indicate success: 401 (Unauthorized).", ex.Message); - } - finally - { - logger.LogInformation("Disposing Connection"); - await connection.DisposeAsync().OrTimeout(); - logger.LogInformation("Disposed Connection"); - } - } - } - [Fact] [LogLevel(LogLevel.Trace)] public async Task UnauthorizedHubConnectionDoesNotConnect() @@ -657,53 +618,6 @@ bool ExpectedErrors(WriteContext writeContext) } } - [Fact] - [LogLevel(LogLevel.Trace)] - public async Task AuthorizedHubConnectionCanConnectWithEndpoints() - { - bool ExpectedErrors(WriteContext writeContext) - { - return writeContext.LoggerName == typeof(HttpConnection).FullName && - writeContext.EventId.Name == "ErrorWithNegotiation"; - } - - using (var server = await StartServer(ExpectedErrors)) - { - var logger = LoggerFactory.CreateLogger(); - - string token; - using (var client = new HttpClient()) - { - client.BaseAddress = new Uri(server.Url); - - var response = await client.GetAsync("generatetoken?user=bob"); - token = await response.Content.ReadAsStringAsync(); - } - - var url = server.Url + "/authHubEndpoints"; - var connection = new HubConnectionBuilder() - .WithLoggerFactory(LoggerFactory) - .WithUrl(url, HttpTransportType.LongPolling, o => - { - o.AccessTokenProvider = () => Task.FromResult(token); - }) - .Build(); - - try - { - logger.LogInformation("Starting connection to {url}", url); - await connection.StartAsync().OrTimeout(); - logger.LogInformation("Connected to {url}", url); - } - finally - { - logger.LogInformation("Disposing Connection"); - await connection.DisposeAsync().OrTimeout(); - logger.LogInformation("Disposed Connection"); - } - } - } - [Fact] [LogLevel(LogLevel.Trace)] public async Task AuthorizedHubConnectionCanConnect() diff --git a/src/SignalR/server/SignalR/test/MapSignalRTests.cs b/src/SignalR/server/SignalR/test/MapSignalRTests.cs index 01bc4d2e3370..8f1a79dc4a22 100644 --- a/src/SignalR/server/SignalR/test/MapSignalRTests.cs +++ b/src/SignalR/server/SignalR/test/MapSignalRTests.cs @@ -31,41 +31,6 @@ public void NotAddingSignalRServiceThrows() var executedConfigure = false; var builder = new WebHostBuilder(); - builder - .UseKestrel() - .Configure(app => - { - executedConfigure = true; - - var ex = Assert.Throws(() => - { -#pragma warning disable CS0618 // Type or member is obsolete - app.UseSignalR(routes => - { - routes.MapHub("/overloads"); - }); -#pragma warning restore CS0618 // Type or member is obsolete - }); - - Assert.Equal("Unable to find the required services. Please add all the required services by calling " + - "'IServiceCollection.AddSignalR' inside the call to 'ConfigureServices(...)' in the application startup code.", ex.Message); - }) - .UseUrls("http://127.0.0.1:0"); - - using (var host = builder.Build()) - { - host.Start(); - } - - Assert.True(executedConfigure); - } - - [Fact] - public void NotAddingSignalRServiceThrowsWhenUsingEndpointRouting() - { - var executedConfigure = false; - var builder = new WebHostBuilder(); - builder .UseKestrel() .ConfigureServices(services => @@ -189,7 +154,7 @@ public void MapHubFindsMultipleAuthAttributesOnDoubleAuthHub() public void MapHubEndPointRoutingFindsAttributesOnHub() { var authCount = 0; - using (var host = BuildWebHostWithEndPointRouting(routes => routes.MapHub("/path", options => + using (var host = BuildWebHost(routes => routes.MapHub("/path", options => { authCount += options.AuthorizationData.Count; }))) @@ -219,7 +184,7 @@ public void MapHubEndPointRoutingFindsAttributesOnHubAndFromOptions() { var authCount = 0; HttpConnectionDispatcherOptions configuredOptions = null; - using (var host = BuildWebHostWithEndPointRouting(routes => routes.MapHub("/path", options => + using (var host = BuildWebHost(routes => routes.MapHub("/path", options => { authCount += options.AuthorizationData.Count; options.AuthorizationData.Add(new AuthorizeAttribute()); @@ -256,7 +221,7 @@ void ConfigureRoutes(IEndpointRouteBuilder endpoints) .RequireAuthorization(new AuthorizeAttribute("Foo")); } - using (var host = BuildWebHostWithEndPointRouting(ConfigureRoutes)) + using (var host = BuildWebHost(ConfigureRoutes)) { host.Start(); @@ -295,7 +260,7 @@ void ConfigureRoutes(IEndpointRouteBuilder endpoints) endpoints.MapHub("/path"); } - using (var host = BuildWebHostWithEndPointRouting(ConfigureRoutes)) + using (var host = BuildWebHost(ConfigureRoutes)) { host.Start(); @@ -320,9 +285,7 @@ void ConfigureRoutes(IEndpointRouteBuilder endpoints) [Fact] public void MapHubAppliesHubMetadata() { -#pragma warning disable CS0618 // Type or member is obsolete - void ConfigureRoutes(HubRouteBuilder routes) -#pragma warning restore CS0618 // Type or member is obsolete + void ConfigureRoutes(IEndpointRouteBuilder routes) { // This "Foo" policy should override the default auth attribute routes.MapHub("/path"); @@ -375,7 +338,7 @@ private class AuthHub : Hub { } - private IWebHost BuildWebHostWithEndPointRouting(Action configure) + private IWebHost BuildWebHost(Action configure) { return new WebHostBuilder() .UseKestrel() @@ -391,23 +354,5 @@ private IWebHost BuildWebHostWithEndPointRouting(Action c .UseUrls("http://127.0.0.1:0") .Build(); } - -#pragma warning disable CS0618 // Type or member is obsolete - private IWebHost BuildWebHost(Action configure) - { - return new WebHostBuilder() - .UseKestrel() - .ConfigureServices(services => - { - services.AddSignalR(); - }) - .Configure(app => - { - app.UseSignalR(options => configure(options)); - }) - .UseUrls("http://127.0.0.1:0") - .Build(); - } -#pragma warning restore CS0618 // Type or member is obsolete } } diff --git a/src/SignalR/server/SignalR/test/Startup.cs b/src/SignalR/server/SignalR/test/Startup.cs index 25612f917f40..8ee6f7e53f82 100644 --- a/src/SignalR/server/SignalR/test/Startup.cs +++ b/src/SignalR/server/SignalR/test/Startup.cs @@ -71,18 +71,10 @@ public void Configure(IApplicationBuilder app) app.UseAuthentication(); app.UseAuthorization(); - // Legacy routing, runs different code path for mapping hubs -#pragma warning disable CS0618 // Type or member is obsolete - app.UseSignalR(routes => - { - routes.MapHub("/authHub"); - }); -#pragma warning restore CS0618 // Type or member is obsolete - app.UseEndpoints(endpoints => { endpoints.MapHub("/uncreatable"); - endpoints.MapHub("/authHubEndpoints"); + endpoints.MapHub("/authHub"); endpoints.MapConnectionHandler("/echo"); endpoints.MapConnectionHandler("/echoAndClose");