Say I have a view with the following code at the top of the page:

@{
    ViewBag.Title = "About Us";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

And I have a controller method:

    public ActionResult About()
    {
        return View();
    }

How can I test that the ViewBag was set properly?

I have tried the following code.

[TestCase]
public void About()
{
    var controller = new AboutController();
    var ar = controller.About() as ViewResult;
    Assert.AreEqual("About Us", ar.ViewBag.Title);
}

But I get the following result when I run the test:

Tests.Controllers.AboutControllerTests.About():
    Expected: "About Us"
    But was: null
Edit
Report