Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

joaopbnogueira
Copy link

The DefaultRouteDispatcher was modified to check the controller for a Route attribute, similarly to what it does with actions.

As per MSDN documentation Route attributes on actions take precedence over Route attributes on controllers.

If no attribute is found, the DefaultRouteDispatcher works as before.

A new test was created to check this feature (DispatchReturnsResultWithRouterAttributeControllerRouteName).

@ploeh
Copy link
Owner

ploeh commented Feb 22, 2017

Thank you; this is looking good 👍

Did you accidentally check in UpgradeLog.htm?

@joaopbnogueira
Copy link
Author

joaopbnogueira commented Feb 22, 2017

Oops, yes apparently I did. Please reject the pull request so that I can correct my branch and re-submit it.
(Or is that unnecessary? Sorry but I'm more of a subversion guy!)

}

var newRouteValues = AddControllerNameAndMethodToRouteValues(callExpression, routeValues);
newRouteValues = RemoveControllerAndActionRouteValuesIfNeeded(controllerRouteAttribute, newRouteValues);
Copy link
Owner

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();
Copy link
Owner

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?

Copy link
Author

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.

Copy link
Owner

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:

  1. Decline this pull request. You can do this yourself.
  2. Send a new pull request without these extra features, but only handling of Controller-level attributes.
  3. Send another pull request later with the other changes.

Making pull requests smaller tend to make the entire process faster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants