I am trying to test an ActionResult
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.
I have left out the model creation because I want to just focus on the Request.Browser.Type
.
public ActionResult ActionName(string listing)
{
if (model.Count > 1 && Request.Browser.Type != "IE8" && Request.Browser.Type != "IE7")
{
return PartialView("~/Areas/Features/Views/Video/MultiVideo.cshtml", model);
}
return PartialView("~/Areas/Features/Views/Video/SingleVideo.cshtml", model.FirstOrDefault());
}
Ultimately I want to know two things
- How can you Mock the
Request.Browser.Type
if at all? - Is this even good practice to do inside your controller? If not what solutions would be better?
What I have tried:
var browser = new Mock<HttpContext>(MockBehavior.Strict);
browser.Setup(x => x.Request.Browser).Returns("IE9");