예제 #1
0
        public void When_CNPJ_Is_Invalid_Then_The_Validator_Should_Fail(string cnpj)
        {
            TestExtensionsValidator validator = new TestExtensionsValidator(x => x.RuleFor(r => r.CNPJ).IsValidCNPJ());
            ValidationResult        result    = validator.Validate(new Person {
                CNPJ = cnpj
            });

            Assert.False(result.IsValid);
        }
예제 #2
0
        public void When_CNPJ_Is_Valid_Then_The_Validator_Should_Pass()
        {
            TestExtensionsValidator validator = new TestExtensionsValidator(x => x.RuleFor(r => r.CNPJ).IsValidCNPJ());
            ValidationResult        result    = validator.Validate(new Person {
                CNPJ = "11.434.325/0001-07"
            });

            Assert.True(result.IsValid);
        }
        public void When_CPF_Is_Valid_Then_The_Validator_Should_Pass()
        {
            TestExtensionsValidator validator = new TestExtensionsValidator(x => x.RuleFor(r => r.CPF).IsValidCPF());
            ValidationResult        result    = validator.Validate(new Person {
                CPF = "822.420.106-62"
            });

            Assert.True(result.IsValid);
        }
예제 #4
0
        public void When_CPF_Is_Invalid_Then_The_Validator_Should_Fail(string cpf)
        {
            TestExtensionsValidator validator = new TestExtensionsValidator(x => x.RuleFor(r => r.CPF).IsValidCPF());
            ValidationResult        result    = validator.Validate(new Person {
                CPF = cpf
            });

            Assert.False(result.IsValid);
        }
        public void When_CPF_Is_Invalid_Then_The_Validator_Should_Fail(string cpf)
        {
            TestExtensionsValidator validator = new TestExtensionsValidator(x => x.RuleFor(r => r.CPF).IsValidCPF());
            ValidationResult        result    = validator.Validate(new Person {
                CPF = cpf
            });

            Assert.False(result.IsValid);
            Assert.Equal(result.Errors.First().ErrorMessage, "O CPF é inválido!");
        }
예제 #6
0
        public void When_CNPJ_Is_Invalid_Then_Set_Custom_Message_And_Validator_Should_Fail()
        {
            const string customMessage = "Custom Message";

            TestExtensionsValidator validator = new TestExtensionsValidator(x => x.RuleFor(r => r.CNPJ).IsValidCNPJ().WithMessage(customMessage));
            ValidationResult        result    = validator.Validate(new Person {
                CNPJ = "00.000.000/0000-00"
            });

            string errorMessage = result.Errors.FirstOrDefault()?.ErrorMessage ?? string.Empty;

            Assert.False(result.IsValid);
            Assert.Equal(customMessage, errorMessage);
        }
예제 #7
0
        public void When_PIS_Is_Valid_Then_Validator_Should_Pass(string pis)
        {
            // Arrange
            var validator = new TestExtensionsValidator(x => x.RuleFor(r => r.PIS).IsValidPIS());

            // Act
            var validationResult = validator.Validate(new Person {
                PIS = pis
            });

            // Assert
            Assert.True(validationResult.IsValid);
            Assert.Empty(validationResult.Errors);
        }
예제 #8
0
        public void When_PIS_Has_Invalid_Length_Then_Validator_Should_Fail(string pis)
        {
            // Arrange
            var errorMessage = "The PIS is invalid";
            var validator    = new TestExtensionsValidator(x => x.RuleFor(r => r.PIS).IsValidPIS().WithMessage(errorMessage));

            // Act
            var validationResult = validator.Validate(new Person {
                PIS = pis
            });

            // Assert
            Assert.False(validationResult.IsValid);
            Assert.NotEmpty(validationResult.Errors);
            var returnedErrorMessage = validationResult.Errors.First().ErrorMessage;

            Assert.Equal(errorMessage, returnedErrorMessage);
        }
예제 #9
0
        public void When_PIS_Is_Invalid_Then_Validator_Should_Fail_With_Default_ErrorMessage(string pis)
        {
            // Arrange
            var expectedMessage = "O PIS é ínválido!";
            var validator       = new TestExtensionsValidator(x => x.RuleFor(r => r.PIS).IsValidPIS());

            // Act
            var validationResult = validator.Validate(new Person {
                PIS = pis
            });

            // Assert
            Assert.False(validationResult.IsValid);
            Assert.NotEmpty(validationResult.Errors);
            var returnedErrorMessage = validationResult.Errors.First().ErrorMessage;

            Assert.Equal(expectedMessage, returnedErrorMessage);
        }