Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewResult.ViewName property empty in unit test

Tags:

asp.net-mvc

in my unit test, the ViewResult.ViewName property is always empty when i use the action name for the view:

return View(model);
or
return View();

Is that by design?

like image 372
Michel Avatar asked May 26 '10 11:05

Michel


2 Answers

Yes it is by design:

protected internal ViewResult View()
{
    return this.View(null, null, null);
}

Checkout MVCContrib.TestHelper for better syntax:

// act
var actual = controller.Index();

// assert
actual.AssertViewRendered();
like image 143
Darin Dimitrov Avatar answered Sep 18 '22 00:09

Darin Dimitrov


Looks like it is indeed:

protected internal ViewResult View()
{
    return this.View(null, null, null);
}

protected internal virtual ViewResult View(string viewName, 
    string masterName, object model)
{
    if (model != null)
    {
        base.ViewData.Model = model;
    }
    ViewResult result = new ViewResult();
    result.ViewName = viewName;
    result.MasterName = masterName;
    result.ViewData = base.ViewData;
    result.TempData = base.TempData;
    return result;
}
like image 22
Anton Gogolev Avatar answered Sep 21 '22 00:09

Anton Gogolev