-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for controller-level attribute routes. Resolves #44 #45
base: master
Are you sure you want to change the base?
Conversation
Thank you; this is looking good 👍 Did you accidentally check in |
Oops, yes apparently I did. Please reject the pull request so that I can correct my branch and re-submit it. |
} | ||
|
||
var newRouteValues = AddControllerNameAndMethodToRouteValues(callExpression, routeValues); | ||
newRouteValues = RemoveControllerAndActionRouteValuesIfNeeded(controllerRouteAttribute, newRouteValues); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not that I want to be a killjoy here, but I can remove this method call without any tests failing.
It's not that I predict that a lot of work will be done on Hyprlinkr in the future, but I tend to rely heavily on unit tests when I refactor. My modus operandi is that if all tests are still green after a refactoring, then I broke nothing.
There's a risk, then, that I (or someone else) might break a feature for you in the future, because this isn't covered by tests. If this is important to you, would it be possible to add some tests? Or perhaps remove this for now, and then come back to it in a later pull request?
var newRouteValues = new Dictionary<string, object>(routeValues); | ||
var controllerName = callExpression.Object.Type.Name.ToLowerInvariant().Replace("controller", ""); | ||
newRouteValues["controller"] = controllerName; | ||
newRouteValues["action"] = callExpression.Method.Name.ToLowerInvariant(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can remove the above three statements without breaking any tests. What value do these lines of code add?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, I should have added additional test cases.
Those methods manage the "controller" and "action" KVPs which may or may not be necessary to create the actual route Uri, depending on the actual Route Template.
The problem is that if they are put into the RouteValues
dictionary and they are not needed, they will show up incorrectly as querystrings, which is not desirable.
I'll write the test cases that illustrate these issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a suggestion, which will make things go smoother:
- Decline this pull request. You can do this yourself.
- Send a new pull request without these extra features, but only handling of Controller-level attributes.
- Send another pull request later with the other changes.
Making pull requests smaller tend to make the entire process faster.
The
DefaultRouteDispatcher
was modified to check the controller for aRoute
attribute, similarly to what it does with actions.As per MSDN documentation
Route
attributes on actions take precedence overRoute
attributes on controllers.If no attribute is found, the
DefaultRouteDispatcher
works as before.A new test was created to check this feature (
DispatchReturnsResultWithRouterAttributeControllerRouteName
).