为什么mvccontrib的AssertViewRendered().ForView("编辑")由于视图名称是完整的cshtml路径而失败?

Kal*_*exx 5 c# asp.net-mvc mvccontrib mvccontrib-testhelper asp.net-mvc-3

我有以下单元测试:

    [TestMethod]
    public void Add_Returns_Edit_View()
    {
        // Act
        ActionResult result = _controller.Add();

        // Verify
        result.AssertViewRendered().ForView("Edit");
    }
Run Code Online (Sandbox Code Playgroud)

这应该是传递,因为Add操作返回Edit视图.但是,此断言失败,并出现以下异常

MvcContrib.TestHelper.ActionResultAssertionException: Expected view name 'Edit', actual was '~/Views/JobSearch/Edit.cshtml'
Run Code Online (Sandbox Code Playgroud)

为什么视图名称将作为完整路径名返回?这可能是由于我对T4MVC的使用,如果是这样,我怎么能通过?


编辑 "添加"视图如下所示:

    public virtual ActionResult Add()
    {
        return View(MVC.JobSearch.Views.Edit, new JobSearch());
    }
Run Code Online (Sandbox Code Playgroud)

Vin*_*nyG 3

您可以像这样针对 T4MVC 值进行测试:

result.AssertViewRendered().ForView(MVC.JobSearch.Views.Edit);
Run Code Online (Sandbox Code Playgroud)

我认为这是更清洁的解决方案...如果您有更好的建议请告诉我:)