我一直在按照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.cs
MSpecMVC 的文件中)
public static ViewResultAnd ShouldBeAView(this ActionResult actionResult)
{
actionResult.ShouldBeOfType<ViewResult>();
return new ViewResultAnd(actionResult as ViewResult);
}
虽然,我可以确认它actionResult
是 type System.Web.Mvc.ViewResult
。我在另一台计算机上使用了相同的工具来运行其他测试,但我没有遇到当前问题。