Skip to content

Instantly share code, notes, and snippets.

@wbsimms
Created April 30, 2015 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wbsimms/e1ba771a5196e2e70424 to your computer and use it in GitHub Desktop.
Save wbsimms/e1ba771a5196e2e70424 to your computer and use it in GitHub Desktop.
TestControllerContext
using System.Security.Principal;
using System.Web;
using System.Web.Mvc;
namespace PracticeTime.Web.Test.Controllers
{
public class TestControllerContext : ControllerContext
{
private string userName = "student";
public string UserName
{
get { return this.userName; }
set { this.userName = value; }
}
public override HttpContextBase HttpContext { get { return new TestHttpContext(){UserName = this.UserName}; }
set { base.HttpContext = value; }
}
}
public class TestHttpContext : HttpContextBase
{
private string userName = "student";
public string UserName {
get { return this.userName; }
set { this.userName = value; }
}
public override IPrincipal User
{
get
{
return new TestPrincipal(UserName);
}
set
{
base.User = value;
}
}
}
public class TestPrincipal : IPrincipal
{
private string userName = "student";
public TestPrincipal(string userName)
{
this.userName = userName;
}
public bool IsInRole(string role)
{
return true;
}
public IIdentity Identity
{
get { return new GenericIdentity(userName); }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment