public static void StubLoggedInStatus(Controller controller, NKanbanPrincipal user, bool loggedin = true) { //stub out HttpContext.Request.IsAuthenticated and HttpContext.Request.User var stubContext = A.Fake<HttpContextBase>(); var stubRequest = A.Fake<HttpRequestBase>(); A.CallTo(() => stubContext.Request).Returns(stubRequest); A.CallTo(() => stubRequest.IsAuthenticated).Returns(loggedin); A.CallTo(() => stubContext.User).Returns(user); controller.ControllerContext = new ControllerContext(stubContext, new RouteData(), controller); }
protected void Application_AuthenticateRequest(object sender, EventArgs e) { //TODO - Add code to ignore requests for assets like images, js, css, etc if (HttpContext.Current == null || HttpContext.Current.User == null) { return; } var customPrincipal = new NKanbanPrincipal(new NKanbanIdentity(new FormsIdentityWrapper(HttpContext.Current.User.Identity))); HttpContext.Current.User = customPrincipal; Thread.CurrentPrincipal = customPrincipal; }