コード例 #1
0
        public void ShouldValidateValidCNPJ()
        {
            CNPJValidator validator = new CNPJValidator();

            validator.AssertValid("11222333000181");
            validator.AssertValid("63025530002409");
            validator.AssertValid("61519128000150");
            validator.AssertValid("68745386000102");
        }
コード例 #2
0
        public void ShouldGenerateValidUnformattedCPF()
        {
            CNPJValidator cnpjValidator = new CNPJValidator();
            string        generated     = cnpjValidator.GenerateRandomValid();

            cnpjValidator.AssertValid(generated);
        }
コード例 #3
0
        public void ShouldValidateValidFormattedCNPJ()
        {
            CNPJValidator validator = new CNPJValidator(true);
            string        value     = validString;

            validator.AssertValid(value);
        }
コード例 #4
0
        public void ShoulValidateNullCNPJ()
        {
            CNPJValidator validator = new CNPJValidator();
            string        value     = null;

            validator.AssertValid(value);
        }
コード例 #5
0
 public void ShouldValidateValidCNPJ()
 {
     cnpjValidator.AssertValid("11222333000181");
     cnpjValidator.AssertValid("63025530002409");
     cnpjValidator.AssertValid("61519128000150");
     cnpjValidator.AssertValid("68745386000102");
 }
コード例 #6
0
        public void ShouldNotValidateCNPJWithInvalidCharacter()
        {
            CNPJValidator validator = new CNPJValidator(false);

            try
            {
                string value = "1111111a111111";
                validator.AssertValid(value);
                Assert.Fail();
            }
            catch (InvalidStateException e)
            {
                Assert.IsTrue(e.GetInvalidMessages().Count == 1);
                AssertMessage(e, INVALID_DIGITS);
            }
        }
コード例 #7
0
        public void ShouldNotValidateCNPJWithMoreDigitsThanAllowed()
        {
            CNPJValidator validator = new CNPJValidator();

            try
            {
                string value = "123456789012345";
                validator.AssertValid(value);
                Assert.Fail();
            }
            catch (InvalidStateException e)
            {
                Assert.IsTrue(e.GetInvalidMessages().Count == 1);
                AssertMessage(e, INVALID_DIGITS);
            }
        }
コード例 #8
0
        public void ShouldNotValidateValidUnformattedCNPJWhenExplicity()
        {
            CNPJValidator validator = new CNPJValidator(true);

            // VALID CNPJ = 26.637.142/0001-58
            try
            {
                string value = "26637142000158";
                validator.AssertValid(value);
                Assert.Fail();
            }
            catch (InvalidStateException e)
            {
                Assert.IsTrue(e.GetInvalidMessages().Count == 1);
                AssertMessage(e, INVALID_FORMAT);
            }
        }
コード例 #9
0
        public void ShouldNotValidateCNPJCheckDigitsWithSecondCheckDigitWrong()
        {
            CNPJValidator validator = new CNPJValidator();

            // VALID CNPJ = 266371420001-58
            try
            {
                string value = "26637142000154";
                validator.AssertValid(value);
                Assert.Fail();
            }
            catch (InvalidStateException e)
            {
                Assert.IsTrue(e.GetInvalidMessages().Count == 1);
                AssertMessage(e, INVALID_CHECK_DIGITS);
            }
        }
コード例 #10
0
        public void ShouldNotValidateCNPJCheckDigitsWithFirstCheckDigitWrong()
        {
            CNPJValidator validator = new CNPJValidator();

            // VALID CNPJ = 742213250001-30
            try
            {
                string value = "74221325000160";
                validator.AssertValid(value);
                Assert.Fail();
            }
            catch (InvalidStateException e)
            {
                Assert.IsTrue(e.GetInvalidMessages().Count == 1);
                AssertMessage(e, INVALID_CHECK_DIGITS);
            }
        }