示例#1
0
        public void AttemptLogin_signs_user_in_when_authentication_succeeds([Frozen] CSF.Security.Authentication.IPasswordAuthenticationService authService,
                                                                            [Frozen] ILogsUserInOrOut loginLogout,
                                                                            LoginLogoutManager sut,
                                                                            ILoginRequest request,
                                                                            LoginCredentials credentials,
                                                                            [HasIdentity] User user)
        {
            // Arrange
            user.Username = credentials.Username;
            Mock.Get(request)
            .Setup(x => x.GetCredentials())
            .Returns(credentials);
            Mock.Get(authService)
            .Setup(x => x.Authenticate(credentials))
            .Returns(new AuthenticationResult(user.GetIdentity(), user.Username, true));

            Mock.Get(loginLogout)
            .Setup(x => x.LogUserIn(It.IsAny <IAuthenticationResult>()));

            // Act
            sut.AttemptLogin(request);

            // Assert
            Mock.Get(loginLogout)
            .Verify(x => x.LogUserIn(It.IsAny <IAuthenticationResult>()), Times.Once());
        }
示例#2
0
        public LoginLogoutManager(IPasswordAuthenticationService authenticationService,
                                  ILogsUserInOrOut loginLogoutService,
                                  ILoginThrottlingService throttlingService)
        {
            if (loginLogoutService == null)
            {
                throw new ArgumentNullException(nameof(loginLogoutService));
            }
            if (throttlingService == null)
            {
                throw new ArgumentNullException(nameof(throttlingService));
            }
            if (authenticationService == null)
            {
                throw new ArgumentNullException(nameof(authenticationService));
            }

            this.authenticationService = authenticationService;
            this.loginLogoutService    = loginLogoutService;
            this.throttlingService     = throttlingService;
        }
示例#3
0
        public void AttemptLogin_does_not_log_user_in_when_user_is_not_found([Frozen] CSF.Security.Authentication.IPasswordAuthenticationService authService,
                                                                             [Frozen] ILogsUserInOrOut loginLogout,
                                                                             LoginLogoutManager sut,
                                                                             ILoginRequest request,
                                                                             LoginCredentials credentials)
        {
            // Arrange
            Mock.Get(request)
            .Setup(x => x.GetCredentials())
            .Returns(credentials);
            Mock.Get(authService)
            .Setup(x => x.Authenticate(credentials))
            .Returns(AuthenticationResult.UserNotFound);

            // Act
            sut.AttemptLogin(request);

            // Assert
            Mock.Get(loginLogout)
            .Verify(x => x.LogUserIn(It.IsAny <IAuthenticationResult>()), Times.Never());
        }
示例#4
0
        public void AttemptLogin_returns_success_result_when_authentication_succeeds([Frozen] CSF.Security.Authentication.IPasswordAuthenticationService authService,
                                                                                     [Frozen] ILogsUserInOrOut loginLogout,
                                                                                     LoginLogoutManager sut,
                                                                                     ILoginRequest request,
                                                                                     LoginCredentials credentials,
                                                                                     [HasIdentity] User user)
        {
            // Arrange
            Mock.Get(request)
            .Setup(x => x.GetCredentials())
            .Returns(credentials);
            Mock.Get(authService)
            .Setup(x => x.Authenticate(credentials))
            .Returns(new AuthenticationResult(user.GetIdentity(), user.Username, true));

            user.Username = credentials.Username;
            user.GenerateIdentity();

            // Act
            var result = sut.AttemptLogin(request);

            // Assert
            Assert.IsTrue(result.Success);
        }