public void LogOff() { var userManager = new UserManager<ApplicationUser>(new TestUserStore()); var mockAuthenticationManager = new Mock<IAuthenticationManager>(); mockAuthenticationManager.Setup(am => am.SignOut()); mockAuthenticationManager.Setup(am => am.SignIn()); AccountController controller = new AccountController(userService, userProfileService, goalService, updateService, commentService, followRequestService, followUserService, securityTokenService, userManager); controller.AuthenticationManager = mockAuthenticationManager.Object; var httprequest = new HttpRequest("", "http://localhost/", ""); var stringWriter = new StringWriter(); var httpResponce = new HttpResponse(stringWriter); var httpContext = new HttpContext(httprequest, httpResponce); var sessionContainer = new HttpSessionStateContainer("id", new SessionStateItemCollection(), new HttpStaticObjectsCollection(), 10, true, HttpCookieMode.AutoDetect, SessionStateMode.InProc, false); httpContext.Items["AspSession"] = typeof(HttpSessionState).GetConstructor( BindingFlags.NonPublic | BindingFlags.Instance, null, CallingConventions.Standard, new[] { typeof(HttpSessionStateContainer) }, null) .Invoke(new object[] { sessionContainer }); HttpContext.Current = httpContext; var result = controller.LogOff() as RedirectToRouteResult; Assert.AreEqual("Index", result.RouteValues["action"]); }