public async Task ValidateAsync_AggregatesOnlySyncErrors()
        {
            var validators           = new List <INewPasswordValidatorBase>();
            var asyncValidationError = new ValidationError("test-async");

            var mockAsyncValidator = new Mock <IAsyncNewPasswordValidator>();

            mockAsyncValidator
            .Setup(v => v.ValidateAsync(It.IsAny <INewPasswordValidationContext>()))
            .ReturnsAsync(asyncValidationError);
            validators.Add(mockAsyncValidator.Object);

            var maxLengthValidator = new MaxLengthNewPasswordValidator();

            maxLengthValidator.Configure(6);
            validators.Add(maxLengthValidator);

            var uniqueCharsValidator = new MinUniqueCharactersNewPasswordValidator();

            uniqueCharsValidator.Configure(5);
            validators.Add(uniqueCharsValidator);

            var policy  = new PasswordPolicy("test", validators, new Dictionary <string, string>());
            var context = new NewPasswordValidationContext()
            {
                Password = "******"
            };

            var errors = await policy.ValidateAsync(context);

            errors.Should().HaveCount(2);
            errors.Should().NotContain(asyncValidationError);
        }
        public void WhenLessThanMaxLength_ReturnsSuccess(string password)
        {
            var validator = new MaxLengthNewPasswordValidator();

            validator.Configure(8);

            var context = new NewPasswordValidationContext()
            {
                Password = password
            };

            var result = validator.Validate(context);

            result.Should().BeNull();
        }
        public void WhenMoreThanMaxLength_ReturnsError()
        {
            var validator = new MaxLengthNewPasswordValidator();

            validator.Configure(8);

            var context = new NewPasswordValidationContext()
            {
                Password = "******"
            };

            var result = validator.Validate(context);

            result.Should().NotBeNull();
            result.ErrorCode.Should().Be(PasswordPolicyValidationErrors.MaxLengthExceeded.ErrorCode);
        }