需要有关使用 MvcContrib.TestHelper 的 ShouldMapTo() 通用扩展方法的错误的帮助

发布于 2024-08-23 19:43:47 字数 1088 浏览 3 评论 0原文

我尝试使用 MvcContrib.TestHelper ShouldMapTo() 扩展方法对我的路线进行单元测试,但我的测试失败并显示以下错误消息:

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

但 ReviewController 确实满足约束。它继承自一个名为 SmartController 的类,该类又继承自 System.Web.Mvc.Controller。因此我不知道如何解决这个错误。

这是我的单元测试:

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

这是 ReviewController 类的声明:

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

和 SmartController 类的声明:

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

只是为了笑,我尝试从继承层次结构中删除 SmartController,以便 ReviewController 直接从 Controller 继承,但仍然抛出错误。

有谁知道我做错了什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单爱 2024-08-30 19:43:47

我将此方法与 MVC 2 和使用 MVC 2 构建的 MvcContrib 一起使用,一切正常。我发现了这个问题:

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

您是否在 MVC 2 中使用旧的 MvcContrib 程序集(使用 MVC1 构建)?如果是,您应该下载 MvcContrib 二进制文件或 MVC 2 的源代码。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文