title: Unit Test Controller Session Variables in MVC3
body: <p>I am unit testing my controller.</p>
  
  <p>In one of my controller methods I am setting Session variables:</p>
  
  <pre><code> public void Index(){
        Session["foo"] = "bar";
  
        return View();
   }
  </code></pre>
  
  <p>How can I unit test this? The problem is that the Session property is null when testing. Injecting is not possible because the Session property is readonly.</p>
  
  <pre><code> [TestMethod]
   public void TestIndex()
       // When
       _controller.Index();
  
       // Then
       Assert.AreEqual("bar", _controller.Session["foo"])
  </code></pre>