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?
public virtual ActionResult Add()
{
return View(MVC.JobSearch.Views.Edit, new JobSearch());
}
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 :)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With