Cannot test incoming routes

Jan 23, 2013 at 3:25 PM
Edited Jan 23, 2013 at 4:22 PM

Using MVC4. Testing of outgoing routes works fine. But testing of incoming routes doesn't work even if I use the example code:


tester.WithIncomingRequest("/").ShouldMatchRoute("Home", "Index");


The error is:

MvcRouteUnitTester.AssertionException : Route values mismatch. Expected: 0 route values, but was: 1 route values (for url: "/").


What am I doing wrong?

Jan 23, 2013 at 4:43 PM

After some fiddling, I think I understand, but not sure if it's a bug:

If I test a route I've explicitly defined in Global.asax, then the test works.

But if I test a route which I did not define, in other words I am relying on the default routing behavior, then the test fails with the above exception. This sort of test should work as well, I should not need to add dozens of routes just so I can then test them.

Am I missing something? I love this tool, but this bug/feature/whatever is confusing... Any advice appreciated!

Jan 23, 2013 at 5:24 PM

Confused the heck out of me as there is also a bug in the exception's text in  "MvcRouteUnitTester.RequestInfo.ShouldMatchRoute(string, string, object)"

if (expectedRouteValues == null) {
  throw new AssertionException(string.Format("Route values mismatch. Expected: 0 route values, but was: {0} route values (for url: \"{1}\").", actualRouteValuesDictionary.Count, this.requestUrl));

The "0" and "{0}" should be switched around.

And also, this code block is the source for my bug report above. But not sure how to fix it, if at all possible?