views:

938

answers:

1

I'm trying to set up Route mapping tests using MVC Contrib as described in Test ASP.NET MVC routes using MVC Contrib

The tests compile and execute, but they always fail with the message "The URL did not match any route."

I set up another test to try to get an idea of what the problem is:

    Public Sub TestIndexRoute()
        Dim routes = New RouteCollection
        myMvcApp.MvcApplication.RegisterRoutes(routes)
        Assert.That(routes.Count > 0)
        Assert.NotNull(routes("Default"), "Default route not found.")
        Dim routeData = RouteTestingExtensions.Route("~/Author")
        Assert.NotNull(routeData, "routeData is Nothing.")
        Assert.That(routeData.Values("controller") = "Author")
    End Sub

That test fails on Assert.NotNull(routeData, "routeData is Nothing."), so I know that there must be some problem with the MVCContrib code that is trying to access my app's RouteCollection.

From the blog post:

It also assumes you set your routes in the ASP.NET MVC RouteCollection object.

How do I confirm that I'm doing that? I'm using routes.MapRoute within MvcApplication.RegisterRoutes method in the Global.asax code behind. Is there something else to do to set this up properly?

Edit: I should probably mention that I'm new to unit testing. I've been putting off learning it for too long and this seemed like as good a place to start as any.

+3  A: 

Try:

MvcApplication.RegisterRoutes(RouteTable.Routes);

instead of:

Dim routes = New RouteCollection
myMvcApp.MvcApplication.RegisterRoutes(routes)

See RouteTestingExtensions, line 43

eu-ge-ne
Thanks! That's the piece I was missing!
Dennis Palmer