I cannot return the result .ViewName for use in Nunit tests, since it always returns string.empty. I explicitly set the view name inside my controller and expected the test to pick it up. I had a hunt around, and it seems that I should return the Viewname if I set it explicitly. Does anyone have any idea?
public class HomeController : Controller
{
public ActionResult Index()
{
return View("Index");
}
}
My test is as follows
[Test]
public void TestIndexView()
{
var controller = new HomeController();
var result = controller.Index() as ViewResult;
Assert.AreEqual("Index", result.ViewName);
}
Rippo source
share