views:

98

answers:

3

I have a hybrid ASP.NET MVC application, and I'd like to test that the route table properly allows my .aspx pages to be loaded. In particular I'm interested in making sure that the root of my site goes to index.aspx, not to a controller.

Update: You can test for the Ignored paths in the routing table. However, this doesn't test for the route on the root if you haven't provided a default controller. The routeData comes out null.

A: 

Well that's easy. Root always goes to Default.aspx, even in "pure" MVC. MVC apps have a special Default.aspx to reroute to Home/Index. Yours will be a real page, instead.

Craig Stuntz
This is only true, as far as it goes, in IIS6, correct? II7 in integrated pipeline mode goes straight to your routing, I believe.Also, even if Default.aspx is the first thing the runtime loads, it doesn't actually get displayed if the routing overrides it, Rights?
JoshRivers
Try it: Navigate to / in IIS7. If you're redirected to /Home/Index, that's Default.aspx.cs at work. If you see /Home/Index *without a redirect*, then routing is defaulting that action.
Craig Stuntz
+1  A: 

You could try Phil Haack's route debugger, although what Craig said is correct.

Dan Atkinson
Can you use this in a unit test? It looks like it's a debugger, not a testing tool.
JoshRivers
To unit test, I would look here: http://bit.ly/13Dr06. This is a previous SO question which was answered for beta 1, but I have no reason to believe that this wouldn't work for the full version. The answer links to here: http://bit.ly/hOzSb.
Dan Atkinson
+2  A: 

MvcContrib has a RouteTestingExtensions class in their TestHelper. This is how I test routes. The tests end up looking like this:

"~/computer-accessories/".ShouldMapTo<CategoryController>(x => x.Accessories());
Chris Missal
I didn't know about this one! Thanks! :D
Dan Atkinson