public void Login_ShouldReturnViewIfModelIsInvalid() { // Setup invalid model AccountController controller = _controller.Build(); controller.ModelState.AddModelError("Test Error", "Test Error Message"); // Call Login method ActionResult result = controller.Login(new LoginViewModel()).Result; // Verify result result.AssertIsView("Login"); }
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_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()); }