Search code examples
c#asp.net-mvcasp.net-mvc-3mvccontribmvccontrib-testhelper

Why does mvccontrib's AssertViewRendered().ForView("Edit") fail due to view name being full cshtml path?


I have the following unit test:

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

        // Verify
        result.AssertViewRendered().ForView("Edit");
    }

This should be passing, since the Add action is returning the Edit view. However, this assertion fails with the following exception

MvcContrib.TestHelper.ActionResultAssertionException: Expected view name 'Edit', actual was '~/Views/JobSearch/Edit.cshtml'

Why is the view name coming back as the full path name? Could this be due to my usage of T4MVC, and if so how can I get this to pass?


Edit The Add view looks like this:

    public virtual ActionResult Add()
    {
        return View(MVC.JobSearch.Views.Edit, new JobSearch());
    }

Solution

  • You can test against the T4MVC value like this :

    result.AssertViewRendered().ForView(MVC.JobSearch.Views.Edit);
    

    I think it's the cleaner solution... If you have better let me know :)