99using Microsoft . AspNetCore . Routing . Matching ;
1010using Microsoft . AspNetCore . Routing . TestObjects ;
1111using Microsoft . Extensions . DependencyInjection ;
12+ using Microsoft . Extensions . Logging ;
13+ using Microsoft . Extensions . Logging . Testing ;
1214using Xunit ;
1315
1416namespace Microsoft . AspNetCore . Routing
@@ -23,48 +25,68 @@ public class DefaultLinkParserTest : LinkParserTestBase
2325 public void ParsePathByAddresss_NoMatchingEndpoint_ReturnsNull ( )
2426 {
2527 // Arrange
26- var endpoint = EndpointFactory . CreateRouteEndpoint ( "{controller}/{action}/{id?}" , metadata : new object [ ] { new IntMetadata ( 1 ) , } ) ;
28+ var endpoint = EndpointFactory . CreateRouteEndpoint ( "{controller}/{action}/{id?}" , displayName : "Test1" , metadata : new object [ ] { new IntMetadata ( 1 ) , } ) ;
2729
28- var parser = CreateLinkParser ( endpoint ) ;
30+ var sink = new TestSink ( ) ;
31+ var loggerFactory = new TestLoggerFactory ( sink , enabled : true ) ;
32+ var parser = CreateLinkParser ( services => { services . AddSingleton < ILoggerFactory > ( loggerFactory ) ; } , endpoint ) ;
2933
3034 // Act
3135 var values = parser . ParsePathByAddress ( 0 , "/Home/Index/17" ) ;
3236
3337 // Assert
3438 Assert . Null ( values ) ;
39+
40+ Assert . Collection (
41+ sink . Writes ,
42+ w => Assert . Equal ( "No endpoints found for address 0" , w . Message ) ) ;
3543 }
3644
3745 [ Fact ]
3846 public void ParsePathByAddresss_HasMatches_ReturnsNullWhenParsingFails ( )
3947 {
4048 // Arrange
41- var endpoint1 = EndpointFactory . CreateRouteEndpoint ( "{controller}/{action}/{id}" , metadata : new object [ ] { new IntMetadata ( 1 ) , } ) ;
42- var endpoint2 = EndpointFactory . CreateRouteEndpoint ( "{controller}/{action}/{id2}" , metadata : new object [ ] { new IntMetadata ( 0 ) , } ) ;
49+ var endpoint1 = EndpointFactory . CreateRouteEndpoint ( "{controller}/{action}/{id}" , displayName : "Test1" , metadata : new object [ ] { new IntMetadata ( 1 ) , } ) ;
50+ var endpoint2 = EndpointFactory . CreateRouteEndpoint ( "{controller}/{action}/{id2}" , displayName : "Test2" , metadata : new object [ ] { new IntMetadata ( 0 ) , } ) ;
4351
44- var parser = CreateLinkParser ( endpoint1 , endpoint2 ) ;
52+ var sink = new TestSink ( ) ;
53+ var loggerFactory = new TestLoggerFactory ( sink , enabled : true ) ;
54+ var parser = CreateLinkParser ( services => { services . AddSingleton < ILoggerFactory > ( loggerFactory ) ; } , endpoint1 , endpoint2 ) ;
4555
4656 // Act
4757 var values = parser . ParsePathByAddress ( 0 , "/" ) ;
4858
4959 // Assert
5060 Assert . Null ( values ) ;
61+
62+ Assert . Collection (
63+ sink . Writes ,
64+ w => Assert . Equal ( "Found the endpoints Test2 for address 0" , w . Message ) ,
65+ w => Assert . Equal ( "Path parsing failed for endpoints Test2 and URI path /" , w . Message ) ) ;
5166 }
5267
5368 [ Fact ]
5469 public void ParsePathByAddresss_HasMatches_ReturnsFirstSuccessfulParse ( )
5570 {
5671 // Arrange
57- var endpoint0 = EndpointFactory . CreateRouteEndpoint ( "{controller}/{action}" , metadata : new object [ ] { new IntMetadata ( 0 ) , } ) ;
58- var endpoint1 = EndpointFactory . CreateRouteEndpoint ( "{controller}/{action}/{id}" , metadata : new object [ ] { new IntMetadata ( 0 ) , } ) ;
59- var endpoint2 = EndpointFactory . CreateRouteEndpoint ( "{controller}/{action}/{id2}" , metadata : new object [ ] { new IntMetadata ( 0 ) , } ) ;
72+ var endpoint0 = EndpointFactory . CreateRouteEndpoint ( "{controller}/{action}" , displayName : "Test1" , metadata : new object [ ] { new IntMetadata ( 0 ) , } ) ;
73+ var endpoint1 = EndpointFactory . CreateRouteEndpoint ( "{controller}/{action}/{id}" , displayName : "Test2" , metadata : new object [ ] { new IntMetadata ( 0 ) , } ) ;
74+ var endpoint2 = EndpointFactory . CreateRouteEndpoint ( "{controller}/{action}/{id2}" , displayName : "Test3" , metadata : new object [ ] { new IntMetadata ( 0 ) , } ) ;
6075
61- var parser = CreateLinkParser ( endpoint0 , endpoint1 , endpoint2 ) ;
76+ var sink = new TestSink ( ) ;
77+ var loggerFactory = new TestLoggerFactory ( sink , enabled : true ) ;
78+ var parser = CreateLinkParser ( services => { services . AddSingleton < ILoggerFactory > ( loggerFactory ) ; } , endpoint0 , endpoint1 , endpoint2 ) ;
6279
6380 // Act
6481 var values = parser . ParsePathByAddress ( 0 , "/Home/Index/17" ) ;
6582
6683 // Assert
6784 MatcherAssert . AssertRouteValuesEqual ( new { controller = "Home" , action = "Index" , id = "17" } , values ) ;
85+
86+ Assert . Collection (
87+ sink . Writes ,
88+ w => Assert . Equal ( "Found the endpoints Test1, Test2, Test3 for address 0" , w . Message ) ,
89+ w => Assert . Equal ( "Path parsing succeeded for endpoint Test2 and URI path /Home/Index/17" , w . Message ) ) ;
6890 }
6991
7092 [ Fact ]
0 commit comments