示例#1
0
        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");
        }
示例#2
0
        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");
        }
示例#3
0
        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());
        }
示例#4
0
        public void Login_ShouldAddModelErrorOnSignInFailure()
        {
            // Setup sign in manager
            var userManager           = new MockUserManager();
            var authenticationManager = new FakeAuthenticationManager().Build();
            var signInManager         = new MockSignInManager(userManager, authenticationManager.Object);

            AccountController controller = _controller
                                           .WithSignInManager(signInManager).Build();

            // Call Login method
            var request = new LoginViewModel {
                Email = "*****@*****.**", Password = "******"
            };
            ActionResult result = controller.Login(request).Result;

            // Verify result
            result.AssertIsStatus(HttpStatusCode.Forbidden);
        }
示例#5
0
        public void Register_ShouldSignInUserIfCreated()
        {
            // Setup dependencies
            var request = ConstructDefaultRegisterViewModel();

            var userManager = new MockUserManager()
                              .WithUserCreationResult(IdentityResult.Success);

            var authenticationManager = new FakeAuthenticationManager().Build();
            var signInManager         = new MockSignInManager(userManager, authenticationManager.Object);

            // Call register
            var result = _controller
                         .WithUserManager(userManager)
                         .WithSignInManager(signInManager).Build()
                         .Register(request).Result;

            // Verify result
            authenticationManager.Verify(
                a => a.SignIn(It.IsAny <AuthenticationProperties>(), It.IsAny <ClaimsIdentity[]>()), Times.Once);

            result.AssertIsRedirect("Home", "Index");
        }