Closed chrilith closed 11 years ago
This is great stuff. I'm going to merge and run a few tests. I'll have this committed soon.
Can you post some example URLs that your are matching? I'd like to add your use cases to my tests.
Well, no PC right now but here is a test case that should work.
Create a TestController with 2 or 3 actions you'll names Action1, Action2 etc...
Now your url parameter : {controller}/{action}/{label}-{id}.html
And your pattern: ^(?
Now if you use RouteLink or RouteUrl you can create a link with anything you want for controller, action, label or id but when the url will be clicked the route may not be found if the elements doesn't match the pattern.
Setting RegexRoute.AutoConstraints = true will prevent you to generate illegal links since the parameters will be checked without the need to add extra constraints.
To test this just generate a link passing Action1 and another passing Action3 You can also pass an invalid label with numbers.
I'll add that to my tests. Thanks!
Constraints are applied when generating a route url. It is locigal to use the same rules as the regex pattern but it may be a pain to copy each part of the regex for the given group name in a constraints RouteValueDictionray. Using AutoConstraints will generate these parts for the developer based on the regex pattern.
Like this, we cannot generate a unexpected url. HTTP requests and url generation are sync.