Ejemplo n.º 1
0
        public void Should_PassValidation_When_AllRulesPass()
        {
            // Arrange
            var userAccountDtoValidator = new UserAccountDtoValidator();
            var userAccountDto          = new UserAccountDto()
            {
                Username = "******",
                Password = "******"
            };

            // Act
            var result  = userAccountDtoValidator.Validate(userAccountDto, ruleSet: "CreateUser");
            var isValid = result.IsValid;

            // Assert
            isValid.Should().Be(true);
        }
Ejemplo n.º 2
0
        public void Should_FailValidationWithMessage_When_UsernameContainsSpaces()
        {
            // Arrange
            var userAccountDtoValidator = new UserAccountDtoValidator();
            var userAccountDto          = new UserAccountDto()
            {
                Username = "******",
                Password = "******"
            };

            // Act
            var result  = userAccountDtoValidator.Validate(userAccountDto, ruleSet: "CreateUser");
            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.");
        }
Ejemplo n.º 3
0
        public void Should_FailValidationWithMessage_When_PasswordIsMoreThan64Characters()
        {
            // Arrange
            var userAccountDtoValidator = new UserAccountDtoValidator();
            var userAccountDto          = new UserAccountDto()
            {
                Username = "******",
                Password = "******"
            };

            // Act
            var result  = userAccountDtoValidator.Validate(userAccountDto, ruleSet: "CreateUser");
            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.");
        }
Ejemplo n.º 4
0
        public void Should_FailValidationWithMessage_When_UsernameIsNull()
        {
            // Arrange
            var userAccountDtoValidator = new UserAccountDtoValidator();
            var userAccountDto          = new UserAccountDto()
            {
                Username = null,
                Password = "******"
            };

            // Act
            var result  = userAccountDtoValidator.Validate(userAccountDto, ruleSet: "CreateUser");
            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.");
        }
Ejemplo n.º 5
0
        public void Should_FailValidationWithMessage_When_PasswordIsEmpty()
        {
            // Arrange
            var userAccountDtoValidator = new UserAccountDtoValidator();
            var userAccountDto          = new UserAccountDto()
            {
                Username = "******",
                Password = ""
            };

            // Act
            var result  = userAccountDtoValidator.Validate(userAccountDto, ruleSet: "CreateUser");
            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.");
        }