Created
July 23, 2012 16:31
-
-
Save brenoferreira/3164589 to your computer and use it in GitHub Desktop.
Fake HttpContext.Current
This file contains hidden or 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
class PrincipalStub : IPrincipal | |
{ | |
public IIdentity Identity | |
{ | |
get { return new IdentityStub(); } | |
} | |
public bool IsInRole(string role) | |
{ | |
return true; | |
} | |
} | |
class IdentityStub : IIdentity | |
{ | |
public string AuthenticationType | |
{ | |
get { return "forms"; } | |
} | |
public bool IsAuthenticated | |
{ | |
get { return true; } | |
} | |
public string Name | |
{ | |
get { return "teste"; } | |
} | |
} | |
protected virtual void ConfigurarHttpContext() | |
{ | |
var context = new HttpContext(new HttpRequest("", URLBASE, ""), new HttpResponse(new StringWriter())); | |
context.User = new PrincipalStub(); | |
HttpContext.Current = context; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment