@@ -28,7 +28,7 @@ public async Task<IActionResult> GetOrder([FromRoute]int id)
2828}" . AssertReplace ( "api/orders/{id}" , text ) ) ;
2929 var literal = syntaxTree . FindLiteralExpression ( text ) ;
3030 Assert . AreEqual ( true , UrlTemplate . TryParse ( literal , out var template ) ) ;
31- CollectionAssert . AreEqual ( expected , template . Path . Select ( x => x . Text . Text ) ) ;
31+ CollectionAssert . AreEqual ( expected , template . Path . Select ( x => x . Span . Text ) ) ;
3232 }
3333
3434 [ TestCase ( "{id}" , new [ ] { "{id}" } ) ]
@@ -57,20 +57,21 @@ public async Task<IActionResult> GetOrder([FromRoute]int id)
5757}" . AssertReplace ( "api/orders/{id}" , text ) ) ;
5858 var literal = syntaxTree . FindLiteralExpression ( text ) ;
5959 Assert . AreEqual ( true , UrlTemplate . TryParse ( literal , out var template ) ) ;
60- CollectionAssert . AreEqual ( expected , template . Path . Select ( x => x . Text . Text ) ) ;
60+ CollectionAssert . AreEqual ( expected , template . Path . Select ( x => x . Span . Text ) ) ;
6161
6262 // ReSharper disable once PossibleInvalidOperationException
6363 var parameter = template . Path . Single ( x => x . Parameter . HasValue )
6464 . Parameter . Value ;
6565 Assert . AreEqual ( "id" , parameter . Name . Text ) ;
6666 }
6767
68- [ TestCase ( "orders/{id:min(1)}" , new [ ] { "orders" , "{id:min(1)}" } ) ]
69- [ TestCase ( "orders/{id:int:min(1):max(2)}" , new [ ] { "orders" , "{id:int:min(1):max(2)}" } ) ]
70- [ TestCase ( "orders/{id:max(2)}" , new [ ] { "orders" , "{id:max(2)}" } ) ]
71- [ TestCase ( "orders/{id:int:max(2)}" , new [ ] { "orders" , "{id:int:max(2)}" } ) ]
72- [ TestCase ( "orders/{id:range(1,23)}" , new [ ] { "orders" , "{id:range(1,23)}" } ) ]
73- public void TryParseWhenIntParameter ( string text , string [ ] expected )
68+ [ TestCase ( "orders/{id?}" , new [ ] { "orders" , "{id?}" } , new [ ] { "?" } ) ]
69+ [ TestCase ( "orders/{id:min(1)}" , new [ ] { "orders" , "{id:min(1)}" } , new [ ] { "min(1)" } ) ]
70+ [ TestCase ( "orders/{id:int:min(1):max(2)}" , new [ ] { "orders" , "{id:int:min(1):max(2)}" } , new [ ] { "int" , "min(1)" , "max(2)" } ) ]
71+ [ TestCase ( "orders/{id:max(2)}" , new [ ] { "orders" , "{id:max(2)}" } , new [ ] { "max(2)" } ) ]
72+ [ TestCase ( "orders/{id:int:max(2)}" , new [ ] { "orders" , "{id:int:max(2)}" } , new [ ] { "int" , "max(2)" } ) ]
73+ [ TestCase ( "orders/{id:range(1,23)}" , new [ ] { "orders" , "{id:range(1,23)}" } , new [ ] { "range(1,23)" } ) ]
74+ public void TryParseWhenIntParameter ( string text , string [ ] segments , string [ ] constraints )
7475 {
7576 var syntaxTree = CSharpSyntaxTree . ParseText ( @"
7677namespace ValidCode
@@ -89,25 +90,28 @@ public async Task<IActionResult> GetOrder([FromRoute]int id)
8990}" . AssertReplace ( "orders/{id}" , text ) ) ;
9091 var literal = syntaxTree . FindLiteralExpression ( text ) ;
9192 Assert . AreEqual ( true , UrlTemplate . TryParse ( literal , out var template ) ) ;
92- CollectionAssert . AreEqual ( expected , template . Path . Select ( x => x . Text . Text ) ) ;
93+ CollectionAssert . AreEqual ( segments , template . Path . Select ( x => x . Span . Text ) ) ;
9394
9495 // ReSharper disable once PossibleInvalidOperationException
9596 var parameter = template . Path . Single ( x => x . Parameter . HasValue )
9697 . Parameter . Value ;
9798 Assert . AreEqual ( "id" , parameter . Name . Text ) ;
99+ CollectionAssert . AreEqual ( constraints , parameter . Constraints . Select ( x => x . Span . Text ) ) ;
98100 }
99101
100- [ TestCase ( "orders/{id?}" , new [ ] { "orders" , "{id?}" } ) ]
101- [ TestCase ( "orders/{id:alpha}" , new [ ] { "orders" , "{id:alpha}" } ) ]
102- [ TestCase ( "orders/{id:alpha:minlength(1)}" , new [ ] { "orders" , "{id:alpha:minlength(1)}" } ) ]
103- [ TestCase ( "orders/{id:minlength(1)}" , new [ ] { "orders" , "{id:minlength(1)}" } ) ]
104- [ TestCase ( "orders/{id:maxlength(1)}" , new [ ] { "orders" , "{id:maxlength(1)}" } ) ]
105- [ TestCase ( "orders/{id:length(1)}" , new [ ] { "orders" , "{id:length(1)}" } ) ]
106- [ TestCase ( "orders/{id:length(1,2)}" , new [ ] { "orders" , "{id:length(1,2)}" } ) ]
107- [ TestCase ( "orders/{id:regex(^\\ \\ d{{3}}-\\ \\ d{{2}}-\\ \\ d{{4}}$)}" , new [ ] { "orders" , "{id:regex(^\\ d{{3}}-\\ d{{2}}-\\ d{{4}}$)}" } ) ]
108- [ TestCase ( "orders/{id:regex(a/b)}" , new [ ] { "orders" , "{id:regex(a/b)}" } ) ]
102+ [ TestCase ( "orders/{id}" , new [ ] { "orders" , "{id}" } , new string [ 0 ] ) ]
103+ [ TestCase ( "orders/{id?}" , new [ ] { "orders" , "{id?}" } , new [ ] { "?" } ) ]
104+ [ TestCase ( "orders/{id:alpha}" , new [ ] { "orders" , "{id:alpha}" } , new [ ] { "alpha" } ) ]
105+ [ TestCase ( "orders/{id:ALPHA}" , new [ ] { "orders" , "{id:ALPHA}" } , new [ ] { "ALPHA" } ) ]
106+ [ TestCase ( "orders/{id:alpha:minlength(1)}" , new [ ] { "orders" , "{id:alpha:minlength(1)}" } , new [ ] { "alpha" , "minlength(1)" } ) ]
107+ [ TestCase ( "orders/{id:minlength(1)}" , new [ ] { "orders" , "{id:minlength(1)}" } , new [ ] { "minlength(1)" } ) ]
108+ [ TestCase ( "orders/{id:maxlength(1)}" , new [ ] { "orders" , "{id:maxlength(1)}" } , new [ ] { "maxlength(1)" } ) ]
109+ [ TestCase ( "orders/{id:length(1)}" , new [ ] { "orders" , "{id:length(1)}" } , new [ ] { "length(1)" } ) ]
110+ [ TestCase ( "orders/{id:length(1,2)}" , new [ ] { "orders" , "{id:length(1,2)}" } , new [ ] { "length(1,2)" } ) ]
111+ [ TestCase ( "orders/{id:regex(^\\ \\ d{3}-\\ \\ d{2}-\\ \\ d{4}$)}" , new [ ] { "orders" , "{id:regex(^\\ d{3}-\\ d{2}-\\ d{4}$)}" } , new [ ] { "regex(^\\ d{3}-\\ d{2}-\\ d{4}$)" } ) ]
112+ [ TestCase ( "orders/{id:regex(a/b)}" , new [ ] { "orders" , "{id:regex(a/b)}" } , new [ ] { "regex(a/b)" } ) ]
109113 ////[TestCase("orders/{id:regex(a[)}/]b)}", new[] { "orders", "{id:regex(a[)}/]b)}" })]
110- public void TryParseWhenStringParameter ( string text , string [ ] expected )
114+ public void TryParseWhenStringParameter ( string text , string [ ] segments , string [ ] constraints )
111115 {
112116 var syntaxTree = CSharpSyntaxTree . ParseText ( @"
113117namespace ValidCode
@@ -126,12 +130,14 @@ public async Task<IActionResult> GetOrder(string id)
126130}" . AssertReplace ( "orders/{id}" , text ) ) ;
127131 var literal = syntaxTree . FindLiteralExpression ( text ) ;
128132 Assert . AreEqual ( true , UrlTemplate . TryParse ( literal , out var template ) ) ;
129- CollectionAssert . AreEqual ( expected , template . Path . Select ( x => x . Text . Text ) ) ;
133+ CollectionAssert . AreEqual ( segments , template . Path . Select ( x => x . Span . Text ) ) ;
130134
131135 // ReSharper disable once PossibleInvalidOperationException
132136 var parameter = template . Path . Single ( x => x . Parameter . HasValue )
133137 . Parameter . Value ;
134138 Assert . AreEqual ( "id" , parameter . Name . Text ) ;
139+ CollectionAssert . AreEqual ( constraints , parameter . Constraints . Select ( x => x . Span . Text )
140+ . ToArray ( ) ) ;
135141 }
136142 }
137143}
0 commit comments