public void OneTimeSetUp() { var authenticatedIdentity = new MockIdentity(true); var authenticatedUser = new ClaimsPrincipal(authenticatedIdentity); authenticatedIdentity.AddClaim(new Claim("ID", "123")); _authenticationManager = new FakeAuthenticationManager() .WithUser(authenticatedUser).Build().Object; }
public void Login_ShouldDisplayLoginPageForUnauthenticatedUser() { // Setup Authentication Manager var unAuthenticatedIdentity = new MockIdentity(); var authenticatedUser = new ClaimsPrincipal(unAuthenticatedIdentity); var authenticationManager = new FakeAuthenticationManager() .WithUser(authenticatedUser).Build(); // Call login method ActionResult result = _controller .WithAuthenticationManager(authenticationManager.Object).Build() .Login(); // Verify Login view is returned result.AssertIsView("Login"); }
public void Login_ShouldRedirectAuthenticatedUserToHomePage() { // Setup Authentication Manager var authenticatedIdentity = new MockIdentity(true); var authenticatedUser = new ClaimsPrincipal(authenticatedIdentity); var authenticationManager = new FakeAuthenticationManager() .WithUser(authenticatedUser).Build(); // Call login method ActionResult result = _controller .WithAuthenticationManager(authenticationManager.Object).Build() .Login(); // Verify user is redirected to Home page result.AssertIsRedirect("Home", "Index"); }
public void Login_ShouldSetReturnUrlIfProvided() { // Setup Authentication Manager var unAuthenticatedIdentity = new MockIdentity(); var authenticatedUser = new ClaimsPrincipal(unAuthenticatedIdentity); var authenticationManager = new FakeAuthenticationManager() .WithUser(authenticatedUser).Build(); // Call login method ActionResult result = _controller .WithAuthenticationManager(authenticationManager.Object).Build() .Login("/TestReturnUrl"); // Verify expected result ViewResult returnedView = result.AssertIsView("Login"); Assert.AreEqual("/TestReturnUrl", returnedView.ViewBag.ReturnUrl.ToString()); }