public void Should_return_false_when_token_is_missing_or_invalid(string token)
        {
            // Given
            var fakeUser = new User();
            var passwordService = new PasswordService(A.Dummy<ICryptoService>());

            // When
            var isValid = passwordService.IsPasswordValid(fakeUser, token);

            // Then
            isValid.ShouldBe(false);
        }
        public void Should_return_false_when_supplied_parameters_are_missing_or_invalid(string password, string hash, string salt)
        {
            // Given
            var fakeUser = new User() { Salt = salt, Hash = hash };
            var passwordService = new PasswordService(new PBKDF2());

            // When
            var isValid = passwordService.IsPasswordValid(fakeUser, password);

            // Then
            isValid.ShouldBe(false);
        }
        public void Should_return_true_when_password_matches_user_password()
        {
            // Given
            var token = MakeFake.Guid;
            var fakeUser = new User() { ForgotPasswordRequestToken= token, ForgotPasswordRequestDate = DateTime.Now };
            var passwordService = new PasswordService(A.Dummy<ICryptoService>());

            // When
            var isValid = passwordService.IsForgotPasswordTokenValid(fakeUser, token);

            // Then
            isValid.ShouldBe(true);
        }
        public void Should_return_false_when_user_is_missing()
        {
            // Given
            var token = MakeFake.Guid;
            User fakeUser = null;
            var passwordService = new PasswordService(A.Dummy<ICryptoService>());

            // When
            var isValid = passwordService.IsForgotPasswordTokenValid(fakeUser, token);

            // Then
            isValid.ShouldBe(false);
        }
        public void Should_return_true_when_supplied_password_matches_user_password()
        {
            // Given
            var password = MakeFake.Password;
            var fakeUser = new User() { Salt = MakeFake.Salt, Hash = MakeFake.Hash };
            var passwordService = new PasswordService(new PBKDF2());

            // When
            var isValid = passwordService.IsPasswordValid(fakeUser, password);

            // Then
            isValid.ShouldBe(true);
        }
        public void Should_return_false_when_supplied_user_is_missing()
        {
            // Given
            var password = MakeFake.Password;
            User fakeUser = null;
            var passwordService = new PasswordService(new PBKDF2());

            // When
            var isValid = passwordService.IsPasswordValid(fakeUser, password);

            // Then
            isValid.ShouldBe(false);
        }
        public void Should_return_false_when_minutes_elapsed_since_the_token_was_requested_is_greater_than_the_ForgotPasswordTimeLimit()
        {
            // Given
            var token = MakeFake.Guid;
            var requestDate = DateTime.MinValue;
            var fakeUser = new User() { ForgotPasswordRequestToken = token, ForgotPasswordRequestDate = requestDate };
            var passwordService = new PasswordService(A.Dummy<ICryptoService>());

            // When
            var isValid = passwordService.IsForgotPasswordTokenValid(fakeUser, token);

            // Then
            isValid.ShouldBe(false);
        }
        public void Should_return_generated_password_of_correct_length()
        {
            // Given
            var passwordService = new PasswordService(new PBKDF2());

            // When
            var password = passwordService.Generate();

            // Then
            password.ShouldNotBe(null);
            password.Hash.ShouldNotBe(null);
            password.Salt.ShouldNotBe(null);
            password.Clear.ShouldNotBe(null);
            password.Clear.Length.ShouldBe(PasswordService.PasswordCharactersCount);
        }