From 2e63e5afe31e9bba15e4737fc252bcd20c621758 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Thu, 22 Mar 2018 22:35:55 -0700 Subject: [PATCH] The rename games part 1 of many (#1696) - React to rename of EndPoint to ConnectionHandler - Rename UseSockets to UseConnections - Rename MapEndPoint to MapConnectionHandler - Rename HttpSocketOptions to HttpConnectionOptions --- .../DefaultHubDispatcherBenchmark.cs | 2 +- build/dependencies.props | 4 +- ...hoEndPoint.cs => EchoConnectionHandler.cs} | 6 +- clients/ts/FunctionalTests/Startup.cs | 7 +- samples/ClientSample/RawSample.cs | 2 +- samples/SocialWeather/ConnectionList.cs | 2 +- .../PersistentConnectionLifeTimeManager.cs | 4 +- ...t.cs => SocialWeatherConnectionHandler.cs} | 12 +- samples/SocialWeather/Startup.cs | 6 +- .../MessagesConnectionHandler.cs} | 8 +- samples/SocketsSample/ConnectionList.cs | 2 +- samples/SocketsSample/Startup.cs | 10 +- .../HubConnection.cs | 2 +- .../Internal/Protocol/IHubProtocol.cs | 2 +- .../Internal/Protocol/JsonHubProtocol.cs | 2 +- .../HubConnectionContext.cs | 6 +- ...HubEndPoint.cs => HubConnectionHandler.cs} | 22 +- .../SignalRDependencyInjectionExtensions.cs | 2 +- .../SignalRSocketBuilderExtensions.cs | 7 +- .../Protocol/MessagePackHubProtocol.cs | 2 +- .../HubRouteBuilder.cs | 16 +- .../SignalRAppBuilderExtensions.cs | 2 +- .../SignalRDependencyInjectionExtensions.cs | 2 +- .../ConnectionBuilderExtensions.cs | 23 - .../DefaultConnectionContext.cs | 4 +- .../EndPoint.cs | 21 - .../ConnectionInherentKeepAliveFeature.cs | 2 +- .../IConnection.cs | 2 +- ...oft.AspNetCore.Sockets.Abstractions.csproj | 2 +- .../HttpConnection.Log.cs | 2 +- .../HttpConnection.cs | 2 +- .../ITransport.cs | 2 +- .../LongPollingTransport.Log.cs | 2 +- .../LongPollingTransport.cs | 4 +- ...soft.AspNetCore.Sockets.Client.Http.csproj | 3 - .../ServerSentEventsTransport.Log.cs | 2 +- .../ServerSentEventsTransport.cs | 2 +- .../WebSocketsTransport.Log.cs | 2 +- .../WebSocketsTransport.cs | 2 +- ....cs => ConnectionsAppBuilderExtensions.cs} | 6 +- ...nnectionsDependencyInjectionExtensions.cs} | 4 +- .../ConnectionsRouteBuilder.cs | 65 +++ .../HttpConnectionContextExtensions.cs | 2 +- .../HttpConnectionDispatcher.Log.cs | 2 +- .../HttpConnectionDispatcher.cs | 26 +- ...ketOptions.cs => HttpConnectionOptions.cs} | 2 +- .../Transports/WebSocketsTransport.cs | 2 +- .../SocketRouteBuilder.cs | 65 --- .../HttpConnectionTests.AbortAsync.cs | 2 +- ...HttpConnectionTests.ConnectionLifecycle.cs | 2 +- .../HttpConnectionTests.Negotiate.cs | 2 +- .../HttpConnectionTests.OnReceived.cs | 2 +- .../HttpConnectionTests.SendAsync.cs | 2 +- .../HttpConnectionTests.cs | 2 +- .../HubConnectionTests.cs | 2 +- .../LongPollingTransportTests.cs | 2 +- .../ResponseUtils.cs | 2 +- .../ServerSentEventsTransportTests.cs | 2 +- .../TestConnection.cs | 2 +- .../TestTransport.cs | 2 +- .../HubConnectionContextUtils.cs | 2 +- .../TestClient.cs | 4 +- ...hoEndPoint.cs => EchoConnectionHandler.cs} | 4 +- .../EndToEndTests.cs | 4 +- ...oint.cs => HttpHeaderConnectionHandler.cs} | 4 +- ...tTests.cs => HubConnectionHandlerTests.cs} | 516 +++++++++--------- .../HubEndpointTestUtils/Hubs.cs | 2 +- .../HubEndpointTestUtils/Utils.cs | 14 +- .../DefaultHubProtocolResolverTests.cs | 2 +- .../MapSignalRTests.cs | 18 +- .../Startup.cs | 10 +- .../WebSocketsTransportTests.cs | 2 +- .../HttpConnectionDispatcherTests.cs | 222 ++++---- .../LongPollingTests.cs | 2 +- ...tTests.cs => MapConnectionHandlerTests.cs} | 40 +- .../WebSocketsTests.cs | 2 +- 76 files changed, 599 insertions(+), 654 deletions(-) rename clients/ts/FunctionalTests/{EchoEndPoint.cs => EchoConnectionHandler.cs} (90%) rename samples/SocialWeather/{SocialWeatherEndPoint.cs => SocialWeatherConnectionHandler.cs} (85%) rename samples/SocketsSample/{EndPoints/MessagesEndPoint.cs => ConnectionHandlers/MessagesConnectionHandler.cs} (92%) rename src/Microsoft.AspNetCore.SignalR.Core/{HubEndPoint.cs => HubConnectionHandler.cs} (92%) delete mode 100644 src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionBuilderExtensions.cs delete mode 100644 src/Microsoft.AspNetCore.Sockets.Abstractions/EndPoint.cs rename src/Microsoft.AspNetCore.Sockets.Http/{SocketsAppBuilderExtensions.cs => ConnectionsAppBuilderExtensions.cs} (71%) rename src/Microsoft.AspNetCore.Sockets.Http/{SocketsDependencyInjectionExtensions.cs => ConnectionsDependencyInjectionExtensions.cs} (79%) create mode 100644 src/Microsoft.AspNetCore.Sockets.Http/ConnectionsRouteBuilder.cs rename src/Microsoft.AspNetCore.Sockets.Http/{HttpSocketOptions.cs => HttpConnectionOptions.cs} (95%) delete mode 100644 src/Microsoft.AspNetCore.Sockets.Http/SocketRouteBuilder.cs rename test/Microsoft.AspNetCore.SignalR.Tests/{EchoEndPoint.cs => EchoConnectionHandler.cs} (89%) rename test/Microsoft.AspNetCore.SignalR.Tests/{HttpHeaderEndPoint.cs => HttpHeaderConnectionHandler.cs} (92%) rename test/Microsoft.AspNetCore.SignalR.Tests/{HubEndpointTests.cs => HubConnectionHandlerTests.cs} (71%) rename test/Microsoft.AspNetCore.Sockets.Tests/{MapEndPointTests.cs => MapConnectionHandlerTests.cs} (74%) diff --git a/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/DefaultHubDispatcherBenchmark.cs b/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/DefaultHubDispatcherBenchmark.cs index d21bb61c40..7128043e4e 100644 --- a/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/DefaultHubDispatcherBenchmark.cs +++ b/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/DefaultHubDispatcherBenchmark.cs @@ -9,7 +9,7 @@ using System.Reactive.Linq; using System.Threading.Channels; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.SignalR.Internal; using Microsoft.AspNetCore.SignalR.Internal.Protocol; using Microsoft.AspNetCore.Sockets; diff --git a/build/dependencies.props b/build/dependencies.props index 7590b78207..4308906952 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -22,11 +22,11 @@ 2.1.0-preview2-30355 2.1.0-preview2-30355 2.1.0-preview2-30355 - 2.1.0-preview2-30355 + 2.1.0-a-preview2-bedrock-renames-17598 2.1.0-preview2-30355 2.1.0-preview2-30355 0.5.0-preview2-30355 - 2.1.0-preview2-30355 + 2.1.0-a-preview2-bedrock-renames-17598 2.1.0-preview2-30355 2.1.0-preview2-30355 2.1.0-preview2-30355 diff --git a/clients/ts/FunctionalTests/EchoEndPoint.cs b/clients/ts/FunctionalTests/EchoConnectionHandler.cs similarity index 90% rename from clients/ts/FunctionalTests/EchoEndPoint.cs rename to clients/ts/FunctionalTests/EchoConnectionHandler.cs index ed08754845..1dcf340e04 100644 --- a/clients/ts/FunctionalTests/EchoEndPoint.cs +++ b/clients/ts/FunctionalTests/EchoConnectionHandler.cs @@ -3,13 +3,13 @@ using System.Buffers; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; -using Microsoft.AspNetCore.Protocols.Features; +using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Sockets; namespace FunctionalTests { - public class EchoEndPoint : EndPoint + public class EchoConnectionHandler : ConnectionHandler { public async override Task OnConnectedAsync(ConnectionContext connection) { diff --git a/clients/ts/FunctionalTests/Startup.cs b/clients/ts/FunctionalTests/Startup.cs index a5b77ef60d..6c65dc518e 100644 --- a/clients/ts/FunctionalTests/Startup.cs +++ b/clients/ts/FunctionalTests/Startup.cs @@ -23,7 +23,7 @@ namespace FunctionalTests public void ConfigureServices(IServiceCollection services) { - services.AddSockets(); + services.AddConnections(); services.AddSignalR() .AddJsonProtocol(options => { @@ -70,7 +70,6 @@ namespace FunctionalTests } }; }); - services.AddSingleton(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) @@ -81,9 +80,9 @@ namespace FunctionalTests } app.UseFileServer(); - app.UseSockets(routes => + app.UseConnections(routes => { - routes.MapEndPoint("/echo"); + routes.MapConnectionHandler("/echo"); }); app.UseSignalR(routes => diff --git a/samples/ClientSample/RawSample.cs b/samples/ClientSample/RawSample.cs index c4d8f614fb..5ac8c1a6cb 100644 --- a/samples/ClientSample/RawSample.cs +++ b/samples/ClientSample/RawSample.cs @@ -8,7 +8,7 @@ using System.Net.Http; using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets.Client; using Microsoft.Extensions.CommandLineUtils; diff --git a/samples/SocialWeather/ConnectionList.cs b/samples/SocialWeather/ConnectionList.cs index 870c1fb44e..7806439a33 100644 --- a/samples/SocialWeather/ConnectionList.cs +++ b/samples/SocialWeather/ConnectionList.cs @@ -5,7 +5,7 @@ using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; namespace Microsoft.AspNetCore.Sockets { diff --git a/samples/SocialWeather/PersistentConnectionLifeTimeManager.cs b/samples/SocialWeather/PersistentConnectionLifeTimeManager.cs index 00d625ff5c..c95e16a738 100644 --- a/samples/SocialWeather/PersistentConnectionLifeTimeManager.cs +++ b/samples/SocialWeather/PersistentConnectionLifeTimeManager.cs @@ -5,8 +5,8 @@ using System; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; -using Microsoft.AspNetCore.Protocols.Features; +using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Sockets; namespace SocialWeather diff --git a/samples/SocialWeather/SocialWeatherEndPoint.cs b/samples/SocialWeather/SocialWeatherConnectionHandler.cs similarity index 85% rename from samples/SocialWeather/SocialWeatherEndPoint.cs rename to samples/SocialWeather/SocialWeatherConnectionHandler.cs index f6f5c58b6c..42bf01052e 100644 --- a/samples/SocialWeather/SocialWeatherEndPoint.cs +++ b/samples/SocialWeather/SocialWeatherConnectionHandler.cs @@ -4,21 +4,21 @@ using System.Buffers; using System.IO; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; -using Microsoft.AspNetCore.Protocols.Features; +using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Sockets; using Microsoft.Extensions.Logging; namespace SocialWeather { - public class SocialWeatherEndPoint : EndPoint + public class SocialWeatherConnectionHandler : ConnectionHandler { private readonly PersistentConnectionLifeTimeManager _lifetimeManager; private readonly FormatterResolver _formatterResolver; - private readonly ILogger _logger; + private readonly ILogger _logger; - public SocialWeatherEndPoint(PersistentConnectionLifeTimeManager lifetimeManager, - FormatterResolver formatterResolver, ILogger logger) + public SocialWeatherConnectionHandler(PersistentConnectionLifeTimeManager lifetimeManager, + FormatterResolver formatterResolver, ILogger logger) { _lifetimeManager = lifetimeManager; _formatterResolver = formatterResolver; diff --git a/samples/SocialWeather/Startup.cs b/samples/SocialWeather/Startup.cs index 2501f09f01..b7721e3a2a 100644 --- a/samples/SocialWeather/Startup.cs +++ b/samples/SocialWeather/Startup.cs @@ -15,9 +15,7 @@ namespace SocialWeather { public void ConfigureServices(IServiceCollection services) { - services.AddRouting(); - services.AddSockets(); - services.AddSingleton(); + services.AddConnections(); services.AddTransient(); services.AddSingleton(typeof(JsonStreamFormatter<>), typeof(JsonStreamFormatter<>)); services.AddSingleton(); @@ -32,7 +30,7 @@ namespace SocialWeather app.UseDeveloperExceptionPage(); } - app.UseSockets(o => { o.MapEndPoint("/weather"); }); + app.UseConnections(o => o.MapConnectionHandler("/weather")); app.UseFileServer(); var formatterResolver = app.ApplicationServices.GetRequiredService(); diff --git a/samples/SocketsSample/EndPoints/MessagesEndPoint.cs b/samples/SocketsSample/ConnectionHandlers/MessagesConnectionHandler.cs similarity index 92% rename from samples/SocketsSample/EndPoints/MessagesEndPoint.cs rename to samples/SocketsSample/ConnectionHandlers/MessagesConnectionHandler.cs index 038e8873fa..9a7b711116 100644 --- a/samples/SocketsSample/EndPoints/MessagesEndPoint.cs +++ b/samples/SocketsSample/ConnectionHandlers/MessagesConnectionHandler.cs @@ -5,13 +5,13 @@ using System.Buffers; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; -using Microsoft.AspNetCore.Protocols.Features; +using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Sockets; -namespace SocketsSample.EndPoints +namespace SocketsSample.ConnectionHandlers { - public class MessagesEndPoint : EndPoint + public class MessagesConnectionHandler : ConnectionHandler { private ConnectionList Connections { get; } = new ConnectionList(); diff --git a/samples/SocketsSample/ConnectionList.cs b/samples/SocketsSample/ConnectionList.cs index 870c1fb44e..7806439a33 100644 --- a/samples/SocketsSample/ConnectionList.cs +++ b/samples/SocketsSample/ConnectionList.cs @@ -5,7 +5,7 @@ using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; namespace Microsoft.AspNetCore.Sockets { diff --git a/samples/SocketsSample/Startup.cs b/samples/SocketsSample/Startup.cs index 5573bacb79..91e7023939 100644 --- a/samples/SocketsSample/Startup.cs +++ b/samples/SocketsSample/Startup.cs @@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Sockets; using Microsoft.Extensions.DependencyInjection; using MsgPack.Serialization; -using SocketsSample.EndPoints; +using SocketsSample.ConnectionHandlers; using SocketsSample.Hubs; using StackExchange.Redis; @@ -19,7 +19,7 @@ namespace SocketsSample // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { - services.AddSockets(); + services.AddConnections(); services.AddSignalR(options => { @@ -42,8 +42,6 @@ namespace SocketsSample .AllowCredentials(); }); }); - - services.AddSingleton(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -66,9 +64,9 @@ namespace SocketsSample routes.MapHub("/hubT"); }); - app.UseSockets(routes => + app.UseConnections(routes => { - routes.MapEndPoint("/chat"); + routes.MapConnectionHandler("/chat"); }); } } diff --git a/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs b/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs index a5e9e90560..af3d8e2e05 100644 --- a/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs +++ b/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs @@ -8,7 +8,7 @@ using System.IO; using System.Threading; using System.Threading.Channels; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols.Features; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.SignalR.Internal; using Microsoft.AspNetCore.SignalR.Internal.Formatters; using Microsoft.AspNetCore.SignalR.Internal.Protocol; diff --git a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/IHubProtocol.cs b/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/IHubProtocol.cs index ab5f071eb5..7430391c7e 100644 --- a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/IHubProtocol.cs +++ b/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/IHubProtocol.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.IO; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; namespace Microsoft.AspNetCore.SignalR.Internal.Protocol { diff --git a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/JsonHubProtocol.cs b/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/JsonHubProtocol.cs index c7522bf2fc..df6a664f2f 100644 --- a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/JsonHubProtocol.cs +++ b/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/JsonHubProtocol.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Runtime.ExceptionServices; using System.Text; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.SignalR.Internal.Formatters; using Microsoft.Extensions.Options; using Newtonsoft.Json; diff --git a/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs b/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs index 754bcfb4aa..70a4ce9037 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs @@ -14,8 +14,8 @@ using System.Security.Claims; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols; -using Microsoft.AspNetCore.Protocols.Features; +using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.SignalR.Core; using Microsoft.AspNetCore.SignalR.Internal; using Microsoft.AspNetCore.SignalR.Internal.Protocol; @@ -313,7 +313,7 @@ namespace Microsoft.AspNetCore.SignalR Abort(); } - // Used by the HubEndPoint only + // Used by the HubConnectionHandler only internal Task AbortAsync() { Abort(); diff --git a/src/Microsoft.AspNetCore.SignalR.Core/HubEndPoint.cs b/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionHandler.cs similarity index 92% rename from src/Microsoft.AspNetCore.SignalR.Core/HubEndPoint.cs rename to src/Microsoft.AspNetCore.SignalR.Core/HubConnectionHandler.cs index 2ff9c0de1b..d54eeac045 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/HubEndPoint.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionHandler.cs @@ -5,7 +5,7 @@ using System; using System.Buffers; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.SignalR.Core; using Microsoft.AspNetCore.SignalR.Internal; using Microsoft.AspNetCore.SignalR.Internal.Protocol; @@ -15,31 +15,31 @@ using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.SignalR { - public class HubEndPoint : EndPoint where THub : Hub + public class HubConnectionHandler : ConnectionHandler where THub : Hub { private readonly HubLifetimeManager _lifetimeManager; private readonly ILoggerFactory _loggerFactory; - private readonly ILogger> _logger; + private readonly ILogger> _logger; private readonly IHubProtocolResolver _protocolResolver; private readonly HubOptions _hubOptions; private readonly HubOptions _globalHubOptions; private readonly IUserIdProvider _userIdProvider; private readonly HubDispatcher _dispatcher; - public HubEndPoint(HubLifetimeManager lifetimeManager, - IHubProtocolResolver protocolResolver, - IOptions globalHubOptions, - IOptions> hubOptions, - ILoggerFactory loggerFactory, - IUserIdProvider userIdProvider, - HubDispatcher dispatcher) + public HubConnectionHandler(HubLifetimeManager lifetimeManager, + IHubProtocolResolver protocolResolver, + IOptions globalHubOptions, + IOptions> hubOptions, + ILoggerFactory loggerFactory, + IUserIdProvider userIdProvider, + HubDispatcher dispatcher) { _protocolResolver = protocolResolver; _lifetimeManager = lifetimeManager; _loggerFactory = loggerFactory; _hubOptions = hubOptions.Value; _globalHubOptions = globalHubOptions.Value; - _logger = loggerFactory.CreateLogger>(); + _logger = loggerFactory.CreateLogger>(); _userIdProvider = userIdProvider; _dispatcher = dispatcher; } diff --git a/src/Microsoft.AspNetCore.SignalR.Core/SignalRDependencyInjectionExtensions.cs b/src/Microsoft.AspNetCore.SignalR.Core/SignalRDependencyInjectionExtensions.cs index 02f12060ee..7d3fc13fb3 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/SignalRDependencyInjectionExtensions.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/SignalRDependencyInjectionExtensions.cs @@ -15,7 +15,7 @@ namespace Microsoft.Extensions.DependencyInjection services.AddSingleton(typeof(IHubProtocolResolver), typeof(DefaultHubProtocolResolver)); services.AddSingleton(typeof(IHubContext<>), typeof(HubContext<>)); services.AddSingleton(typeof(IHubContext<,>), typeof(HubContext<,>)); - services.AddSingleton(typeof(HubEndPoint<>), typeof(HubEndPoint<>)); + services.AddSingleton(typeof(HubConnectionHandler<>), typeof(HubConnectionHandler<>)); services.AddSingleton(typeof(IUserIdProvider), typeof(DefaultUserIdProvider)); services.AddSingleton(typeof(HubDispatcher<>), typeof(DefaultHubDispatcher<>)); services.AddScoped(typeof(IHubActivator<>), typeof(DefaultHubActivator<>)); diff --git a/src/Microsoft.AspNetCore.SignalR.Core/SignalRSocketBuilderExtensions.cs b/src/Microsoft.AspNetCore.SignalR.Core/SignalRSocketBuilderExtensions.cs index a1e0e5f5e6..ed90edea45 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/SignalRSocketBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/SignalRSocketBuilderExtensions.cs @@ -1,7 +1,7 @@ // 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.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Sockets; using Microsoft.Extensions.DependencyInjection; @@ -9,10 +9,9 @@ namespace Microsoft.AspNetCore.SignalR { public static class SignalRSocketBuilderExtensions { - public static IConnectionBuilder UseHub(this IConnectionBuilder socketBuilder) where THub : Hub + public static IConnectionBuilder UseHub(this IConnectionBuilder connectionBuilder) where THub : Hub { - var endpoint = socketBuilder.ApplicationServices.GetRequiredService>(); - return socketBuilder.Run(connection => endpoint.OnConnectedAsync(connection)); + return connectionBuilder.UseConnectionHandler>(); } } } diff --git a/src/Microsoft.AspNetCore.SignalR.Protocols.MsgPack/Internal/Protocol/MessagePackHubProtocol.cs b/src/Microsoft.AspNetCore.SignalR.Protocols.MsgPack/Internal/Protocol/MessagePackHubProtocol.cs index 07b84e923d..59d4a93ec7 100644 --- a/src/Microsoft.AspNetCore.SignalR.Protocols.MsgPack/Internal/Protocol/MessagePackHubProtocol.cs +++ b/src/Microsoft.AspNetCore.SignalR.Protocols.MsgPack/Internal/Protocol/MessagePackHubProtocol.cs @@ -7,7 +7,7 @@ using System.Diagnostics; using System.IO; using System.Runtime.ExceptionServices; using System.Runtime.InteropServices; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.SignalR.Internal.Formatters; using Microsoft.Extensions.Options; using MsgPack; diff --git a/src/Microsoft.AspNetCore.SignalR/HubRouteBuilder.cs b/src/Microsoft.AspNetCore.SignalR/HubRouteBuilder.cs index 97463258e9..e6ea9c2566 100644 --- a/src/Microsoft.AspNetCore.SignalR/HubRouteBuilder.cs +++ b/src/Microsoft.AspNetCore.SignalR/HubRouteBuilder.cs @@ -11,35 +11,35 @@ namespace Microsoft.AspNetCore.SignalR { public class HubRouteBuilder { - private readonly SocketRouteBuilder _routes; + private readonly ConnectionsRouteBuilder _routes; - public HubRouteBuilder(SocketRouteBuilder routes) + public HubRouteBuilder(ConnectionsRouteBuilder routes) { _routes = routes; } public void MapHub(string path) where THub : Hub { - MapHub(new PathString(path), socketOptions: null); + MapHub(new PathString(path), configureOptions: null); } public void MapHub(PathString path) where THub : Hub { - MapHub(path, socketOptions: null); + MapHub(path, configureOptions: null); } - public void MapHub(PathString path, Action socketOptions) where THub : Hub + public void MapHub(PathString path, Action configureOptions) where THub : Hub { // find auth attributes var authorizeAttributes = typeof(THub).GetCustomAttributes(inherit: true); - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); foreach (var attribute in authorizeAttributes) { options.AuthorizationData.Add(attribute); } - socketOptions?.Invoke(options); + configureOptions?.Invoke(options); - _routes.MapSocket(path, options, builder => + _routes.MapConnections(path, options, builder => { builder.UseHub(); }); diff --git a/src/Microsoft.AspNetCore.SignalR/SignalRAppBuilderExtensions.cs b/src/Microsoft.AspNetCore.SignalR/SignalRAppBuilderExtensions.cs index 954a18087c..d687ad2701 100644 --- a/src/Microsoft.AspNetCore.SignalR/SignalRAppBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.SignalR/SignalRAppBuilderExtensions.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Builder "calling 'IServiceCollection.AddSignalR()'."); } - app.UseSockets(routes => + app.UseConnections(routes => { configure(new HubRouteBuilder(routes)); }); diff --git a/src/Microsoft.AspNetCore.SignalR/SignalRDependencyInjectionExtensions.cs b/src/Microsoft.AspNetCore.SignalR/SignalRDependencyInjectionExtensions.cs index 5872ff392c..ae2498ecde 100644 --- a/src/Microsoft.AspNetCore.SignalR/SignalRDependencyInjectionExtensions.cs +++ b/src/Microsoft.AspNetCore.SignalR/SignalRDependencyInjectionExtensions.cs @@ -11,7 +11,7 @@ namespace Microsoft.Extensions.DependencyInjection { public static ISignalRBuilder AddSignalR(this IServiceCollection services) { - services.AddSockets(); + services.AddConnections(); services.AddSingleton(); services.AddSingleton, HubOptionsSetup>(); return services.AddSignalRCore() diff --git a/src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionBuilderExtensions.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionBuilderExtensions.cs deleted file mode 100644 index cc438b74bc..0000000000 --- a/src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionBuilderExtensions.cs +++ /dev/null @@ -1,23 +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.Protocols; - -namespace Microsoft.AspNetCore.Sockets -{ - public static class ConnectionBuilderExtensions - { - public static IConnectionBuilder UseEndPoint(this IConnectionBuilder connectionBuilder) where TEndPoint : EndPoint - { - var endpoint = (TEndPoint)connectionBuilder.ApplicationServices.GetService(typeof(TEndPoint)); - - if (endpoint == null) - { - throw new InvalidOperationException($"{nameof(EndPoint)} type {typeof(TEndPoint)} is not registered."); - } - // This is a terminal middleware, so there's no need to use the 'next' parameter - return connectionBuilder.Run(connection => endpoint.OnConnectedAsync(connection)); - } - } -} diff --git a/src/Microsoft.AspNetCore.Sockets.Abstractions/DefaultConnectionContext.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/DefaultConnectionContext.cs index 693fb74312..cf61973cda 100644 --- a/src/Microsoft.AspNetCore.Sockets.Abstractions/DefaultConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Sockets.Abstractions/DefaultConnectionContext.cs @@ -8,8 +8,8 @@ using System.Security.Claims; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols; -using Microsoft.AspNetCore.Protocols.Features; +using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Connections.Features; namespace Microsoft.AspNetCore.Sockets { diff --git a/src/Microsoft.AspNetCore.Sockets.Abstractions/EndPoint.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/EndPoint.cs deleted file mode 100644 index 89de4b79fa..0000000000 --- a/src/Microsoft.AspNetCore.Sockets.Abstractions/EndPoint.cs +++ /dev/null @@ -1,21 +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.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; - -namespace Microsoft.AspNetCore.Sockets -{ - /// - /// Represents an end point that multiple connections connect to. For HTTP, endpoints are URLs, for non HTTP it can be a TCP listener (or similar) - /// - public abstract class EndPoint - { - /// - /// Called when a new connection is accepted to the endpoint - /// - /// The new - /// A that represents the connection lifetime. When the task completes, the connection is complete. - public abstract Task OnConnectedAsync(ConnectionContext connection); - } -} diff --git a/src/Microsoft.AspNetCore.Sockets.Abstractions/Features/ConnectionInherentKeepAliveFeature.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/Features/ConnectionInherentKeepAliveFeature.cs index 7de46e5385..c5785c3450 100644 --- a/src/Microsoft.AspNetCore.Sockets.Abstractions/Features/ConnectionInherentKeepAliveFeature.cs +++ b/src/Microsoft.AspNetCore.Sockets.Abstractions/Features/ConnectionInherentKeepAliveFeature.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.AspNetCore.Protocols.Features +namespace Microsoft.AspNetCore.Connections.Features { public class ConnectionInherentKeepAliveFeature : IConnectionInherentKeepAliveFeature { diff --git a/src/Microsoft.AspNetCore.Sockets.Abstractions/IConnection.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/IConnection.cs index 5f6a558f1a..b5605c96f8 100644 --- a/src/Microsoft.AspNetCore.Sockets.Abstractions/IConnection.cs +++ b/src/Microsoft.AspNetCore.Sockets.Abstractions/IConnection.cs @@ -5,7 +5,7 @@ using System; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; namespace Microsoft.AspNetCore.Sockets.Client { diff --git a/src/Microsoft.AspNetCore.Sockets.Abstractions/Microsoft.AspNetCore.Sockets.Abstractions.csproj b/src/Microsoft.AspNetCore.Sockets.Abstractions/Microsoft.AspNetCore.Sockets.Abstractions.csproj index 78df076a72..94f6277253 100644 --- a/src/Microsoft.AspNetCore.Sockets.Abstractions/Microsoft.AspNetCore.Sockets.Abstractions.csproj +++ b/src/Microsoft.AspNetCore.Sockets.Abstractions/Microsoft.AspNetCore.Sockets.Abstractions.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.Log.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.Log.cs index 00dc83ffdb..bb6433c34a 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.Log.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.Log.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Sockets.Client diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs index 3adf223633..3c6351e9a0 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs @@ -12,7 +12,7 @@ using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Sockets.Client.Http; using Microsoft.AspNetCore.Sockets.Client.Internal; using Microsoft.AspNetCore.Sockets.Http.Internal; diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/ITransport.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/ITransport.cs index 411a7d0925..9f6e3cfeb9 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/ITransport.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/ITransport.cs @@ -4,7 +4,7 @@ using System; using System.Threading.Tasks; using System.IO.Pipelines; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; namespace Microsoft.AspNetCore.Sockets.Client { diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/LongPollingTransport.Log.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/LongPollingTransport.Log.cs index 5148cf73fd..6d0df576e5 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/LongPollingTransport.Log.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/LongPollingTransport.Log.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Sockets.Client diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/LongPollingTransport.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/LongPollingTransport.cs index d946f67704..f702a2f33c 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/LongPollingTransport.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/LongPollingTransport.cs @@ -8,10 +8,10 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Sockets.Client.Http; -using Microsoft.AspNetCore.Protocols.Features; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; namespace Microsoft.AspNetCore.Sockets.Client { diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/Microsoft.AspNetCore.Sockets.Client.Http.csproj b/src/Microsoft.AspNetCore.Sockets.Client.Http/Microsoft.AspNetCore.Sockets.Client.Http.csproj index afab54c3f3..3d367e968f 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/Microsoft.AspNetCore.Sockets.Client.Http.csproj +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/Microsoft.AspNetCore.Sockets.Client.Http.csproj @@ -21,9 +21,6 @@ - - - diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsTransport.Log.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsTransport.Log.cs index df8e93360a..10414a88e5 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsTransport.Log.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsTransport.Log.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Sockets.Client diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsTransport.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsTransport.cs index 8d819d6cbd..922d5fddbd 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsTransport.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsTransport.cs @@ -7,7 +7,7 @@ using System.Net.Http; using System.Net.Http.Headers; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Sockets.Client.Http; using Microsoft.AspNetCore.Sockets.Internal.Formatters; using Microsoft.Extensions.Logging; diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/WebSocketsTransport.Log.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/WebSocketsTransport.Log.cs index d182d0daa7..4d06ca2412 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/WebSocketsTransport.Log.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/WebSocketsTransport.Log.cs @@ -3,7 +3,7 @@ using System; using System.Net.WebSockets; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Sockets.Client diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/WebSocketsTransport.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/WebSocketsTransport.cs index 8475dc7e23..e54e4d99d9 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/WebSocketsTransport.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/WebSocketsTransport.cs @@ -9,7 +9,7 @@ using System.Net.WebSockets; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Sockets.Client.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; diff --git a/src/Microsoft.AspNetCore.Sockets.Http/SocketsAppBuilderExtensions.cs b/src/Microsoft.AspNetCore.Sockets.Http/ConnectionsAppBuilderExtensions.cs similarity index 71% rename from src/Microsoft.AspNetCore.Sockets.Http/SocketsAppBuilderExtensions.cs rename to src/Microsoft.AspNetCore.Sockets.Http/ConnectionsAppBuilderExtensions.cs index f9baeb883c..e97b0e5ecb 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/SocketsAppBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/ConnectionsAppBuilderExtensions.cs @@ -8,15 +8,15 @@ using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Builder { - public static class SocketsAppBuilderExtensions + public static class ConnectionsAppBuilderExtensions { - public static IApplicationBuilder UseSockets(this IApplicationBuilder app, Action callback) + public static IApplicationBuilder UseConnections(this IApplicationBuilder app, Action callback) { var dispatcher = app.ApplicationServices.GetRequiredService(); var routes = new RouteBuilder(app); - callback(new SocketRouteBuilder(routes, dispatcher)); + callback(new ConnectionsRouteBuilder(routes, dispatcher)); app.UseWebSockets(); app.UseRouter(routes.Build()); diff --git a/src/Microsoft.AspNetCore.Sockets.Http/SocketsDependencyInjectionExtensions.cs b/src/Microsoft.AspNetCore.Sockets.Http/ConnectionsDependencyInjectionExtensions.cs similarity index 79% rename from src/Microsoft.AspNetCore.Sockets.Http/SocketsDependencyInjectionExtensions.cs rename to src/Microsoft.AspNetCore.Sockets.Http/ConnectionsDependencyInjectionExtensions.cs index 96c7044ddc..bd5cdfc1e0 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/SocketsDependencyInjectionExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/ConnectionsDependencyInjectionExtensions.cs @@ -6,9 +6,9 @@ using Microsoft.Extensions.DependencyInjection.Extensions; namespace Microsoft.Extensions.DependencyInjection { - public static class SocketsDependencyInjectionExtensions + public static class ConnectionsDependencyInjectionExtensions { - public static IServiceCollection AddSockets(this IServiceCollection services) + public static IServiceCollection AddConnections(this IServiceCollection services) { services.AddRouting(); services.AddAuthorizationPolicyEvaluator(); diff --git a/src/Microsoft.AspNetCore.Sockets.Http/ConnectionsRouteBuilder.cs b/src/Microsoft.AspNetCore.Sockets.Http/ConnectionsRouteBuilder.cs new file mode 100644 index 0000000000..0d66ba04ab --- /dev/null +++ b/src/Microsoft.AspNetCore.Sockets.Http/ConnectionsRouteBuilder.cs @@ -0,0 +1,65 @@ +// 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.Http; +using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Routing; + +namespace Microsoft.AspNetCore.Sockets +{ + public class ConnectionsRouteBuilder + { + private readonly HttpConnectionDispatcher _dispatcher; + private readonly RouteBuilder _routes; + + public ConnectionsRouteBuilder(RouteBuilder routes, HttpConnectionDispatcher dispatcher) + { + _routes = routes; + _dispatcher = dispatcher; + } + + public void MapConnections(string path, Action configure) => + MapConnections(new PathString(path), new HttpConnectionOptions(), configure); + + public void MapConnections(PathString path, Action configure) => + MapConnections(path, new HttpConnectionOptions(), configure); + + public void MapConnections(PathString path, HttpConnectionOptions options, Action configure) + { + var connectionBuilder = new ConnectionBuilder(_routes.ServiceProvider); + configure(connectionBuilder); + var socket = connectionBuilder.Build(); + _routes.MapRoute(path, c => _dispatcher.ExecuteAsync(c, options, socket)); + _routes.MapRoute(path + "/negotiate", c => _dispatcher.ExecuteNegotiateAsync(c, options)); + } + + public void MapConnectionHandler(string path) where TConnectionHandler : ConnectionHandler + { + MapConnectionHandler(new PathString(path), configureOptions: null); + } + + public void MapConnectionHandler(PathString path) where TConnectionHandler : ConnectionHandler + { + MapConnectionHandler(path, configureOptions: null); + } + + public void MapConnectionHandler(PathString path, Action configureOptions) where TConnectionHandler : ConnectionHandler + { + var authorizeAttributes = typeof(TConnectionHandler).GetCustomAttributes(inherit: true); + var options = new HttpConnectionOptions(); + foreach (var attribute in authorizeAttributes) + { + options.AuthorizationData.Add(attribute); + } + configureOptions?.Invoke(options); + + MapConnections(path, options, builder => + { + builder.UseConnectionHandler(); + }); + } + } +} diff --git a/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionContextExtensions.cs b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionContextExtensions.cs index 67a4d968d6..d0b1fa339c 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionContextExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionContextExtensions.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Sockets.Http.Features; namespace Microsoft.AspNetCore.Sockets diff --git a/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.Log.cs b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.Log.cs index 1cdc33e490..1bb37df6c0 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.Log.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.Log.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Sockets LoggerMessage.Define(LogLevel.Trace, new EventId(6, "ReceivedBytes"), "Received {Count} bytes."); private static readonly Action _transportNotSupported = - LoggerMessage.Define(LogLevel.Debug, new EventId(7, "TransportNotSupported"), "{TransportType} transport not supported by this endpoint type."); + LoggerMessage.Define(LogLevel.Debug, new EventId(7, "TransportNotSupported"), "{TransportType} transport not supported by this connection handler."); private static readonly Action _cannotChangeTransport = LoggerMessage.Define(LogLevel.Error, new EventId(8, "CannotChangeTransport"), "Cannot change transports mid-connection; currently using {TransportType}, requesting {RequestedTransport}."); diff --git a/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.cs b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.cs index 5b08db7a9e..19d3d35597 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.cs @@ -12,8 +12,8 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Internal; -using Microsoft.AspNetCore.Protocols; -using Microsoft.AspNetCore.Protocols.Features; +using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Sockets.Internal; using Microsoft.AspNetCore.Sockets.Internal.Transports; using Microsoft.Extensions.Logging; @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Sockets _logger = _loggerFactory.CreateLogger(); } - public async Task ExecuteAsync(HttpContext context, HttpSocketOptions options, ConnectionDelegate connectionDelegate) + public async Task ExecuteAsync(HttpContext context, HttpConnectionOptions options, ConnectionDelegate connectionDelegate) { // Create the log scope and attempt to pass the Connection ID to it so as many logs as possible contain // the Connection ID metadata. If this is the negotiate request then the Connection ID for the scope will @@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Sockets else if (HttpMethods.IsGet(context.Request.Method)) { // GET /{path} - await ExecuteEndpointAsync(context, connectionDelegate, options, logScope); + await ExecuteAsync(context, connectionDelegate, options, logScope); } else { @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Sockets } } - public async Task ExecuteNegotiateAsync(HttpContext context, HttpSocketOptions options) + public async Task ExecuteNegotiateAsync(HttpContext context, HttpConnectionOptions options) { // Create the log scope and the scope connectionId param will be set when the connection is created. var logScope = new ConnectionLogScope(connectionId: string.Empty); @@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.Sockets } } - private async Task ExecuteEndpointAsync(HttpContext context, ConnectionDelegate connectionDelegate, HttpSocketOptions options, ConnectionLogScope logScope) + private async Task ExecuteAsync(HttpContext context, ConnectionDelegate connectionDelegate, HttpConnectionOptions options, ConnectionLogScope logScope) { var supportedTransports = options.Transports; @@ -356,7 +356,7 @@ namespace Microsoft.AspNetCore.Sockets await connectionDelegate(connection); } - private Task ProcessNegotiate(HttpContext context, HttpSocketOptions options, ConnectionLogScope logScope) + private Task ProcessNegotiate(HttpContext context, HttpConnectionOptions options, ConnectionLogScope logScope) { context.Response.ContentType = "application/json"; @@ -377,7 +377,7 @@ namespace Microsoft.AspNetCore.Sockets return context.Response.Body.WriteAsync(negotiateResponseBuffer, 0, negotiateResponseBuffer.Length); } - private static string GetNegotiatePayload(string connectionId, HttpContext context, HttpSocketOptions options) + private static string GetNegotiatePayload(string connectionId, HttpContext context, HttpConnectionOptions options) { var sb = new StringBuilder(); using (var jsonWriter = new JsonTextWriter(new StringWriter(sb))) @@ -441,7 +441,7 @@ namespace Microsoft.AspNetCore.Sockets private static string GetConnectionId(HttpContext context) => context.Request.Query["id"]; - private async Task ProcessSend(HttpContext context, HttpSocketOptions options) + private async Task ProcessSend(HttpContext context, HttpConnectionOptions options) { var connection = await GetConnectionAsync(context, options); if (connection == null) @@ -471,7 +471,7 @@ namespace Microsoft.AspNetCore.Sockets await connection.Application.Output.FlushAsync(); } - private async Task EnsureConnectionStateAsync(DefaultConnectionContext connection, HttpContext context, TransportType transportType, TransportType supportedTransports, ConnectionLogScope logScope, HttpSocketOptions options) + private async Task EnsureConnectionStateAsync(DefaultConnectionContext connection, HttpContext context, TransportType transportType, TransportType supportedTransports, ConnectionLogScope logScope, HttpConnectionOptions options) { if ((supportedTransports & transportType) == 0) { @@ -596,7 +596,7 @@ namespace Microsoft.AspNetCore.Sockets return newHttpContext; } - private async Task GetConnectionAsync(HttpContext context, HttpSocketOptions options) + private async Task GetConnectionAsync(HttpContext context, HttpConnectionOptions options) { var connectionId = GetConnectionId(context); @@ -623,7 +623,7 @@ namespace Microsoft.AspNetCore.Sockets return connection; } - private void EnsureConnectionStateInternal(DefaultConnectionContext connection, HttpSocketOptions options) + private void EnsureConnectionStateInternal(DefaultConnectionContext connection, HttpConnectionOptions options) { // If the connection doesn't have a pipe yet then create one, we lazily create the pipe to save on allocations until the client actually connects if (connection.Transport == null) @@ -637,7 +637,7 @@ namespace Microsoft.AspNetCore.Sockets } // This is only used for WebSockets connections, which can connect directly without negotiating - private async Task GetOrCreateConnectionAsync(HttpContext context, HttpSocketOptions options) + private async Task GetOrCreateConnectionAsync(HttpContext context, HttpConnectionOptions options) { var connectionId = GetConnectionId(context); DefaultConnectionContext connection; diff --git a/src/Microsoft.AspNetCore.Sockets.Http/HttpSocketOptions.cs b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionOptions.cs similarity index 95% rename from src/Microsoft.AspNetCore.Sockets.Http/HttpSocketOptions.cs rename to src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionOptions.cs index ffc61d563f..c4ac05b09e 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/HttpSocketOptions.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionOptions.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Authorization; namespace Microsoft.AspNetCore.Sockets { - public class HttpSocketOptions + public class HttpConnectionOptions { public IList AuthorizationData { get; } = new List(); diff --git a/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/WebSocketsTransport.cs b/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/WebSocketsTransport.cs index 248c2993be..f86102228f 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/WebSocketsTransport.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/WebSocketsTransport.cs @@ -9,7 +9,7 @@ using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Sockets.Internal.Transports diff --git a/src/Microsoft.AspNetCore.Sockets.Http/SocketRouteBuilder.cs b/src/Microsoft.AspNetCore.Sockets.Http/SocketRouteBuilder.cs deleted file mode 100644 index 1afac841a2..0000000000 --- a/src/Microsoft.AspNetCore.Sockets.Http/SocketRouteBuilder.cs +++ /dev/null @@ -1,65 +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.Http; -using Microsoft.AspNetCore.Protocols; -using Microsoft.AspNetCore.Routing; - -namespace Microsoft.AspNetCore.Sockets -{ - public class SocketRouteBuilder - { - private readonly HttpConnectionDispatcher _dispatcher; - private readonly RouteBuilder _routes; - - public SocketRouteBuilder(RouteBuilder routes, HttpConnectionDispatcher dispatcher) - { - _routes = routes; - _dispatcher = dispatcher; - } - - public void MapSocket(string path, Action socketConfig) => - MapSocket(new PathString(path), new HttpSocketOptions(), socketConfig); - - public void MapSocket(PathString path, Action socketConfig) => - MapSocket(path, new HttpSocketOptions(), socketConfig); - - public void MapSocket(PathString path, HttpSocketOptions options, Action connectionConfig) - { - var connectionBuilder = new ConnectionBuilder(_routes.ServiceProvider); - connectionConfig(connectionBuilder); - var socket = connectionBuilder.Build(); - _routes.MapRoute(path, c => _dispatcher.ExecuteAsync(c, options, socket)); - _routes.MapRoute(path + "/negotiate", c => _dispatcher.ExecuteNegotiateAsync(c, options)); - } - - public void MapEndPoint(string path) where TEndPoint : EndPoint - { - MapEndPoint(new PathString(path), socketOptions: null); - } - - public void MapEndPoint(PathString path) where TEndPoint : EndPoint - { - MapEndPoint(path, socketOptions: null); - } - - public void MapEndPoint(PathString path, Action socketOptions) where TEndPoint : EndPoint - { - var authorizeAttributes = typeof(TEndPoint).GetCustomAttributes(inherit: true); - var options = new HttpSocketOptions(); - foreach (var attribute in authorizeAttributes) - { - options.AuthorizationData.Add(attribute); - } - socketOptions?.Invoke(options); - - MapSocket(path, options, builder => - { - builder.UseEndPoint(); - }); - } - } -} diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.AbortAsync.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.AbortAsync.cs index 349d5db667..20b9d457d5 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.AbortAsync.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.AbortAsync.cs @@ -3,7 +3,7 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Sockets; using Xunit; diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.ConnectionLifecycle.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.ConnectionLifecycle.cs index bff6c5b0af..310e777db2 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.ConnectionLifecycle.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.ConnectionLifecycle.cs @@ -6,7 +6,7 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNetCore.Client.Tests; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets.Client; using Microsoft.Extensions.Logging.Testing; diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.Negotiate.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.Negotiate.cs index 5e04044fa5..cdf3921efb 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.Negotiate.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.Negotiate.cs @@ -5,7 +5,7 @@ using System; using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Client.Tests; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets.Client; using Moq; diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.OnReceived.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.OnReceived.cs index 56b7b03fe3..3f71fe400b 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.OnReceived.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.OnReceived.cs @@ -6,7 +6,7 @@ using System.Net; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Client.Tests; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Sockets; using Xunit; diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.SendAsync.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.SendAsync.cs index a59fc103dd..968be6b051 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.SendAsync.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.SendAsync.cs @@ -6,7 +6,7 @@ using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNetCore.Client.Tests; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Sockets; using Xunit; diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.cs index 9c76472215..613b892ffb 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.cs @@ -9,7 +9,7 @@ using System.Security.Cryptography.X509Certificates; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Client.Tests; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Sockets.Client; using Microsoft.AspNetCore.Sockets.Client.Http; using Microsoft.Extensions.Logging; diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs index ff77652f34..8206aa4dfd 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.SignalR.Internal; using Microsoft.AspNetCore.SignalR.Internal.Protocol; using Microsoft.AspNetCore.Sockets.Client; diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/LongPollingTransportTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/LongPollingTransportTests.cs index 2a76e1b37a..658a4e16f4 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/LongPollingTransportTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/LongPollingTransportTests.cs @@ -13,7 +13,7 @@ using System.Text; using System.Threading; using System.Threading.Channels; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.SignalR.Client.Tests; using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets.Client; diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/ResponseUtils.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/ResponseUtils.cs index 5a3df4bed2..9734282c1a 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/ResponseUtils.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/ResponseUtils.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.Net; using System.Net.Http; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Sockets; using Newtonsoft.Json; using SocketsTransportType = Microsoft.AspNetCore.Sockets.TransportType; diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/ServerSentEventsTransportTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/ServerSentEventsTransportTests.cs index a4955dbf48..1d684ae82f 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/ServerSentEventsTransportTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/ServerSentEventsTransportTests.cs @@ -13,7 +13,7 @@ using System.Threading; using System.Threading.Channels; using System.Threading.Tasks; using Microsoft.AspNetCore.Client.Tests; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets.Client; using Microsoft.AspNetCore.Sockets.Client.Http; diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestConnection.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestConnection.cs index 20ef8418a3..c2ffc164e4 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestConnection.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestConnection.cs @@ -9,7 +9,7 @@ using System.Threading; using System.Threading.Channels; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.SignalR.Internal.Formatters; using Microsoft.AspNetCore.SignalR.Internal.Protocol; using Microsoft.AspNetCore.Sockets.Client; diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestTransport.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestTransport.cs index 8e0c327771..1c35dedb6f 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestTransport.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestTransport.cs @@ -1,7 +1,7 @@ using System; using System.IO.Pipelines; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets.Client; diff --git a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/HubConnectionContextUtils.cs b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/HubConnectionContextUtils.cs index 88558e705b..d49e1f67ca 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/HubConnectionContextUtils.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/HubConnectionContextUtils.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.SignalR.Internal; using Microsoft.AspNetCore.SignalR.Internal.Protocol; using Microsoft.AspNetCore.Sockets; diff --git a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/TestClient.cs b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/TestClient.cs index d3c82332c0..e4c6669446 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/TestClient.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/TestClient.cs @@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests } public async Task ConnectAsync( - EndPoint endPoint, + Connections.ConnectionHandler handler, bool sendHandshakeRequestMessage = true, bool expectedHandshakeResponseMessage = true) { @@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests } } - var connection = endPoint.OnConnectedAsync(Connection); + var connection = handler.OnConnectedAsync(Connection); if (expectedHandshakeResponseMessage) { diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/EchoEndPoint.cs b/test/Microsoft.AspNetCore.SignalR.Tests/EchoConnectionHandler.cs similarity index 89% rename from test/Microsoft.AspNetCore.SignalR.Tests/EchoEndPoint.cs rename to test/Microsoft.AspNetCore.SignalR.Tests/EchoConnectionHandler.cs index b7bedecc60..f9367ca2c6 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/EchoEndPoint.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/EchoConnectionHandler.cs @@ -4,12 +4,12 @@ using System.Buffers; using System.IO.Pipelines; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Sockets; namespace Microsoft.AspNetCore.SignalR.Tests { - public class EchoEndPoint : EndPoint + public class EchoConnectionHandler : ConnectionHandler { public override async Task OnConnectedAsync(ConnectionContext connection) { diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs index 23113b6298..e51ba6489e 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/EndToEndTests.cs @@ -9,7 +9,7 @@ using System.Net.WebSockets; using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.SignalR.Client; using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets.Client; @@ -215,7 +215,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests catch (OperationCanceledException) { // Because the server and client are run in the same process there is a race where websocket.SendAsync - // can send a message but before returning be suspended allowing the server to run the EchoEndpoint and + // can send a message but before returning be suspended allowing the server to run the EchoConnectionHandler and // send a close frame which triggers a cancellation token on the client and cancels the websocket.SendAsync. // Our solution to this is to just catch OperationCanceledException from the sent message if the race happens // because we know the send went through, and its safe to check the response. diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/HttpHeaderEndPoint.cs b/test/Microsoft.AspNetCore.SignalR.Tests/HttpHeaderConnectionHandler.cs similarity index 92% rename from test/Microsoft.AspNetCore.SignalR.Tests/HttpHeaderEndPoint.cs rename to test/Microsoft.AspNetCore.SignalR.Tests/HttpHeaderConnectionHandler.cs index 7fb3de2d05..7b6879f452 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/HttpHeaderEndPoint.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/HttpHeaderConnectionHandler.cs @@ -7,13 +7,13 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets.Http.Features; namespace Microsoft.AspNetCore.SignalR.Tests { - public class HttpHeaderEndPoint : EndPoint + public class HttpHeaderConnectionHandler : ConnectionHandler { public override async Task OnConnectedAsync(ConnectionContext connection) { diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/HubEndpointTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/HubConnectionHandlerTests.cs similarity index 71% rename from test/Microsoft.AspNetCore.SignalR.Tests/HubEndpointTests.cs rename to test/Microsoft.AspNetCore.SignalR.Tests/HubConnectionHandlerTests.cs index 7c44ffe8d4..1c5d3ba899 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/HubEndpointTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/HubConnectionHandlerTests.cs @@ -10,10 +10,10 @@ using System.Security.Claims; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.SignalR.Internal; using Microsoft.AspNetCore.SignalR.Internal.Protocol; -using Microsoft.AspNetCore.SignalR.Tests.HubEndpointTestUtils; +using Microsoft.AspNetCore.SignalR.Tests; using Microsoft.AspNetCore.Sockets; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; @@ -27,23 +27,23 @@ using Xunit; namespace Microsoft.AspNetCore.SignalR.Tests { - public class HubEndpointTests + public class HubConnectionHandlerTests { [Fact] public async Task HubsAreDisposed() { var trackDispose = new TrackDispose(); - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(s => s.AddSingleton(trackDispose)); - var endPoint = serviceProvider.GetService>(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(s => s.AddSingleton(trackDispose)); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); // kill the connection client.Dispose(); - await endPointTask; + await connectionHandlerTask; Assert.Equal(2, trackDispose.DisposeCount); } @@ -53,17 +53,17 @@ namespace Microsoft.AspNetCore.SignalR.Tests public async Task ConnectionAbortedTokenTriggers() { var state = new ConnectionLifetimeState(); - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(s => s.AddSingleton(state)); - var endPoint = serviceProvider.GetService>(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(s => s.AddSingleton(state)); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); // kill the connection client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); Assert.True(state.TokenCallbackTriggered); Assert.False(state.TokenStateInConnected); @@ -74,16 +74,16 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task AbortFromHubMethodForcesClientDisconnect() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); await client.InvokeAsync(nameof(AbortHub.Kill)); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } @@ -91,8 +91,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests public async Task ObservableHubRemovesSubscriptionsWithInfiniteStreams() { var observable = new Observable(); - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(s => s.AddSingleton(observable)); - var endPoint = serviceProvider.GetService>(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(s => s.AddSingleton(observable)); + var connectionHandler = serviceProvider.GetService>(); var waitForSubscribe = new TaskCompletionSource(); observable.OnSubscribe = o => @@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); async Task Produce() { @@ -146,7 +146,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests Assert.Empty(observable.Observers); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } @@ -154,8 +154,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests public async Task ObservableHubRemovesSubscriptions() { var observable = new Observable(); - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(s => s.AddSingleton(observable)); - var endPoint = serviceProvider.GetService>(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(s => s.AddSingleton(observable)); + var connectionHandler = serviceProvider.GetService>(); var waitForSubscribe = new TaskCompletionSource(); observable.OnSubscribe = o => @@ -171,7 +171,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); async Task Subscribe() { @@ -205,7 +205,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests Assert.Empty(observable.Observers); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } @@ -213,8 +213,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests public async Task ObservableHubRemovesSubscriptionWhenCanceledFromClient() { var observable = new Observable(); - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(s => s.AddSingleton(observable)); - var endPoint = serviceProvider.GetService>(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(s => s.AddSingleton(observable)); + var connectionHandler = serviceProvider.GetService>(); var waitForSubscribe = new TaskCompletionSource(); observable.OnSubscribe = o => @@ -230,7 +230,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); var invocationId = await client.SendStreamInvocationAsync(nameof(ObservableHub.Subscribe)).OrTimeout(); @@ -246,24 +246,24 @@ namespace Microsoft.AspNetCore.SignalR.Tests client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task MissingHandshakeAndMessageSentFromHubConnectionCanBeDisposedCleanly() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint, false, false); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler, false, false); // kill the connection client.Dispose(); - await endPointTask; + await connectionHandlerTask; Assert.Null(client.HandshakeResponseMessage); } @@ -272,30 +272,30 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task HandshakeTimesOut() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(services => + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(services => { services.Configure(options => { options.HandshakeTimeout = TimeSpan.FromMilliseconds(5); }); }); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint, false); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler, false); Assert.NotNull(client.HandshakeResponseMessage); Assert.Equal("Handshake was canceled.", client.HandshakeResponseMessage.Error); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task CanLoadHubContext() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); var context = serviceProvider.GetRequiredService>(); await context.Clients.All.SendAsync("Send", "test"); } @@ -303,7 +303,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task CanLoadTypedHubContext() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); var context = serviceProvider.GetRequiredService>(); await context.Clients.All.Send("test"); } @@ -314,18 +314,18 @@ namespace Microsoft.AspNetCore.SignalR.Tests var hubProtocolMock = new Mock(); hubProtocolMock.Setup(m => m.Name).Returns("CustomProtocol"); - var endPoint = HubEndPointTestUtils.GetHubEndpoint(typeof(HubT)); + var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(typeof(HubT)); using (var client = new TestClient(protocol: hubProtocolMock.Object)) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); Assert.NotNull(client.HandshakeResponseMessage); Assert.Equal("The protocol 'CustomProtocol' is not supported.", client.HandshakeResponseMessage.Error); client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } @@ -335,38 +335,38 @@ namespace Microsoft.AspNetCore.SignalR.Tests var hubProtocolMock = new Mock(); hubProtocolMock.Setup(m => m.Name).Returns("CustomProtocol"); - var endPoint = HubEndPointTestUtils.GetHubEndpoint(typeof(HubT)); + var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(typeof(HubT)); using (var client = new TestClient(protocol: new MessagePackHubProtocol())) { client.Connection.SupportedFormats = TransferFormat.Text; - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); Assert.NotNull(client.HandshakeResponseMessage); Assert.Equal("Cannot use the 'messagepack' protocol on the current transport. The transport does not support 'Binary' transfer format.", client.HandshakeResponseMessage.Error); client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task HandshakeSuccessSendsResponseWithoutError() { - var endPoint = HubEndPointTestUtils.GetHubEndpoint(typeof(HubT)); + var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(typeof(HubT)); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); Assert.NotNull(client.HandshakeResponseMessage); Assert.Null(client.HandshakeResponseMessage.Error); client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } @@ -377,18 +377,18 @@ namespace Microsoft.AspNetCore.SignalR.Tests hubProtocolMock.Setup(m => m.Name).Returns("json"); hubProtocolMock.Setup(m => m.Version).Returns(9001); - var endPoint = HubEndPointTestUtils.GetHubEndpoint(typeof(HubT)); + var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(typeof(HubT)); using (var client = new TestClient(protocol: hubProtocolMock.Object)) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); Assert.NotNull(client.HandshakeResponseMessage); Assert.Equal("The server does not support version 9001 of the 'json' protocol.", client.HandshakeResponseMessage.Error); client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } @@ -401,13 +401,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests .Throws(new InvalidOperationException("Lifetime manager OnConnectedAsync failed.")); var mockHubActivator = new Mock>(); - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(services => + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(services => { services.AddSingleton(mockLifetimeManager.Object); services.AddSingleton(mockHubActivator.Object); }); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { @@ -415,8 +415,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests await Assert.ThrowsAsync( async () => { - var endPointTask = await client.ConnectAsync(endPoint); - await endPointTask.OrTimeout(); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); + await connectionHandlerTask.OrTimeout(); }); Assert.Equal("Lifetime manager OnConnectedAsync failed.", exception.Message); @@ -434,19 +434,19 @@ namespace Microsoft.AspNetCore.SignalR.Tests public async Task HubOnDisconnectedAsyncCalledIfHubOnConnectedAsyncThrows() { var mockLifetimeManager = new Mock>(); - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(services => + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(services => { services.AddSingleton(mockLifetimeManager.Object); }); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); mockLifetimeManager.Verify(m => m.OnConnectedAsync(It.IsAny()), Times.Once); mockLifetimeManager.Verify(m => m.OnDisconnectedAsync(It.IsAny()), Times.Once); @@ -457,19 +457,19 @@ namespace Microsoft.AspNetCore.SignalR.Tests public async Task LifetimeManagerOnDisconnectedAsyncCalledIfHubOnDisconnectedAsyncThrows() { var mockLifetimeManager = new Mock>(); - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(services => + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(services => { services.AddSingleton(mockLifetimeManager.Object); }); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); client.Dispose(); - var exception = await Assert.ThrowsAsync(async () => await endPointTask); + var exception = await Assert.ThrowsAsync(async () => await connectionHandlerTask); Assert.Equal("Hub OnDisconnected failed.", exception.Message); mockLifetimeManager.Verify(m => m.OnConnectedAsync(It.IsAny()), Times.Once); @@ -480,13 +480,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task HubMethodCanReturnValueFromTask() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); var result = (await client.InvokeAsync(nameof(MethodHub.TaskValueMethod)).OrTimeout()).Result; @@ -496,7 +496,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests // kill the connection client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } @@ -504,11 +504,11 @@ namespace Microsoft.AspNetCore.SignalR.Tests [MemberData(nameof(HubTypes))] public async Task HubMethodsAreCaseInsensitive(Type hubType) { - var endPoint = HubEndPointTestUtils.GetHubEndpoint(hubType); + var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(hubType); using (var client = new TestClient()) { - var endPointTask = (Task)await client.ConnectAsync(endPoint); + var connectionHandlerTask = (Task)await client.ConnectAsync(connectionHandler); var result = (await client.InvokeAsync("echo", "hello").OrTimeout()).Result; @@ -517,7 +517,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests // kill the connection client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } @@ -526,13 +526,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests [InlineData(nameof(MethodHub.MethodThatYieldsFailedTask))] public async Task HubMethodCanThrowOrYieldFailedTask(string methodName) { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); var message = await client.InvokeAsync(methodName).OrTimeout(); @@ -541,20 +541,20 @@ namespace Microsoft.AspNetCore.SignalR.Tests // kill the connection client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task HubMethodDoesNotSendResultWhenInvocationIsNonBlocking() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); await client.SendInvocationAsync(nameof(MethodHub.ValueMethod), nonBlocking: true).OrTimeout(); @@ -572,20 +572,20 @@ namespace Microsoft.AspNetCore.SignalR.Tests break; } - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task HubMethodCanBeVoid() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); var result = (await client.InvokeAsync(nameof(MethodHub.VoidMethod)).OrTimeout()).Result; @@ -594,20 +594,20 @@ namespace Microsoft.AspNetCore.SignalR.Tests // kill the connection client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task HubMethodCanBeRenamedWithAttribute() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); var result = (await client.InvokeAsync("RenamedMethod").OrTimeout()).Result; @@ -617,20 +617,20 @@ namespace Microsoft.AspNetCore.SignalR.Tests // kill the connection client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task HubMethodNameAttributeIsInherited() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); var result = (await client.InvokeAsync("RenamedVirtualMethod").OrTimeout()).Result; @@ -640,7 +640,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests // kill the connection client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } @@ -650,13 +650,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests [InlineData(nameof(MethodHub.ValueMethod))] public async Task NonBlockingInvocationDoesNotSendCompletion(string methodName) { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient(synchronousCallbacks: true)) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); // This invocation should be completely synchronous await client.SendInvocationAsync(methodName, nonBlocking: true).OrTimeout(); @@ -668,20 +668,20 @@ namespace Microsoft.AspNetCore.SignalR.Tests var closeMessage = await client.ReadAsync().OrTimeout(); Assert.IsType(closeMessage); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task HubMethodWithMultiParam() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); var result = (await client.InvokeAsync(nameof(MethodHub.ConcatString), (byte)32, 42, 'm', "string").OrTimeout()).Result; @@ -690,20 +690,20 @@ namespace Microsoft.AspNetCore.SignalR.Tests // kill the connection client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task CanCallInheritedHubMethodFromInheritingHub() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); var result = (await client.InvokeAsync(nameof(InheritedHub.BaseMethod), "string").OrTimeout()).Result; @@ -712,20 +712,20 @@ namespace Microsoft.AspNetCore.SignalR.Tests // kill the connection client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task CanCallOverridenVirtualHubMethod() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); var result = (await client.InvokeAsync(nameof(InheritedHub.VirtualMethod), 10).OrTimeout()).Result; @@ -734,20 +734,20 @@ namespace Microsoft.AspNetCore.SignalR.Tests // kill the connection client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task CannotCallOverriddenBaseHubMethod() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); var result = await client.InvokeAsync(nameof(MethodHub.OnDisconnectedAsync)).OrTimeout(); @@ -756,18 +756,18 @@ namespace Microsoft.AspNetCore.SignalR.Tests // kill the connection client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public void HubsCannotHaveOverloadedMethods() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); try { - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); Assert.True(false); } catch (NotSupportedException ex) @@ -779,13 +779,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task CannotCallStaticHubMethods() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); var result = await client.InvokeAsync(nameof(MethodHub.StaticMethod)).OrTimeout(); @@ -794,20 +794,20 @@ namespace Microsoft.AspNetCore.SignalR.Tests // kill the connection client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task CannotCallObjectMethodsOnHub() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); var result = await client.InvokeAsync(nameof(MethodHub.ToString)).OrTimeout(); Assert.Equal("Unknown hub method 'ToString'", result.Error); @@ -824,20 +824,20 @@ namespace Microsoft.AspNetCore.SignalR.Tests // kill the connection client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task CannotCallDisposeMethodOnHub() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); var result = await client.InvokeAsync(nameof(MethodHub.Dispose)).OrTimeout(); @@ -846,7 +846,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests // kill the connection client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } @@ -854,13 +854,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests [MemberData(nameof(HubTypes))] public async Task BroadcastHubMethodSendsToAllClients(Type hubType) { - var endPoint = HubEndPointTestUtils.GetHubEndpoint(hubType); + var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(hubType); using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstEndPointTask = await firstClient.ConnectAsync(endPoint); - Task secondEndPointTask = await secondClient.ConnectAsync(endPoint); + Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -880,22 +880,22 @@ namespace Microsoft.AspNetCore.SignalR.Tests firstClient.Dispose(); secondClient.Dispose(); - await Task.WhenAll(firstEndPointTask, secondEndPointTask).OrTimeout(); + await Task.WhenAll(firstConnectionHandlerTask, secondConnectionHandlerTask).OrTimeout(); } } [Fact] public async Task SendArraySendsArrayToAllClients() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstEndPointTask = await firstClient.ConnectAsync(endPoint); - Task secondEndPointTask = await secondClient.ConnectAsync(endPoint); + Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -916,7 +916,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests firstClient.Dispose(); secondClient.Dispose(); - await Task.WhenAll(firstEndPointTask, secondEndPointTask).OrTimeout(); + await Task.WhenAll(firstConnectionHandlerTask, secondConnectionHandlerTask).OrTimeout(); } } @@ -924,13 +924,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests [MemberData(nameof(HubTypes))] public async Task SendToOthers(Type hubType) { - var endPoint = HubEndPointTestUtils.GetHubEndpoint(hubType); + var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(hubType); using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstEndPointTask = await firstClient.ConnectAsync(endPoint); - Task secondEndPointTask = await secondClient.ConnectAsync(endPoint); + Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -954,7 +954,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests firstClient.Dispose(); secondClient.Dispose(); - await Task.WhenAll(firstEndPointTask, secondEndPointTask).OrTimeout(); + await Task.WhenAll(firstConnectionHandlerTask, secondConnectionHandlerTask).OrTimeout(); } @@ -964,13 +964,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests [MemberData(nameof(HubTypes))] public async Task SendToCaller(Type hubType) { - var endPoint = HubEndPointTestUtils.GetHubEndpoint(hubType); + var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(hubType); using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstEndPointTask = await firstClient.ConnectAsync(endPoint); - Task secondEndPointTask = await secondClient.ConnectAsync(endPoint); + Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -991,7 +991,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests firstClient.Dispose(); secondClient.Dispose(); - await Task.WhenAll(firstEndPointTask, secondEndPointTask).OrTimeout(); + await Task.WhenAll(firstConnectionHandlerTask, secondConnectionHandlerTask).OrTimeout(); } } @@ -999,15 +999,15 @@ namespace Microsoft.AspNetCore.SignalR.Tests [MemberData(nameof(HubTypes))] public async Task SendToAllExcept(Type hubType) { - var endPoint = HubEndPointTestUtils.GetHubEndpoint(hubType); + var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(hubType); using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) using (var thirdClient = new TestClient()) { - Task firstEndPointTask = await firstClient.ConnectAsync(endPoint); - Task secondEndPointTask = await secondClient.ConnectAsync(endPoint); - Task thirdEndPointTask = await thirdClient.ConnectAsync(endPoint); + Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); + Task thirdConnectionHandlerTask = await thirdClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected, thirdClient.Connected).OrTimeout(); @@ -1034,7 +1034,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests secondClient.Dispose(); thirdClient.Dispose(); - await Task.WhenAll(firstEndPointTask, secondEndPointTask, thirdEndPointTask).OrTimeout(); + await Task.WhenAll(firstConnectionHandlerTask, secondConnectionHandlerTask, thirdConnectionHandlerTask).OrTimeout(); } } @@ -1042,15 +1042,15 @@ namespace Microsoft.AspNetCore.SignalR.Tests [MemberData(nameof(HubTypes))] public async Task SendToMultipleClients(Type hubType) { - var endPoint = HubEndPointTestUtils.GetHubEndpoint(hubType); + var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(hubType); using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) using (var thirdClient = new TestClient()) { - Task firstEndPointTask = await firstClient.ConnectAsync(endPoint); - Task secondEndPointTask = await secondClient.ConnectAsync(endPoint); - Task thirdEndPointTask = await thirdClient.ConnectAsync(endPoint); + Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); + Task thirdConnectionHandlerTask = await thirdClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected, thirdClient.Connected).OrTimeout(); @@ -1079,7 +1079,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests secondClient.Dispose(); thirdClient.Dispose(); - await Task.WhenAll(firstEndPointTask, secondEndPointTask, thirdEndPointTask).OrTimeout(); + await Task.WhenAll(firstConnectionHandlerTask, secondConnectionHandlerTask, thirdConnectionHandlerTask).OrTimeout(); } } @@ -1087,15 +1087,15 @@ namespace Microsoft.AspNetCore.SignalR.Tests [MemberData(nameof(HubTypes))] public async Task SendToMultipleUsers(Type hubType) { - var endPoint = HubEndPointTestUtils.GetHubEndpoint(hubType); + var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(hubType); using (var firstClient = new TestClient(addClaimId: true)) using (var secondClient = new TestClient(addClaimId: true)) using (var thirdClient = new TestClient(addClaimId: true)) { - Task firstEndPointTask = await firstClient.ConnectAsync(endPoint); - Task secondEndPointTask = await secondClient.ConnectAsync(endPoint); - Task thirdEndPointTask = await thirdClient.ConnectAsync(endPoint); + Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); + Task thirdConnectionHandlerTask = await thirdClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected, thirdClient.Connected).OrTimeout(); @@ -1124,7 +1124,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests secondClient.Dispose(); thirdClient.Dispose(); - await Task.WhenAll(firstEndPointTask, secondEndPointTask, thirdEndPointTask).OrTimeout(); + await Task.WhenAll(firstConnectionHandlerTask, secondConnectionHandlerTask, thirdConnectionHandlerTask).OrTimeout(); } } @@ -1132,13 +1132,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests [MemberData(nameof(HubTypes))] public async Task HubsCanAddAndSendToGroup(Type hubType) { - var endPoint = HubEndPointTestUtils.GetHubEndpoint(hubType); + var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(hubType); using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstEndPointTask = await firstClient.ConnectAsync(endPoint); - Task secondEndPointTask = await secondClient.ConnectAsync(endPoint); + Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -1165,7 +1165,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests firstClient.Dispose(); secondClient.Dispose(); - await Task.WhenAll(firstEndPointTask, secondEndPointTask).OrTimeout(); + await Task.WhenAll(firstConnectionHandlerTask, secondConnectionHandlerTask).OrTimeout(); } } @@ -1173,13 +1173,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests [MemberData(nameof(HubTypes))] public async Task SendToGroupExcept(Type hubType) { - var endPoint = HubEndPointTestUtils.GetHubEndpoint(hubType); + var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(hubType); using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstEndPointTask = await firstClient.ConnectAsync(endPoint); - Task secondEndPointTask = await secondClient.ConnectAsync(endPoint); + Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -1215,7 +1215,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests firstClient.Dispose(); secondClient.Dispose(); - await Task.WhenAll(firstEndPointTask, secondEndPointTask).OrTimeout(); + await Task.WhenAll(firstConnectionHandlerTask, secondConnectionHandlerTask).OrTimeout(); } } @@ -1223,13 +1223,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests [MemberData(nameof(HubTypes))] public async Task SendToOthersInGroup(Type hubType) { - var endPoint = HubEndPointTestUtils.GetHubEndpoint(hubType); + var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(hubType); using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstEndPointTask = await firstClient.ConnectAsync(endPoint); - Task secondEndPointTask = await secondClient.ConnectAsync(endPoint); + Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -1263,7 +1263,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests firstClient.Dispose(); secondClient.Dispose(); - await Task.WhenAll(firstEndPointTask, secondEndPointTask).OrTimeout(); + await Task.WhenAll(firstConnectionHandlerTask, secondConnectionHandlerTask).OrTimeout(); } } @@ -1271,13 +1271,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests [MemberData(nameof(HubTypes))] public async Task InvokeMultipleGroups(Type hubType) { - var endPoint = HubEndPointTestUtils.GetHubEndpoint(hubType); + var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(hubType); using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstEndPointTask = await firstClient.ConnectAsync(endPoint); - Task secondEndPointTask = await secondClient.ConnectAsync(endPoint); + Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -1303,27 +1303,27 @@ namespace Microsoft.AspNetCore.SignalR.Tests firstClient.Dispose(); secondClient.Dispose(); - await Task.WhenAll(firstEndPointTask, secondEndPointTask).OrTimeout(); + await Task.WhenAll(firstConnectionHandlerTask, secondConnectionHandlerTask).OrTimeout(); } } [Fact] public async Task RemoveFromGroupWhenNotInGroupDoesNotFail() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); await client.SendInvocationAsync(nameof(MethodHub.GroupRemoveMethod), "testGroup").OrTimeout(); // kill the connection client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } @@ -1331,13 +1331,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests [MemberData(nameof(HubTypes))] public async Task HubsCanSendToUser(Type hubType) { - var endPoint = HubEndPointTestUtils.GetHubEndpoint(hubType); + var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(hubType); using (var firstClient = new TestClient(addClaimId: true)) using (var secondClient = new TestClient(addClaimId: true)) { - Task firstEndPointTask = await firstClient.ConnectAsync(endPoint); - Task secondEndPointTask = await secondClient.ConnectAsync(endPoint); + Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -1354,7 +1354,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests firstClient.Dispose(); secondClient.Dispose(); - await Task.WhenAll(firstEndPointTask, secondEndPointTask).OrTimeout(); + await Task.WhenAll(firstConnectionHandlerTask, secondConnectionHandlerTask).OrTimeout(); } } @@ -1362,13 +1362,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests [MemberData(nameof(HubTypes))] public async Task HubsCanSendToConnection(Type hubType) { - var endPoint = HubEndPointTestUtils.GetHubEndpoint(hubType); + var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(hubType); using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstEndPointTask = await firstClient.ConnectAsync(endPoint); - Task secondEndPointTask = await secondClient.ConnectAsync(endPoint); + Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -1385,20 +1385,20 @@ namespace Microsoft.AspNetCore.SignalR.Tests firstClient.Dispose(); secondClient.Dispose(); - await Task.WhenAll(firstEndPointTask, secondEndPointTask).OrTimeout(); + await Task.WhenAll(firstConnectionHandlerTask, secondConnectionHandlerTask).OrTimeout(); } } [Fact] public async Task DelayedSendTest() { - var endPoint = HubEndPointTestUtils.GetHubEndpoint(typeof(HubT)); + var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(typeof(HubT)); using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstEndPointTask = await firstClient.ConnectAsync(endPoint); - Task secondEndPointTask = await secondClient.ConnectAsync(endPoint); + Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -1415,7 +1415,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests firstClient.Dispose(); secondClient.Dispose(); - await Task.WhenAll(firstEndPointTask, secondEndPointTask).OrTimeout(); + await Task.WhenAll(firstConnectionHandlerTask, secondConnectionHandlerTask).OrTimeout(); } } @@ -1423,8 +1423,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests [MemberData(nameof(StreamingMethodAndHubProtocols))] public async Task HubsCanStreamResponses(string method, IHubProtocol protocol) { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); + var connectionHandler = serviceProvider.GetService>(); var invocationBinder = new Mock(); invocationBinder.Setup(b => b.GetReturnType(It.IsAny())).Returns(typeof(string)); @@ -1432,35 +1432,35 @@ namespace Microsoft.AspNetCore.SignalR.Tests { client.Connection.SupportedFormats = protocol.TransferFormat; - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); // Wait for a connection, or for the endpoint to fail. - await client.Connected.OrThrowIfOtherFails(endPointTask).OrTimeout(); + await client.Connected.OrThrowIfOtherFails(connectionHandlerTask).OrTimeout(); var messages = await client.StreamAsync(method, 4).OrTimeout(); Assert.Equal(5, messages.Count); - HubEndPointTestUtils.AssertHubMessage(new StreamItemMessage(string.Empty, "0"), messages[0]); - HubEndPointTestUtils.AssertHubMessage(new StreamItemMessage(string.Empty, "1"), messages[1]); - HubEndPointTestUtils.AssertHubMessage(new StreamItemMessage(string.Empty, "2"), messages[2]); - HubEndPointTestUtils.AssertHubMessage(new StreamItemMessage(string.Empty, "3"), messages[3]); - HubEndPointTestUtils.AssertHubMessage(CompletionMessage.Empty(string.Empty), messages[4]); + HubConnectionHandlerTestUtils.AssertHubMessage(new StreamItemMessage(string.Empty, "0"), messages[0]); + HubConnectionHandlerTestUtils.AssertHubMessage(new StreamItemMessage(string.Empty, "1"), messages[1]); + HubConnectionHandlerTestUtils.AssertHubMessage(new StreamItemMessage(string.Empty, "2"), messages[2]); + HubConnectionHandlerTestUtils.AssertHubMessage(new StreamItemMessage(string.Empty, "3"), messages[3]); + HubConnectionHandlerTestUtils.AssertHubMessage(CompletionMessage.Empty(string.Empty), messages[4]); client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task NonErrorCompletionSentWhenStreamCanceledFromClient() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); await client.Connected.OrTimeout(); @@ -1477,19 +1477,19 @@ namespace Microsoft.AspNetCore.SignalR.Tests client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task ReceiveCorrectErrorFromStreamThrowing() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); await client.Connected.OrTimeout(); @@ -1502,21 +1502,21 @@ namespace Microsoft.AspNetCore.SignalR.Tests client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task CanSendToConnectionsWithDifferentProtocols() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); + var connectionHandler = serviceProvider.GetService>(); using (var client1 = new TestClient(protocol: new JsonHubProtocol())) using (var client2 = new TestClient(protocol: new MessagePackHubProtocol())) { - Task firstEndPointTask = await client1.ConnectAsync(endPoint); - Task secondEndPointTask = await client2.ConnectAsync(endPoint); + Task firstConnectionHandlerTask = await client1.ConnectAsync(connectionHandler); + Task secondConnectionHandlerTask = await client2.ConnectAsync(connectionHandler); await client1.Connected.OrTimeout(); await client2.Connected.OrTimeout(); @@ -1538,8 +1538,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests client1.Dispose(); client2.Dispose(); - await firstEndPointTask.OrTimeout(); - await secondEndPointTask.OrTimeout(); + await firstConnectionHandlerTask.OrTimeout(); + await secondConnectionHandlerTask.OrTimeout(); } } @@ -1564,7 +1564,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task UnauthorizedConnectionCannotInvokeHubMethodWithAuthorization() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(services => + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(services => { services.AddAuthorization(options => { @@ -1576,11 +1576,11 @@ namespace Microsoft.AspNetCore.SignalR.Tests }); }); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); await client.Connected.OrTimeout(); @@ -1590,14 +1590,14 @@ namespace Microsoft.AspNetCore.SignalR.Tests client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task AuthorizedConnectionCanInvokeHubMethodWithAuthorization() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(services => + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(services => { services.AddAuthorization(options => { @@ -1609,12 +1609,12 @@ namespace Microsoft.AspNetCore.SignalR.Tests }); }); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { client.Connection.User.AddIdentity(new ClaimsIdentity(new[] { new Claim(ClaimTypes.NameIdentifier, "name") })); - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); await client.Connected.OrTimeout(); @@ -1624,14 +1624,14 @@ namespace Microsoft.AspNetCore.SignalR.Tests client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task HubOptionsCanUseCustomJsonSerializerSettings() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(services => + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(services => { services .AddSignalR() @@ -1644,11 +1644,11 @@ namespace Microsoft.AspNetCore.SignalR.Tests }); }); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); await client.Connected.OrTimeout(); @@ -1663,19 +1663,19 @@ namespace Microsoft.AspNetCore.SignalR.Tests client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task JsonHubProtocolUsesCamelCasingByDefault() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); await client.Connected.OrTimeout(); @@ -1690,14 +1690,14 @@ namespace Microsoft.AspNetCore.SignalR.Tests client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task HubOptionsCanUseCustomMessagePackSettings() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(services => + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(services => { services.AddSignalR() .AddMessagePackProtocol(options => @@ -1706,13 +1706,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests }); }); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); var msgPackOptions = serviceProvider.GetRequiredService>(); using (var client = new TestClient(synchronousCallbacks: false, protocol: new MessagePackHubProtocol(msgPackOptions))) { client.Connection.SupportedFormats = TransferFormat.Binary; - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); await client.Connected.OrTimeout(); @@ -1727,22 +1727,22 @@ namespace Microsoft.AspNetCore.SignalR.Tests client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task CanGetHttpContextFromHubConnectionContext() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { var httpContext = new DefaultHttpContext(); client.Connection.SetHttpContext(httpContext); - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); await client.Connected.OrTimeout(); @@ -1751,20 +1751,20 @@ namespace Microsoft.AspNetCore.SignalR.Tests client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task GetHttpContextFromHubConnectionContextHandlesNull() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient()) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); await client.Connected.OrTimeout(); @@ -1773,19 +1773,19 @@ namespace Microsoft.AspNetCore.SignalR.Tests client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task AcceptsPingMessages() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient(false, new JsonHubProtocol())) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); await client.Connected.OrTimeout(); // Send a ping @@ -1797,21 +1797,21 @@ namespace Microsoft.AspNetCore.SignalR.Tests client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } [Fact] public async Task DoesNotWritePingMessagesIfSufficientOtherMessagesAreSent() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(services => + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(services => services.Configure(options => options.KeepAliveInterval = TimeSpan.FromMilliseconds(100))); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient(false, new JsonHubProtocol())) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); await client.Connected.OrTimeout(); @@ -1826,7 +1826,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests // Shut down client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); client.Connection.Transport.Output.Complete(); @@ -1845,14 +1845,14 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task WritesPingMessageIfNothingWrittenWhenKeepAliveIntervalElapses() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(services => + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(services => services.Configure(options => options.KeepAliveInterval = TimeSpan.FromMilliseconds(100))); - var endPoint = serviceProvider.GetService>(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient(false, new JsonHubProtocol())) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); await client.Connected.OrTimeout(); // Wait 500 ms, but make sure to yield some time up to unblock concurrent threads @@ -1868,7 +1868,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests // Shut down client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); client.Connection.Transport.Output.Complete(); @@ -1903,19 +1903,19 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task EndingConnectionSendsCloseMessageWithNoError() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient(false, new JsonHubProtocol())) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); await client.Connected.OrTimeout(); // Shut down client.Dispose(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); client.Connection.Transport.Output.Complete(); @@ -1929,19 +1929,19 @@ namespace Microsoft.AspNetCore.SignalR.Tests [Fact] public async Task ErrorInHubOnConnectSendsCloseMessageWithError() { - var serviceProvider = HubEndPointTestUtils.CreateServiceProvider(); - var endPoint = serviceProvider.GetService>(); + var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(); + var connectionHandler = serviceProvider.GetService>(); using (var client = new TestClient(false, new JsonHubProtocol())) { - var endPointTask = await client.ConnectAsync(endPoint); + var connectionHandlerTask = await client.ConnectAsync(connectionHandler); var message = await client.ReadAsync().OrTimeout(); var closeMessage = Assert.IsType(message); Assert.Equal("Connection closed with an error. InvalidOperationException: Hub OnConnected failed.", closeMessage.Error); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); } } diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/HubEndpointTestUtils/Hubs.cs b/test/Microsoft.AspNetCore.SignalR.Tests/HubEndpointTestUtils/Hubs.cs index b78324bdc6..9954d749cf 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/HubEndpointTestUtils/Hubs.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/HubEndpointTestUtils/Hubs.cs @@ -9,7 +9,7 @@ using System.Threading.Channels; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; -namespace Microsoft.AspNetCore.SignalR.Tests.HubEndpointTestUtils +namespace Microsoft.AspNetCore.SignalR.Tests { public class MethodHub : TestHub { diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/HubEndpointTestUtils/Utils.cs b/test/Microsoft.AspNetCore.SignalR.Tests/HubEndpointTestUtils/Utils.cs index ba93ec8779..88c86a9bf9 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/HubEndpointTestUtils/Utils.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/HubEndpointTestUtils/Utils.cs @@ -7,14 +7,14 @@ using Microsoft.AspNetCore.Sockets; using Microsoft.Extensions.DependencyInjection; using Xunit; -namespace Microsoft.AspNetCore.SignalR.Tests.HubEndpointTestUtils +namespace Microsoft.AspNetCore.SignalR.Tests { - public class HubEndPointTestUtils + public class HubConnectionHandlerTestUtils { - public static Type GetEndPointType(Type hubType) + public static Type GetConnectionHandlerType(Type hubType) { - var endPointType = typeof(HubEndPoint<>); - return endPointType.MakeGenericType(hubType); + var connectionHandlerType = typeof(HubConnectionHandler<>); + return connectionHandlerType.MakeGenericType(hubType); } public static Type GetGenericType(Type genericType, Type hubType) @@ -65,10 +65,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests.HubEndpointTestUtils return services.BuildServiceProvider(); } - public static EndPoint GetHubEndpoint(Type hubType) + public static Connections.ConnectionHandler GetHubConnectionHandler(Type hubType) { var serviceProvider = CreateServiceProvider(); - return (EndPoint)serviceProvider.GetService(GetEndPointType(hubType)); + return (Connections.ConnectionHandler)serviceProvider.GetService(GetConnectionHandlerType(hubType)); } } diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/Internal/DefaultHubProtocolResolverTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/Internal/DefaultHubProtocolResolverTests.cs index db1ecae18c..be08340a26 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/Internal/DefaultHubProtocolResolverTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/Internal/DefaultHubProtocolResolverTests.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.SignalR.Internal; using Microsoft.AspNetCore.SignalR.Internal.Protocol; using Microsoft.Extensions.Logging.Abstractions; diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/MapSignalRTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/MapSignalRTests.cs index ec9811fe2b..3e28106832 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/MapSignalRTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/MapSignalRTests.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests { var ex = Assert.Throws(() => { - using (var builder = BuildWebHost(options => options.MapHub("/overloads"))) + using (var builder = BuildWebHost(routes => routes.MapHub("/overloads"))) { builder.Start(); } @@ -31,9 +31,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests .Configure(app => { var ex = Assert.Throws(() => { - app.UseSignalR(options => + app.UseSignalR(routes => { - options.MapHub("/overloads"); + routes.MapHub("/overloads"); }); }); @@ -47,9 +47,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests public void MapHubFindsAuthAttributeOnHub() { var authCount = 0; - using (var builder = BuildWebHost(options => options.MapHub("/path", httpSocketOptions => + using (var builder = BuildWebHost(routes => routes.MapHub("/path", options => { - authCount += httpSocketOptions.AuthorizationData.Count; + authCount += options.AuthorizationData.Count; }))) { builder.Start(); @@ -62,9 +62,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests public void MapHubFindsAuthAttributeOnInheritedHub() { var authCount = 0; - using (var builder = BuildWebHost(options => options.MapHub("/path", httpSocketOptions => + using (var builder = BuildWebHost(routes => routes.MapHub("/path", options => { - authCount += httpSocketOptions.AuthorizationData.Count; + authCount += options.AuthorizationData.Count; }))) { builder.Start(); @@ -77,9 +77,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests public void MapHubFindsMultipleAuthAttributesOnDoubleAuthHub() { var authCount = 0; - using (var builder = BuildWebHost(options => options.MapHub("/path", httpSocketOptions => + using (var builder = BuildWebHost(routes => routes.MapHub("/path", options => { - authCount += httpSocketOptions.AuthorizationData.Count; + authCount += options.AuthorizationData.Count; }))) { builder.Start(); diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/Startup.cs b/test/Microsoft.AspNetCore.SignalR.Tests/Startup.cs index cc98454e11..0cd9a6eece 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/Startup.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/Startup.cs @@ -11,16 +11,16 @@ namespace Microsoft.AspNetCore.SignalR.Tests { public void ConfigureServices(IServiceCollection services) { - services.AddSockets(); + services.AddConnections(); services.AddSignalR(); - services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { - app.UseSockets(options => options.MapEndPoint("/echo")); - app.UseSockets(options => options.MapEndPoint("/httpheader")); + app.UseConnections(options => options.MapConnectionHandler("/echo")); + app.UseConnections(options => options.MapConnectionHandler("/httpheader")); app.UseSignalR(options => options.MapHub("/uncreatable")); } } diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs index 7f9b589e79..fd229fed24 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs @@ -13,7 +13,7 @@ using System.Reflection; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets.Client; using Microsoft.AspNetCore.Sockets.Client.Http; diff --git a/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs b/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs index 9492d14947..b74e7a51dd 100644 --- a/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs +++ b/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs @@ -18,8 +18,8 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Internal; -using Microsoft.AspNetCore.Protocols; -using Microsoft.AspNetCore.Protocols.Features; +using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Testing; @@ -46,13 +46,13 @@ namespace Microsoft.AspNetCore.Sockets.Tests var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory); var context = new DefaultHttpContext(); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); services.AddOptions(); var ms = new MemoryStream(); context.Request.Path = "/foo"; context.Request.Method = "POST"; context.Response.Body = ms; - await dispatcher.ExecuteNegotiateAsync(context, new HttpSocketOptions()); + await dispatcher.ExecuteNegotiateAsync(context, new HttpConnectionOptions()); var negotiateResponse = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(ms.ToArray())); var connectionId = negotiateResponse.Value("connectionId"); Assert.True(manager.TryGetConnection(connectionId, out var connectionContext)); @@ -69,20 +69,20 @@ namespace Microsoft.AspNetCore.Sockets.Tests var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory); var context = new DefaultHttpContext(); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); services.AddOptions(); var ms = new MemoryStream(); context.Request.Path = "/foo"; context.Request.Method = "POST"; context.Response.Body = ms; - var httpSocketOptions = new HttpSocketOptions { TransportMaxBufferSize = 4, ApplicationMaxBufferSize = 4 }; - await dispatcher.ExecuteNegotiateAsync(context, httpSocketOptions); + var options = new HttpConnectionOptions { TransportMaxBufferSize = 4, ApplicationMaxBufferSize = 4 }; + await dispatcher.ExecuteNegotiateAsync(context, options); var negotiateResponse = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(ms.ToArray())); var connectionId = negotiateResponse.Value("connectionId"); context.Request.QueryString = context.Request.QueryString.Add("id", connectionId); Assert.True(manager.TryGetConnection(connectionId, out var connection)); // Fake actual connection after negotiate to populate the pipes on the connection - await dispatcher.ExecuteAsync(context, httpSocketOptions, c => Task.CompletedTask); + await dispatcher.ExecuteAsync(context, options, c => Task.CompletedTask); // This write should complete immediately but it exceeds the writer threshold var writeTask = connection.Application.Output.WriteAsync(new byte[] { (byte)'b', (byte)'y', (byte)'t', (byte)'e', (byte)'s' }); @@ -121,7 +121,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = responseBody; var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); services.AddOptions(); context.Request.Path = "/foo"; context.Request.Method = "POST"; @@ -131,11 +131,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Query = qs; var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); // This task should complete immediately but it exceeds the writer threshold - var executeTask = dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); + var executeTask = dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app); Assert.False(executeTask.IsCompleted); await connection.Transport.Input.ConsumeAsync(10); await executeTask.OrTimeout(); @@ -161,13 +161,13 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Features.Set(new ResponseFeature()); context.Features.Set(new TestWebSocketConnectionFeature()); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); services.AddOptions(); var ms = new MemoryStream(); context.Request.Path = "/foo"; context.Request.Method = "POST"; context.Response.Body = ms; - await dispatcher.ExecuteNegotiateAsync(context, new HttpSocketOptions { Transports = transports }); + await dispatcher.ExecuteNegotiateAsync(context, new HttpConnectionOptions { Transports = transports }); var negotiateResponse = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(ms.ToArray())); var availableTransports = (TransportType)0; @@ -199,7 +199,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = strm; var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); services.AddOptions(); context.Request.Path = "/foo"; context.Request.Method = "GET"; @@ -210,9 +210,9 @@ namespace Microsoft.AspNetCore.Sockets.Tests SetTransport(context, transportType); var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); + await dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app); Assert.Equal(StatusCodes.Status404NotFound, context.Response.StatusCode); await strm.FlushAsync(); @@ -235,7 +235,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = strm; var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); services.AddOptions(); context.Request.Path = "/foo"; context.Request.Method = "POST"; @@ -245,9 +245,9 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Query = qs; var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); + await dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app); Assert.Equal(StatusCodes.Status404NotFound, context.Response.StatusCode); await strm.FlushAsync(); @@ -272,7 +272,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = strm; var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); services.AddOptions(); context.Request.Path = "/foo"; context.Request.Method = "POST"; @@ -282,9 +282,9 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Query = qs; var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); + await dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app); Assert.Equal(StatusCodes.Status405MethodNotAllowed, context.Response.StatusCode); await strm.FlushAsync(); @@ -317,7 +317,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = responseBody; var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); services.AddOptions(); context.Request.Path = "/foo"; context.Request.Method = "POST"; @@ -327,10 +327,10 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Query = qs; var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); + await dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app); Assert.True(connection.Transport.Input.TryRead(out var result)); Assert.Equal("Hello World", Encoding.UTF8.GetString(result.Buffer.ToArray())); @@ -356,7 +356,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = responseBody; var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); services.AddOptions(); // Setup state on the HttpContext @@ -379,11 +379,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Connection.RemotePort = 43456; var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); // Start a poll - var task = dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); + var task = dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app); // Send to the application var buffer = Encoding.UTF8.GetBytes("Hello World"); @@ -445,16 +445,16 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = strm; var services = new ServiceCollection(); services.AddOptions(); - services.AddSingleton(); + services.AddSingleton(); context.Request.Path = "/foo"; context.Request.Method = "GET"; SetTransport(context, transportType); var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); + await dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app); Assert.Equal(StatusCodes.Status400BadRequest, context.Response.StatusCode); await strm.FlushAsync(); @@ -476,14 +476,14 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = strm; var services = new ServiceCollection(); services.AddOptions(); - services.AddSingleton(); + services.AddSingleton(); context.Request.Path = "/foo"; context.Request.Method = "POST"; var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); + await dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app); Assert.Equal(StatusCodes.Status400BadRequest, context.Response.StatusCode); await strm.FlushAsync(); @@ -552,11 +552,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests SetTransport(context, TransportType.ServerSentEvents); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); + await dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app); Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode); @@ -578,11 +578,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests SetTransport(context, TransportType.ServerSentEvents); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); + await dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app); Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode); @@ -604,11 +604,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context = MakeRequest("/foo", connection); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app); + await dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app); Assert.Equal(StatusCodes.Status204NoContent, context.Response.StatusCode); @@ -630,11 +630,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context = MakeRequest("/foo", connection); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); options.LongPolling.PollTimeout = TimeSpan.FromSeconds(2); await dispatcher.ExecuteAsync(context, options, app).OrTimeout(); @@ -656,11 +656,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests SetTransport(context, TransportType.WebSockets); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); options.WebSockets.CloseTimeout = TimeSpan.FromSeconds(1); var task = dispatcher.ExecuteAsync(context, options, app); @@ -688,11 +688,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests SetTransport(context2, transportType); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); var request1 = dispatcher.ExecuteAsync(context1, options, app); await dispatcher.ExecuteAsync(context2, options, app); @@ -727,11 +727,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context2 = MakeRequest("/foo", connection); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); var request1 = dispatcher.ExecuteAsync(context1, options, app); var request2 = dispatcher.ExecuteAsync(context2, options, app); @@ -765,11 +765,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests SetTransport(context, transportType); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); await dispatcher.ExecuteAsync(context, options, app); @@ -790,11 +790,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context = MakeRequest("/foo", connection); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); var task = dispatcher.ExecuteAsync(context, options, app); var buffer = Encoding.UTF8.GetBytes("Hello World"); @@ -825,11 +825,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests SetTransport(context, TransportType.ServerSentEvents); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); var task = dispatcher.ExecuteAsync(context, options, app); var buffer = Encoding.UTF8.GetBytes("Hello World"); @@ -858,11 +858,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context = MakeRequest("/foo", connection); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); var task = dispatcher.ExecuteAsync(context, options, app); var buffer = Encoding.UTF8.GetBytes("Hello World"); @@ -889,11 +889,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); var context1 = MakeRequest("/foo", connection); var task1 = dispatcher.ExecuteAsync(context1, options, app); @@ -933,12 +933,12 @@ namespace Microsoft.AspNetCore.Sockets.Tests SetTransport(context, transportType); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); options.WebSockets.CloseTimeout = TimeSpan.FromSeconds(0); await dispatcher.ExecuteAsync(context, options, app); @@ -961,7 +961,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context = new DefaultHttpContext(); var services = new ServiceCollection(); services.AddOptions(); - services.AddSingleton(); + services.AddSingleton(); services.AddAuthorizationPolicyEvaluator(); services.AddAuthorization(o => { @@ -983,9 +983,9 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Query = qs; var builder = new ConnectionBuilder(sp); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); options.AuthorizationData.Add(new AuthorizeAttribute("test")); // would hang if EndPoint was running @@ -1006,7 +1006,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context = new DefaultHttpContext(); var services = new ServiceCollection(); services.AddOptions(); - services.AddSingleton(); + services.AddSingleton(); services.AddAuthorizationPolicyEvaluator(); services.AddAuthorization(o => { @@ -1028,9 +1028,9 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Query = qs; var builder = new ConnectionBuilder(sp); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); options.AuthorizationData.Add(new AuthorizeAttribute("test")); context.User = new ClaimsPrincipal(new ClaimsIdentity("authenticated")); @@ -1054,7 +1054,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Features.Set(new ResponseFeature()); var services = new ServiceCollection(); services.AddOptions(); - services.AddSingleton(); + services.AddSingleton(); services.AddAuthorizationPolicyEvaluator(); services.AddAuthorization(o => { @@ -1080,18 +1080,18 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = new MemoryStream(); var builder = new ConnectionBuilder(sp); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); options.AuthorizationData.Add(new AuthorizeAttribute("test")); // "authorize" user context.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.NameIdentifier, "name") })); - var endPointTask = dispatcher.ExecuteAsync(context, options, app); + var connectionHandlerTask = dispatcher.ExecuteAsync(context, options, app); await connection.Transport.Output.WriteAsync(Encoding.UTF8.GetBytes("Hello, World")).AsTask().OrTimeout(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode); Assert.Equal("Hello, World", GetContentAsString(context.Response.Body)); @@ -1110,7 +1110,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Features.Set(new ResponseFeature()); var services = new ServiceCollection(); services.AddOptions(); - services.AddSingleton(); + services.AddSingleton(); services.AddAuthorizationPolicyEvaluator(); services.AddAuthorization(o => { @@ -1140,9 +1140,9 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = new MemoryStream(); var builder = new ConnectionBuilder(sp); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); options.AuthorizationData.Add(new AuthorizeAttribute("test")); options.AuthorizationData.Add(new AuthorizeAttribute("secondPolicy")); @@ -1169,10 +1169,10 @@ namespace Microsoft.AspNetCore.Sockets.Tests new Claim(ClaimTypes.StreetAddress, "12345 123rd St. NW") })); - var endPointTask = dispatcher.ExecuteAsync(context, options, app); + var connectionHandlerTask = dispatcher.ExecuteAsync(context, options, app); await connection.Transport.Output.WriteAsync(Encoding.UTF8.GetBytes("Hello, World")).AsTask().OrTimeout(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode); Assert.Equal("Hello, World", GetContentAsString(context.Response.Body)); @@ -1191,7 +1191,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Features.Set(new ResponseFeature()); var services = new ServiceCollection(); services.AddOptions(); - services.AddSingleton(); + services.AddSingleton(); services.AddAuthorization(o => { o.AddPolicy("test", policy => @@ -1218,18 +1218,18 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = new MemoryStream(); var builder = new ConnectionBuilder(sp); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); options.AuthorizationData.Add(new AuthorizeAttribute("test")); // "authorize" user context.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.NameIdentifier, "name") })); - var endPointTask = dispatcher.ExecuteAsync(context, options, app); + var connectionHandlerTask = dispatcher.ExecuteAsync(context, options, app); await connection.Transport.Output.WriteAsync(Encoding.UTF8.GetBytes("Hello, World")).AsTask().OrTimeout(); - await endPointTask.OrTimeout(); + await connectionHandlerTask.OrTimeout(); Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode); Assert.Equal("Hello, World", GetContentAsString(context.Response.Body)); @@ -1247,7 +1247,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context = new DefaultHttpContext(); var services = new ServiceCollection(); services.AddOptions(); - services.AddSingleton(); + services.AddSingleton(); services.AddAuthorization(o => { o.AddPolicy("test", policy => @@ -1274,9 +1274,9 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = new MemoryStream(); var builder = new ConnectionBuilder(sp); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); options.AuthorizationData.Add(new AuthorizeAttribute("test")); // "authorize" user @@ -1302,11 +1302,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context = MakeRequest("/foo", connection); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); options.LongPolling.PollTimeout = TimeSpan.FromMilliseconds(1); // We don't care about the poll itself Assert.Null(connection.Features.Get()); @@ -1328,13 +1328,13 @@ namespace Microsoft.AspNetCore.Sockets.Tests var context = new DefaultHttpContext(); context.Features.Set(new ResponseFeature()); var services = new ServiceCollection(); - services.AddSingleton(); + services.AddSingleton(); services.AddOptions(); var ms = new MemoryStream(); context.Request.Path = "/foo"; context.Request.Method = "POST"; context.Response.Body = ms; - await dispatcher.ExecuteNegotiateAsync(context, new HttpSocketOptions { Transports = TransportType.WebSockets }); + await dispatcher.ExecuteNegotiateAsync(context, new HttpConnectionOptions { Transports = TransportType.WebSockets }); var negotiateResponse = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(ms.ToArray())); var availableTransports = (JArray)negotiateResponse["availableTransports"]; @@ -1399,7 +1399,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Response.Body = strm; var services = new ServiceCollection(); services.AddOptions(); - services.AddSingleton(); + services.AddSingleton(); SetTransport(context, transportType); context.Request.Path = "/foo"; context.Request.Method = "GET"; @@ -1409,9 +1409,9 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Query = qs; var builder = new ConnectionBuilder(services.BuildServiceProvider()); - builder.UseEndPoint(); + builder.UseConnectionHandler(); var app = builder.Build(); - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); options.Transports = supportedTransports; await dispatcher.ExecuteAsync(context, options, app); @@ -1475,7 +1475,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests } } - public class NerverEndingEndPoint : EndPoint + public class NerverEndingConnectionHandler : ConnectionHandler { public override Task OnConnectedAsync(ConnectionContext connection) { @@ -1484,7 +1484,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests } } - public class BlockingEndPoint : EndPoint + public class BlockingConnectionHandler : ConnectionHandler { public override Task OnConnectedAsync(ConnectionContext connection) { @@ -1494,7 +1494,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests } } - public class SynchronusExceptionEndPoint : EndPoint + public class SynchronusExceptionConnectionHandler : ConnectionHandler { public override Task OnConnectedAsync(ConnectionContext connection) { @@ -1502,7 +1502,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests } } - public class ImmediatelyCompleteEndPoint : EndPoint + public class ImmediatelyCompleteConnectionHandler : ConnectionHandler { public override Task OnConnectedAsync(ConnectionContext connection) { @@ -1510,7 +1510,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests } } - public class HttpContextEndPoint : EndPoint + public class HttpContextConnectionHandler : ConnectionHandler { public override async Task OnConnectedAsync(ConnectionContext connection) { @@ -1543,7 +1543,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests } } - public class TestEndPoint : EndPoint + public class TestConnectionHandler : ConnectionHandler { public override async Task OnConnectedAsync(ConnectionContext connection) { diff --git a/test/Microsoft.AspNetCore.Sockets.Tests/LongPollingTests.cs b/test/Microsoft.AspNetCore.Sockets.Tests/LongPollingTests.cs index ddf8727bc8..ebc91c4feb 100644 --- a/test/Microsoft.AspNetCore.Sockets.Tests/LongPollingTests.cs +++ b/test/Microsoft.AspNetCore.Sockets.Tests/LongPollingTests.cs @@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests [Fact] public void CheckLongPollingTimeoutValue() { - var options = new HttpSocketOptions(); + var options = new HttpConnectionOptions(); Assert.Equal(options.LongPolling.PollTimeout, TimeSpan.FromSeconds(90)); } } diff --git a/test/Microsoft.AspNetCore.Sockets.Tests/MapEndPointTests.cs b/test/Microsoft.AspNetCore.Sockets.Tests/MapConnectionHandlerTests.cs similarity index 74% rename from test/Microsoft.AspNetCore.Sockets.Tests/MapEndPointTests.cs rename to test/Microsoft.AspNetCore.Sockets.Tests/MapConnectionHandlerTests.cs index 10203d3ae0..7147d126f8 100644 --- a/test/Microsoft.AspNetCore.Sockets.Tests/MapEndPointTests.cs +++ b/test/Microsoft.AspNetCore.Sockets.Tests/MapConnectionHandlerTests.cs @@ -10,7 +10,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server.Features; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -19,20 +19,20 @@ using Xunit.Abstractions; namespace Microsoft.AspNetCore.Sockets.Tests { - public class MapEndPointTests + public class MapConnectionHandlerTests { private ITestOutputHelper _output; - public MapEndPointTests(ITestOutputHelper output) + public MapConnectionHandlerTests(ITestOutputHelper output) { _output = output; } [Fact] - public void MapEndPointFindsAuthAttributeOnEndPoint() + public void MapConnectionHandlerFindsAuthAttributeOnEndPoint() { var authCount = 0; - using (var builder = BuildWebHost("/auth", + using (var builder = BuildWebHost("/auth", options => authCount += options.AuthorizationData.Count)) { builder.Start(); @@ -42,10 +42,10 @@ namespace Microsoft.AspNetCore.Sockets.Tests } [Fact] - public void MapEndPointFindsAuthAttributeOnInheritedEndPoint() + public void MapConnectionHandlerFindsAuthAttributeOnInheritedEndPoint() { var authCount = 0; - using (var builder = BuildWebHost("/auth", + using (var builder = BuildWebHost("/auth", options => authCount += options.AuthorizationData.Count)) { builder.Start(); @@ -55,10 +55,10 @@ namespace Microsoft.AspNetCore.Sockets.Tests } [Fact] - public void MapEndPointFindsAuthAttributesOnDoubleAuthEndPoint() + public void MapConnectionHandlerFindsAuthAttributesOnDoubleAuthEndPoint() { var authCount = 0; - using (var builder = BuildWebHost("/auth", + using (var builder = BuildWebHost("/auth", options => authCount += options.AuthorizationData.Count)) { builder.Start(); @@ -69,9 +69,9 @@ namespace Microsoft.AspNetCore.Sockets.Tests [ConditionalFact] [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")] - public async Task MapEndPointWithWebSocketSubProtocolSetsProtocol() + public async Task MapConnectionHandlerWithWebSocketSubProtocolSetsProtocol() { - var host = BuildWebHost("/socket", + var host = BuildWebHost("/socket", options => options.WebSockets.SubProtocol = "protocol1"); await host.StartAsync(); @@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests Assert.Equal(WebSocketMessageType.Close, result.MessageType); } - private class MyEndPoint : EndPoint + private class MyConnectionHandler : ConnectionHandler { public override async Task OnConnectedAsync(ConnectionContext connection) { @@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests } } - private class InheritedAuthEndPoint : AuthEndPoint + private class InheritedAuthConnectionHandler : AuthConnectionHandler { public override Task OnConnectedAsync(ConnectionContext connection) { @@ -117,12 +117,12 @@ namespace Microsoft.AspNetCore.Sockets.Tests } [Authorize] - private class DoubleAuthEndPoint : AuthEndPoint + private class DoubleAuthConnectionHandler : AuthConnectionHandler { } [Authorize] - private class AuthEndPoint : EndPoint + private class AuthConnectionHandler : ConnectionHandler { public override Task OnConnectedAsync(ConnectionContext connection) { @@ -130,22 +130,20 @@ namespace Microsoft.AspNetCore.Sockets.Tests } } - private IWebHost BuildWebHost(string path, Action configure) where TEndPoint : EndPoint + private IWebHost BuildWebHost(string path, Action configureOptions) where TConnectionHandler : ConnectionHandler { return new WebHostBuilder() .UseUrls("http://127.0.0.1:0") .UseKestrel() .ConfigureServices(services => { - services.AddSockets(); - services.AddSingleton(); + services.AddConnections(); }) .Configure(app => { - app.UseSockets(routes => + app.UseConnections(routes => { - routes.MapEndPoint(path, - httpSocketOptions => configure(httpSocketOptions)); + routes.MapConnectionHandler(path, configureOptions); }); }) .ConfigureLogging(factory => diff --git a/test/Microsoft.AspNetCore.Sockets.Tests/WebSocketsTests.cs b/test/Microsoft.AspNetCore.Sockets.Tests/WebSocketsTests.cs index cec8ea1e05..455608e664 100644 --- a/test/Microsoft.AspNetCore.Sockets.Tests/WebSocketsTests.cs +++ b/test/Microsoft.AspNetCore.Sockets.Tests/WebSocketsTests.cs @@ -8,7 +8,7 @@ using System.Net.WebSockets; using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Protocols; +using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Sockets.Internal.Transports; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Testing;