asp.net-mvc - 为什么这个 ViewResult 失败了 MSpecMVC 的 ShouldBeAView 断言?

标签 asp.net-mvc asp.net-mvc-2 mspec

我一直在关注 James Broome's tutorial自学 MSpec 和一些相关的基础设施。我使用的是最新版本的 MSpec,MSpecMvc和 ASP.NET MVC 2 并且我没有使用 J.P 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();
}

我收到以下错误

should return the home view : Failed
Should be of type System.Web.Mvc.ViewResult but is of type System.Web.Mvc.ViewResult



当我单步执行代码时,它会在此方法中的断言(在 MSpecMVC 的 ActionResultExtensions.cs 文件中)
public static ViewResultAnd ShouldBeAView(this ActionResult actionResult)
{
    actionResult.ShouldBeOfType<ViewResult>();
    return new ViewResultAnd(actionResult as ViewResult);
}

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

最佳答案

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

关于asp.net-mvc - 为什么这个 ViewResult 失败了 MSpecMVC 的 ShouldBeAView 断言?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4361185/

相关文章:

ajax - jQuery Ajax(发送前和完成)在 FireFox 上正常工作,但在 IE8 和 Chrome 上无法正常工作

asp.net-mvc - 即使在有效的 ViewResults 上,Machine.Specifications.MVC ShouldBeAView() 也总是失败

asp.net-mvc - 为 MVC5 中的操作授权参数

asp.net - 如果在 ASP.NET MVC4 中使用捆绑和缩小,如何创建 list

c# - 使用 .net MVC RadioButtonFor() 时,如何分组以便只能进行一个选择?

c# - 如何在继承类的规范中包含基类的规范?

c# - 如何让 ReSharper 停止在我的 MSpec 成员上放置显式访问修饰符?

c# - 数据验证 ASP MVC OnActionExecuting

javascript - flot.js 图表中的单点有问题

c# - 枚举(estring)的字符串表示?