コード例 #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);
        }
コード例 #3
0
        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);
        }
コード例 #5
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);
            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);
        }