title: Mocking Request.Browser.Type in Unit Tests
body: <p>I am trying to test an <code>ActionResult</code> that returns a partial view.  This action checks to see if the user is using IE7 or IE8 and will return a different partial if the user is using IE7 or 8.  This is because the java-script we are using doesn't quite work with 7 or 8 so we will treat it differently. </p>
  
  <p>I have left out the model creation because I want to just focus on the <code>Request.Browser.Type</code>.</p>
  
  <pre><code>public ActionResult ActionName(string listing)
  {
      if (model.Count &gt; 1 &amp;&amp; Request.Browser.Type != "IE8" &amp;&amp; Request.Browser.Type != "IE7")
      {
          return PartialView("~/Areas/Features/Views/Video/MultiVideo.cshtml", model);
      }
      return PartialView("~/Areas/Features/Views/Video/SingleVideo.cshtml", model.FirstOrDefault());
  }
  </code></pre>
  
  <p>Ultimately I want to know two things</p>
  
  <ol>
  <li>How can you Mock the <code>Request.Browser.Type</code> if at all?</li>
  <li>Is this even good practice to do inside your controller?  If not what solutions would be better?</li>
  </ol>
  
  <p>What I have tried:</p>
  
  <p><code>var browser = new Mock&lt;HttpContext&gt;(MockBehavior.Strict);
              browser.Setup(x =&gt; x.Request.Browser).Returns("IE9");</code></p>