@@ -20,6 +20,48 @@ namespace Microsoft.AspNetCore.Routing
20
20
{
21
21
public class EndpointRoutingMiddlewareTest
22
22
{
23
+ [ Fact ]
24
+ public async Task Invoke_ChangedPath_ResultsInDifferentResult ( )
25
+ {
26
+ // Arrange
27
+ var httpContext = CreateHttpContext ( ) ;
28
+ var matcher = new Mock < Matcher > ( ) ;
29
+ var pathToEndpoints = new Dictionary < string , Endpoint > ( )
30
+ {
31
+ [ "/initial" ] = new Endpoint ( c => Task . CompletedTask , new EndpointMetadataCollection ( ) , "initialEndpoint" ) ,
32
+ [ "/changed" ] = new Endpoint ( c => Task . CompletedTask , new EndpointMetadataCollection ( ) , "changedEndpoint" )
33
+ } ;
34
+ matcher . Setup ( m => m . MatchAsync ( httpContext ) )
35
+ . Callback < HttpContext > ( context =>
36
+ {
37
+ var endpointToSet = pathToEndpoints [ context . Request . Path ] ;
38
+ context . SetEndpoint ( endpointToSet ) ;
39
+ } )
40
+ . Returns ( Task . CompletedTask )
41
+ . Verifiable ( ) ;
42
+ var matcherFactory = Mock . Of < MatcherFactory > ( factory => factory . CreateMatcher ( It . IsAny < EndpointDataSource > ( ) ) == matcher . Object ) ;
43
+ var middleware = CreateMiddleware (
44
+ matcherFactory : matcherFactory ,
45
+ next : context =>
46
+ {
47
+ Assert . True ( pathToEndpoints . TryGetValue ( context . Request . Path , out var expectedEndpoint ) ) ;
48
+
49
+ var currentEndpoint = context . GetEndpoint ( ) ;
50
+ Assert . Equal ( expectedEndpoint , currentEndpoint ) ;
51
+
52
+ return Task . CompletedTask ;
53
+ } ) ;
54
+
55
+ // Act
56
+ httpContext . Request . Path = "/initial" ;
57
+ await middleware . Invoke ( httpContext ) ;
58
+ httpContext . Request . Path = "/changed" ;
59
+ await middleware . Invoke ( httpContext ) ;
60
+
61
+ // Assert
62
+ matcher . Verify ( ) ;
63
+ }
64
+
23
65
[ Fact ]
24
66
public async Task Invoke_OnException_ResetsEndpoint ( )
25
67
{
0 commit comments