Fix: #10091
This commit is contained in:
parent
15b1566d90
commit
b03bca15de
|
|
@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.Builder.Internal
|
|||
var message =
|
||||
$"The request reached the end of the pipeline without executing the endpoint: '{endpoint.DisplayName}'. " +
|
||||
$"Please register the EndpointMiddleware using '{nameof(IApplicationBuilder)}.UseEndpoints(...)' if using " +
|
||||
$"routing, or '{nameof(IApplicationBuilder)}.UseEndpointExecutor()' if not using routing.";
|
||||
$"routing.";
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Builder.Internal
|
|||
var expected =
|
||||
"The request reached the end of the pipeline without executing the endpoint: 'Test endpoint'. " +
|
||||
"Please register the EndpointMiddleware using 'IApplicationBuilder.UseEndpoints(...)' if " +
|
||||
"using routing, or 'IApplicationBuilder.UseEndpointExecutor()' if not using routing.";
|
||||
"using routing.";
|
||||
Assert.Equal(expected, ex.Message);
|
||||
Assert.False(endpointCalled);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ namespace Microsoft.AspNetCore.Builder
|
|||
}
|
||||
public static partial class EndpointRoutingApplicationBuilderExtensions
|
||||
{
|
||||
public static Microsoft.AspNetCore.Builder.IApplicationBuilder UseEndpointExecutor(this Microsoft.AspNetCore.Builder.IApplicationBuilder builder) { throw null; }
|
||||
public static Microsoft.AspNetCore.Builder.IApplicationBuilder UseEndpoints(this Microsoft.AspNetCore.Builder.IApplicationBuilder builder, System.Action<Microsoft.AspNetCore.Routing.IEndpointRouteBuilder> configure) { throw null; }
|
||||
public static Microsoft.AspNetCore.Builder.IApplicationBuilder UseRouting(this Microsoft.AspNetCore.Builder.IApplicationBuilder builder) { throw null; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,31 +103,6 @@ namespace Microsoft.AspNetCore.Builder
|
|||
return builder.UseMiddleware<EndpointMiddleware>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="EndpointMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/> that will
|
||||
/// execute the <see cref="Endpoint"/> associated with the current request.
|
||||
/// </summary>
|
||||
/// <param name="builder">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
|
||||
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// A call to <see cref="UseEndpointExecutor(IApplicationBuilder)"/> may be used to execute an endpoint with
|
||||
/// using <see cref="UseRouting(IApplicationBuilder)" />. This enables applications to use endpoints with other
|
||||
/// middleware not related to routing.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public static IApplicationBuilder UseEndpointExecutor(this IApplicationBuilder builder)
|
||||
{
|
||||
if (builder == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(builder));
|
||||
}
|
||||
|
||||
// Note: we don't require routing services either.
|
||||
|
||||
return builder.UseMiddleware<EndpointMiddleware>();
|
||||
}
|
||||
|
||||
private static void VerifyRoutingServicesAreRegistered(IApplicationBuilder app)
|
||||
{
|
||||
// Verify if AddRouting was done before calling UseEndpointRouting/UseEndpoint
|
||||
|
|
|
|||
|
|
@ -295,37 +295,6 @@ namespace Microsoft.AspNetCore.Builder
|
|||
e => Assert.Equal("Test endpoint 4", e.DisplayName));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UseEndpointExecutor_RunsEndpoint()
|
||||
{
|
||||
// Arrange
|
||||
var services = CreateServices();
|
||||
|
||||
var endpointRan = false;
|
||||
var app = new ApplicationBuilder(services);
|
||||
|
||||
app.Use(next => context =>
|
||||
{
|
||||
context.SetEndpoint(new Endpoint(c =>
|
||||
{
|
||||
endpointRan = true;
|
||||
return Task.CompletedTask;
|
||||
}, new EndpointMetadataCollection(), "Test"));
|
||||
return next(context);
|
||||
});
|
||||
|
||||
app.UseEndpointExecutor(); // No services required, no UseRouting required
|
||||
|
||||
var appFunc = app.Build();
|
||||
var httpContext = new DefaultHttpContext();
|
||||
|
||||
// Act
|
||||
await appFunc(httpContext);
|
||||
|
||||
// Assert
|
||||
Assert.True(endpointRan);
|
||||
}
|
||||
|
||||
private IServiceProvider CreateServices()
|
||||
{
|
||||
return CreateServices(matcherFactory: null);
|
||||
|
|
|
|||
Loading…
Reference in New Issue