2

我一直在按照James Broome 的教程自学 MSpec 和一些相关的基础设施。我使用的是最新版本的 MSpec、MSpecMvc和 ASP.NET MVC 2,但我没有使用 JP Boodhoo 的库。

当我运行这个测试

[Subject(typeof(HomeController))]
public class when_the_home_controller_is_told_to_display_the_default_view
{
    static string key;
    static string message;
    static ActionResult result;
    static HomeController home_controller;

    Establish context = () =>
    {
        key = "Message";
        message = "Welcome to ASP.NET MVC!";
        home_controller = new HomeController();
    };

    Because of = () => result = home_controller.Index();

    It should_return_the_home_view = () => result.ShouldBeAView().And().ViewName.ShouldBeEmpty();
}

我收到以下错误

应该返回主视图:失败
应该是 System.Web.Mvc.ViewResult 类型,但属于 System.Web.Mvc.ViewResult 类型

当我单步执行代码时,它会在此方法中的断言中出现问题(在ActionResultExtensions.csMSpecMVC 的文件中)

public static ViewResultAnd ShouldBeAView(this ActionResult actionResult)
{
    actionResult.ShouldBeOfType<ViewResult>();
    return new ViewResultAnd(actionResult as ViewResult);
}

虽然,我可以确认它actionResult是 type System.Web.Mvc.ViewResult。我在另一台计算机上使用了相同的工具来运行其他测试,但我没有遇到当前问题。

4

1 回答 1

3

James Broome 的 MSpec.MVC 扩展使用 Mspec v0.2。由于您使用的是 Mspec v0.3,因此存在不匹配。您应该获取源并更新解决方案以使用 MSpec v0.3。

确保 Mspec.MVC 扩展的目标与您的 ASP.NET MVC 解决方案相同的 .NET Framwork 版本(例如,两者都是 4.0)。这也取决于您使用的 MSpec 版本。MSpec v0.3 是针对两者编译.NET 3.5.NET 4.0

于 2010-12-08T19:36:06.020 回答