Geeks With Blogs
.Nettuce Code Salad
 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 | Back to top


Comments on this post: HttpContext with mock IPrincipal

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Jon Canning | Powered by: GeeksWithBlogs.net