Skip to content

Instantly share code, notes, and snippets.

@AlexArchive
Created July 5, 2014 13:51
Show Gist options
  • Save AlexArchive/8fbbb425bc60f582780e to your computer and use it in GitHub Desktop.
Save AlexArchive/8fbbb425bc60f582780e to your computer and use it in GitHub Desktop.
public static void SetFakeControllerContext(this Controller controller, NameValueCollection querystring = null)
{
var context = new Mock<HttpContextBase>();
context.Setup(c => c.Request.QueryString).Returns(querystring ?? new NameValueCollection());
controller.ControllerContext = new ControllerContext(context.Object, new RouteData(),
new Mock<ControllerBase>().Object);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment