Esempio n. 1
0
        public void Login_redirects_to_return_url_after_successful_login([Frozen] ILoginLogoutManager loginLogoutManager,
                                                                         [Frozen] IValidatesRedirectUrls redirectValidator,
                                                                         Agiil.Web.Models.Auth.LoginCredentials credentials,
                                                                         string username,
                                                                         [NoAutoProperties] LoginController sut)
        {
            // Arrange
            Mock.Get(loginLogoutManager)
            .Setup(x => x.AttemptLogin(It.IsAny <ILoginRequest>()))
            .Returns(new LoginResult(username));
            credentials.ReturnUrl = "/Sample/Url";
            Mock.Get(redirectValidator)
            .Setup(x => x.IsValid(It.IsAny <string>()))
            .Returns(true);

            // Act
            var result = sut.Login(credentials);

            // Assert
            Assert.IsInstanceOf <RedirectResult>(result, "Result is a redirect-to-URL");
            var redirect = (RedirectResult)result;

            Assert.AreEqual("/Sample/Url", redirect.Url, "Correct URL");
            Assert.IsFalse(redirect.Permanent, "Non-permanent redirect");
        }
Esempio n. 2
0
        public void Login_ignores_return_url_if_it_is_not_valid([Frozen] ILoginLogoutManager loginLogoutManager,
                                                                [Frozen] IValidatesRedirectUrls redirectValidator,
                                                                Agiil.Web.Models.Auth.LoginCredentials credentials,
                                                                string username,
                                                                [NoAutoProperties] LoginController sut)
        {
            // Arrange
            Mock.Get(loginLogoutManager)
            .Setup(x => x.AttemptLogin(It.IsAny <ILoginRequest>()))
            .Returns(new LoginResult(username));
            credentials.ReturnUrl = "/Sample/Url";
            Mock.Get(redirectValidator)
            .Setup(x => x.IsValid(It.IsAny <string>()))
            .Returns(false);

            // Act
            var result = sut.Login(credentials);

            // Assert
            Assert.IsInstanceOf <RedirectToRouteResult>(result, "Result is a redirect-to-URL");
            var redirect = (RedirectToRouteResult)result;

            Assert.AreEqual("Login", redirect.RouteValues["controller"], "Correct controller");
            Assert.AreEqual(nameof(LoginController.Index), redirect.RouteValues["action"], "Correct action");
        }
Esempio n. 3
0
        public void Login_uses_login_logout_manager_service([Frozen] ILoginLogoutManager loginLogoutManager,
                                                            Agiil.Web.Models.Auth.LoginCredentials credentials,
                                                            [NoAutoProperties] LoginController sut)
        {
            // Arrange
            Mock.Get(loginLogoutManager)
            .Setup(x => x.AttemptLogin(It.IsAny <ILoginRequest>()))
            .Returns(LoginResult.LoginFailed);

            // Act
            sut.Login(credentials);

            // Assert
            Mock.Get(loginLogoutManager).Verify(x => x.AttemptLogin(It.IsAny <ILoginRequest>()), Times.Once());
        }
Esempio n. 4
0
        public void Login_ignores_return_url_on_failed_login([Frozen] ILoginLogoutManager loginLogoutManager,
                                                             Agiil.Web.Models.Auth.LoginCredentials credentials,
                                                             [NoAutoProperties] LoginController sut)
        {
            // Arrange
            Mock.Get(loginLogoutManager)
            .Setup(x => x.AttemptLogin(It.IsAny <ILoginRequest>()))
            .Returns(LoginResult.LoginFailed);
            credentials.ReturnUrl = "/Sample/Url";

            // Act
            var result = sut.Login(credentials);

            // Assert
            Assert.IsInstanceOf <RedirectToRouteResult>(result, "Result is a redirect-to-route");
            var redirect = (RedirectToRouteResult)result;

            Assert.AreEqual("Login", redirect.RouteValues["controller"], "Correct controller");
            Assert.AreEqual(nameof(LoginController.Index), redirect.RouteValues["action"], "Correct action");
        }
Esempio n. 5
0
        public void Login_redirects_to_home_controller_after_successful_login([Frozen] ILoginLogoutManager loginLogoutManager,
                                                                              Agiil.Web.Models.Auth.LoginCredentials credentials,
                                                                              string username,
                                                                              [NoAutoProperties] LoginController sut)
        {
            // Arrange
            Mock.Get(loginLogoutManager)
            .Setup(x => x.AttemptLogin(It.IsAny <ILoginRequest>()))
            .Returns(new LoginResult(username));
            credentials.ReturnUrl = null;

            // Act
            var result = sut.Login(credentials);

            // Assert
            Assert.IsInstanceOf <RedirectToRouteResult>(result, "Result is a redirect-to-route");
            var redirect = (RedirectToRouteResult)result;

            Assert.AreEqual("Login", redirect.RouteValues["controller"], "Correct controller");
            Assert.AreEqual(nameof(LoginController.Index), redirect.RouteValues["action"], "Correct action");
        }