Пример #1
0
        public void Should_PassValidation_When_AllRulesPass()
        {
            // Arrange
            var loginDtoValidator = new LoginDtoValidator();
            var loginDto          = new LoginDto(username: "******", password: "******");

            // Act
            var result  = loginDtoValidator.Validate(loginDto, ruleSet: "UsernameAndPassword");
            var isValid = result.IsValid;

            // Assert
            isValid.Should().Be(true);
        }
Пример #2
0
        public void Should_FailValidationWithMessage_When_UsernameContainsSpecialCharacters()
        {
            // Arrange
            var loginDtoValidator = new LoginDtoValidator();
            var loginDto          = new LoginDto(username: "******", password: "******");

            // Act
            var result  = loginDtoValidator.Validate(loginDto, ruleSet: "UsernameAndPassword");
            var isValid = result.IsValid;
            var errors  = result.Errors;

            // Assert
            isValid.Should().Be(false);
            errors.Count.Should().Be(1);
            errors[0].ToString().Should().Be("Username must not contain spaces and special characters.");
        }
Пример #3
0
        public void Should_FailValidationWithMessage_When_PasswordContainsSpaces()
        {
            // Arrange
            var loginDtoValidator = new LoginDtoValidator();
            var loginDto          = new LoginDto(username: "******", password: "******");

            // Act
            var result  = loginDtoValidator.Validate(loginDto, ruleSet: "UsernameAndPassword");
            var isValid = result.IsValid;
            var errors  = result.Errors;

            // Assert
            isValid.Should().Be(false);
            errors.Count.Should().Be(1);
            errors[0].ToString().Should().Be("Password must not be empty or contain spaces.");
        }
Пример #4
0
        public void Should_FailValidationWithMessage_When_PasswordIsMoreThan64Characters()
        {
            // Arrange
            var loginDtoValidator = new LoginDtoValidator();
            var loginDto          = new LoginDto(username: "******", password: "******");

            // Act
            var result  = loginDtoValidator.Validate(loginDto, ruleSet: "UsernameAndPassword");
            var isValid = result.IsValid;
            var errors  = result.Errors;

            // Assert
            isValid.Should().Be(false);
            errors.Count.Should().Be(1);
            errors[0].ToString().Should().Be("Password must be at least 8 characters and less than or equal to 64.");
        }
Пример #5
0
        public void Should_FailValidationWithMessage_When_UsernameIsNull()
        {
            // Arrange
            var loginDtoValidator = new LoginDtoValidator();
            var loginDto          = new LoginDto(username: null, password: "******");

            // Act
            var result  = loginDtoValidator.Validate(loginDto, ruleSet: "UsernameAndPassword");
            var isValid = result.IsValid;
            var errors  = result.Errors;

            // Assert
            isValid.Should().Be(false);
            errors.Count.Should().Be(2);
            errors[0].ToString().Should().Be("Username is required.");
            errors[1].ToString().Should().Be("Username is required.");
        }
Пример #6
0
        public void Should_FailValidationWithMessage_When_PasswordIsEmpty()
        {
            // Arrange
            var loginDtoValidator = new LoginDtoValidator();
            var loginDto          = new LoginDto(username: "******", password: "");

            // Act
            var result  = loginDtoValidator.Validate(loginDto, ruleSet: "UsernameAndPassword");
            var isValid = result.IsValid;
            var errors  = result.Errors;

            // Assert
            isValid.Should().Be(false);
            errors.Count.Should().Be(3);
            errors[0].ToString().Should().Be("Password is required.");
            errors[1].ToString().Should().Be("Password must be at least 8 characters and less than or equal to 64.");
            errors[2].ToString().Should().Be("Password must not be empty or contain spaces.");
        }
Пример #7
0
        public void ValidateBeforeLogin(LoginDto userForLogin)
        {
            var validator = new LoginDtoValidator();

            CheckValidationResults(validator.Validate(userForLogin));
        }