-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write log message for matched fallback routes (#47798)
Co-authored-by: Chris Ross <Tratcher@Outlook.com>
- Loading branch information
Showing
9 changed files
with
139 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.Routing; | ||
|
||
internal sealed class FallbackMetadata | ||
{ | ||
public static readonly FallbackMetadata Instance = new FallbackMetadata(); | ||
|
||
private FallbackMetadata() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/Http/Routing/test/UnitTests/Builder/FallbackEndpointRouteBuilderExtensionsTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable | ||
|
||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Routing; | ||
|
||
namespace Microsoft.AspNetCore.Builder; | ||
|
||
public class FallbackEndpointRouteBuilderExtensionsTest | ||
{ | ||
private EndpointDataSource GetBuilderEndpointDataSource(IEndpointRouteBuilder endpointRouteBuilder) => | ||
Assert.Single(endpointRouteBuilder.DataSources); | ||
|
||
[Fact] | ||
public void MapFallback_AddFallbackMetadata() | ||
{ | ||
var builder = new DefaultEndpointRouteBuilder(new ApplicationBuilder(EmptyServiceProvider.Instance)); | ||
|
||
RequestDelegate initialRequestDelegate = static (context) => Task.CompletedTask; | ||
|
||
builder.MapFallback(initialRequestDelegate); | ||
|
||
var dataSource = GetBuilderEndpointDataSource(builder); | ||
var endpoint = Assert.Single(dataSource.Endpoints); | ||
|
||
Assert.Contains(FallbackMetadata.Instance, endpoint.Metadata); | ||
Assert.Equal(int.MaxValue, ((RouteEndpoint)endpoint).Order); | ||
} | ||
|
||
[Fact] | ||
public void MapFallback_Pattern_AddFallbackMetadata() | ||
{ | ||
var builder = new DefaultEndpointRouteBuilder(new ApplicationBuilder(EmptyServiceProvider.Instance)); | ||
|
||
RequestDelegate initialRequestDelegate = static (context) => Task.CompletedTask; | ||
|
||
builder.MapFallback("/", initialRequestDelegate); | ||
|
||
var dataSource = GetBuilderEndpointDataSource(builder); | ||
var endpoint = Assert.Single(dataSource.Endpoints); | ||
|
||
Assert.Contains(FallbackMetadata.Instance, endpoint.Metadata); | ||
Assert.Equal(int.MaxValue, ((RouteEndpoint)endpoint).Order); | ||
} | ||
|
||
private sealed class EmptyServiceProvider : IServiceProvider | ||
{ | ||
public static EmptyServiceProvider Instance { get; } = new EmptyServiceProvider(); | ||
public object? GetService(Type serviceType) => null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters