Ejemplo n.º 1
0
        public void TestInvalidCnpj()
        {
            List <string> _listaCnpj = new List <string>()
            {
                "31232123212456", "31.243.245/7777-88"
            };                                                                                      //CPFs Inválidos

            bool   control    = false;
            Int64? cpf        = null;
            string currentCpf = "";

            try
            {
                foreach (var item in _listaCnpj)
                {
                    currentCpf = item;
                    control    = new CnpjValidator(Guid.NewGuid().ToString(), base.Config).ValidateCnpj(item, out cpf);
                    if (!control && (cpf == null || !cpf.HasValue))
                    {
                        cpf = null;
                        break;
                    }
                    cpf = null;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("Current CPF: {0}", currentCpf), ex);
            }

            Assert.IsTrue(!control && !cpf.HasValue);
        }
        private bool IsValidDocumentNumber(string documentNumber)
        {
            const int cnpjSize = 14;
            const int cpfSize  = 11;

            if (documentNumber.All(char.IsDigit))
            {
                IIdentificationDocument identificationDocument = null;

                if (documentNumber.Length == cpfSize)
                {
                    identificationDocument = new CpfValidator();
                }
                else if (documentNumber.Length == cnpjSize)
                {
                    identificationDocument = new CnpjValidator();
                }
                else
                {
                    identificationDocument = new NullDocumentValidator();
                }

                return(identificationDocument.IsValid(documentNumber));
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        public void TestValidCnpj()
        {
            List <string> _listaCnpj = new List <string>()
            {
                "41691825000187", "12.204.603/0001-94"
            };                                                                                      //CPFs Válidos

            bool   control    = false;
            Int64? cpf        = null;
            string currentCpf = "";

            try
            {
                foreach (var item in _listaCnpj)
                {
                    currentCpf = item;
                    control    = new CnpjValidator(Guid.NewGuid().ToString(), base.Config).ValidateCnpj(item, out cpf);
                    if (!control && (cpf == null || !cpf.HasValue))
                    {
                        cpf = null;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("Current CPF: {0}", currentCpf), ex);
            }

            Assert.IsTrue(control && cpf.HasValue);
        }
Ejemplo n.º 4
0
        public HttpResponseMessage PostCnpj(string cnpj)
        {
            var    cnpjValido = CnpjValidator.Validar(cnpj);
            string mensagem   = "";

            if (cnpjValido)
            {
                mensagem = "Cnpj é valido";
            }
            else
            {
                mensagem = "Cnpj é invalido";
            }

            return(Request.CreateResponse(HttpStatusCode.OK, mensagem));
        }