Hi folks,
I'm doing some simple MS unit tests on my standard, nothing special controller.
When i check the ViewName
proprty, from the returned ViewResult
object, it's ""
(empty).
I'm under the impression that the ViewName
is implied by the name of the View
(as suggested by this MS article on ASP.NET MVC controller testing).
BTW, when i test the ViewData, it's all there and correct.
Here's the code i have...
public ActionResult Index(int? page, string tag)
{
if (page == null || page <= 0)
{
page = 1;
}
var viewData = new IndexViewData
{
... my property setters, etc ...
};
return View(viewData);
}
[TestMethod]
public void Index_Action_Should_Return_Index_View_For_Default_HomePage()
{
// Arrange.
var controller = PostController; // Wrapper, cause I use D.I.
// Act.
ViewResult viewResult = controller.Index(null, null) as ViewResult;
// Assert.
Assert.IsNotNull(viewResult);
Assert.AreEqual("Index", viewResult.ViewName); // This is false/fails.
var indexViewData = viewResult.ViewData.Model as IndexViewData;
Assert.IsNotNull(indexViewData); // This is true.
}