Skip to content

Instantly share code, notes, and snippets.

@half-ogre
Created July 3, 2011 08:02
Show Gist options
  • Save half-ogre/1062053 to your computer and use it in GitHub Desktop.
Save half-ogre/1062053 to your computer and use it in GitHub Desktop.
It is way too hard to fake a call to Controller.Url.IsLocalUrl, which means I failed as a tester that day.
public static UrlHelper CreateUrlHelperToFakeIsLocalUrl(string fakeRequestUrl)
{
var httpContextBase = new Mock<HttpContextBase>();
httpContextBase.Setup(x => x.Request.Url).Returns(new Uri(fakeRequestUrl));
var requestContext = new RequestContext(httpContextBase.Object, new RouteData());
return new UrlHelper(requestContext);
}
// controller.Url = CreateUrlHelperToFakeIsLocalUrl("http://aFakeHost/aFakePage");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment