views:

158

answers:

3

Let's say I have defined a route:

        routes.Add(new Route("Users/{id}", new MvcRouteHandler())
            {
                Defaults = new RouteValueDictionary(new { controller ="UserInfo", action = "UserInformation",
                id = ""}),
            });

So, how am I going to create a unit test to ensure that when Users/123 is presented in the URL the action method UserInformation is definitely called, with 123 as the parameter?

The reason I asked this is because I could have typed the wrong name when I specify the RouteValueDictionary, I could have mistyped UserInformationss in the pace of UserInformation. Is there anyway to prevent this?

+1  A: 

Here is an article about unit testing custom routes:

http://weblogs.asp.net/stephenwalther/archive/2008/07/02/asp-net-mvc-tip-13-unit-test-your-custom-routes.aspx

aogan
+1  A: 

It's not important to test that the action UserInformation is called. It's only important to make sure that when the URL is specified, that "UserInformation" is in the route values dictionary with the key "action" and that there's a "controller" value with the appropriate controller name.

If so, the MVC framework guarantees that the UserInformation method will get called. You don't need to test our code via your unit test, just yours. If our code is incorrect, let us know and we'll add a unit test for our code. :)

Haacked
Haacked, I am trying to test my code here. The problem is that when I specify the names in route, I could have make a typo. So a unit test is need here.
Ngu Soon Hui
A: 

Question updated.

Ngu Soon Hui