Created
July 24, 2013 12:44
-
-
Save csharpforevermore/6070228 to your computer and use it in GitHub Desktop.
Mock the HttpContext object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Taken from http://visualstudiofeeds.com/index.php?option=com_content&view=article&id=28667%3AHttpContext+with+mock+IPrincipal&catid=204%3Anettuce&Itemid=54&utm_source=dlvr.it&utm_medium=twitter