Result.viewname is always string.empty

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);
    }
+3
source share
2 answers

Have you tried to clean and rebuild the solution? It should work without problems.

+2
source

return new View("Index");. C, , - View Index() (, , ), . C, # .

0

Source: https://habr.com/ru/post/1723608/


All Articles