Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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());
    }
like image 615
KallDrexx Avatar asked Oct 12 '22 09:10

KallDrexx


2 Answers

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 :)

like image 192
VinnyG Avatar answered Oct 15 '22 10:10

VinnyG


Ok I guess I just didn't investigate into the T4MVC code to get a better look at what is happening. It seems that the MVC.JobSearch.Views.Edit is equal to "~/Views/JobSearch/Edit.cshtml", and so .ForView() is testing against the same exact view name that is described in the View() method call.

Thanks for the help.

like image 31
KallDrexx Avatar answered Oct 15 '22 10:10

KallDrexx