public static class HttpContextBuilder
{
public static HttpContext Build(string userName = null, string url = null)
{
var httpContext = new HttpContext(new HttpRequest("", url ?? "http://test", ""), new HttpResponse(new StringWriter()));
if (!userName.IsNullOrWhiteSpace())
{
var principal = Substitute.For<IPrincipal>();
principal.Identity.Name.Returns(userName);
httpContext.User = principal;
}
return httpContext;
}
}