.Nettuce

Code Salad

  Home  |   Contact  |   Syndication    |   Login
  34 Posts | 0 Stories | 33 Comments | 0 Trackbacks

News

Twitter












Archives

 public static class HttpContextBuilder
    {
        public static HttpContext Build(string userName = nullstring 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;
        }
    }
posted on Friday, February 1, 2013 4:06 PM