Skip to content

Instantly share code, notes, and snippets.

@brenoferreira
Created July 23, 2012 16:31
Show Gist options
  • Save brenoferreira/3164589 to your computer and use it in GitHub Desktop.
Save brenoferreira/3164589 to your computer and use it in GitHub Desktop.
Fake HttpContext.Current
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