Need help with error using MvcContrib.TestHelper's ShouldMapTo() generic extension method
Asked Answered
S

1

10

I'm trying to unit test my routes using the MvcContrib.TestHelper ShouldMapTo<TController>() extension method, but my tests fail with the following error message:

failed: Method MvcContrib.TestHelper.RouteTestingExtensions.ShouldMapTo:
type argument 'ReviewController' violates the constraint of type parameter
'TController'.

But ReviewController does meet the constraint. It inherits from a class called SmartController, which inherits from System.Web.Mvc.Controller. Thus I am at a loss as to how to resolve this error.

Here is my unit test:

[Test]
public void Should_map_review_controller_routes_correctly()
{
    MvcApplication.RegisterRoutes(RouteTable.Routes);
    "~/reviews"
        .ShouldMapTo<ReviewController>(c => c.Index());
}

Here is the declaration of the ReviewController class:

public class ReviewController : SmartController<Review, ReviewForm>
{
...
}

And the declaration of the SmartController class:

public abstract class SmartController<TModel, TForm> : Controller
    where TModel : new()
{
...
}

Just for grins I tried removing SmartController from the inheritance hierarchy so that ReviewController inherits directly from Controller, but the error is still thrown.

Does anyone know what I'm doing wrong?

Splenitis answered 5/3, 2010 at 20:48 Comment(0)
F
4

I used this method with MVC 2 and MvcContrib built with MVC 2 and everything worked fine. I found this problem:

http://groups.google.com/group/mvccontrib-discuss/browse_thread/thread/356203db654fa4bd?pli=1

Are you using old MvcContrib assembly (built with MVC1) with MVC 2? If yes, you should download MvcContrib binaries or sources for MVC 2.

Foilsman answered 6/3, 2010 at 1:23 Comment(2)
Thanks LukLed. That did the trick. I had to update my Rhino.Mocks assembly to work with the new MvcContrib release, but with that in place my tests pass now, so I'm good to go. I really appreciate it.Splenitis
You'll get the same situation if you use the MVC 2 MvcContrib assemblies with an MVC 3 solution. Update to the latest MvcContrib release and all should be fine.Prejudge

© 2022 - 2024 — McMap. All rights reserved.