title: Is there a way to unit test ASP.NET MVC ViewBag properties set in the view?
body: <p>Say I have a view with the following code at the top of the page:</p>
  
  <pre><code>@{
      ViewBag.Title = "About Us";
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  </code></pre>
  
  <p>And I have a controller method:</p>
  
  <pre><code>    public ActionResult About()
      {
          return View();
      }
  </code></pre>
  
  <p>How can I test that the ViewBag was set properly?</p>
  
  <p>I have tried the following code.</p>
  
  <pre><code>[TestCase]
  public void About()
  {
      var controller = new AboutController();
      var ar = controller.About() as ViewResult;
      Assert.AreEqual("About Us", ar.ViewBag.Title);
  }
  </code></pre>
  
  <p>But I get the following result when I run the test:</p>
  
  <pre><code>Tests.Controllers.AboutControllerTests.About():
      Expected: "About Us"
      But was: null
  </code></pre>