public void TestValidCpf() { _listaCpf = new List <string>() { "81926682076", "567.756.290-44" }; //CPFs Válidos bool control = false; Int64? cpf = null; string currentCpf = ""; try { foreach (var item in _listaCpf) { currentCpf = item; control = new CpfValidator(Guid.NewGuid().ToString(), base.Config).ValidateCPF(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); }
public void TestInvalidCpf() { _listaCpf = new List <string>() { "312.543.654.90", "90876856423" }; //CPFs Inválidos bool control = false; Int64? cpf = null; string currentCpf = ""; try { foreach (var item in _listaCpf) { currentCpf = item; control = new CpfValidator(Guid.NewGuid().ToString(), base.Config).ValidateCPF(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); }
public List <string> Validate(ClientDTO obj) { List <string> errors = new List <string>(); if (string.IsNullOrWhiteSpace(obj.Name)) { errors.Add("O cliente deve ser informado"); } else if (obj.Name.Length < 2 && obj.Name.Length > 20) { errors.Add("O cliente deve conter entre 2 e 50 caracteres"); } if (!CpfValidator.IsCpf(obj.CPF)) { errors.Add("CPF invalido"); } if (string.IsNullOrEmpty(obj.Password)) { errors.Add("A senha deve ser informada"); } if (string.IsNullOrEmpty(obj.Phone)) { errors.Add("O numero de telefone deve ser informado"); } if (string.IsNullOrEmpty(obj.RG)) { errors.Add("O RG do cliente deve ser informado"); } if (string.IsNullOrEmpty(obj.Email)) { errors.Add("O Email deve ser informado"); } return(errors); }
public async Task <Response <Proposta> > ValidateProposta(int id) { var response = new Response <Proposta>(); var proposta = await this.GetProposta(id); response.Item = proposta; if (proposta == null) { response.ResponseStatus.AddError("Proposta", "A proposta não existe no banco de dados"); } if (CpfValidator.Validate(proposta.Cliente.CPF)) { response.ResponseStatus.AddError("Cliente", "O CPF do Cliente nao é válido"); } if (CpfValidator.CheckIrregular(proposta.Cliente.CPF)) { response.ResponseStatus.AddError("CpfIrregular", "O CPF do Cliente está irregular"); proposta.Status = PropostaStatus.PendenciaAutomatica; } return(response); }
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); } }
public override ValidationResult Validate() { var result = new CpfValidator().Validate(this); _isValid = result.IsValid; return(result); }
public async Task <IResultResponse> Delete(string document) { IResultResponse response = new ResultResponse(); CpfValidator validator = new CpfValidator(); var result = await validator.ValidateAsync(new Cpf(document)); if (result.IsValid) { User user = await _unitOfWork.UserRepository.GetByDocument(document); if (user != null) { await _unitOfWork.UserRepository.Delete(user); _logger.LogInformation(LoggingEvent.Delete, "Usuário deletado com sucesso"); } else { response.AddMessage($"Usuário com o Cpf {document} não encontrado"); _logger.LogInformation(LoggingEvent.Delete, $"Usuário com o Cpf {document} não encontrado"); } } else { response.AddMessage(result.Errors); _logger.LogInformation(LoggingEvent.Delete, $"Encontrado algum erro de validação"); } return(response); }
public void ShouldTrimCpf() { string cpf = " 706.534.060-02 "; string expectedFormatedCpf = "706.534.060-02"; CpfValidator cpfValidator = new CpfValidator(); Assert.Equal(cpfValidator.Format(cpf, CodeFormat.Trim), expectedFormatedCpf); }
public void ShouldFormatCpfWithoutDigit() { string cpf = "706.534.060-02"; string expectedFormatedCpf = "706.534.060"; CpfValidator cpfValidator = new CpfValidator(); Assert.Equal(cpfValidator.Format(cpf, CodeFormat.WithoutDigit), expectedFormatedCpf); }
public void ShouldFormatCpfWithoutSeparators() { string cpf = "706.534.060-02"; string expectedFormatedCpf = "70653406002"; CpfValidator cpfValidator = new CpfValidator(); Assert.Equal(cpfValidator.Format(cpf, CodeFormat.WithoutNumberSeparator | CodeFormat.WithoutDigitSeparator), expectedFormatedCpf); }
public override bool IsValid(object value) { var cpf = value as string; if (string.IsNullOrEmpty(cpf)) { return(true); } return(CpfValidator.Validate(cpf)); }
public void Valid_Cpf_In_AssertValid(string cpf, IValidator <string> validator) { $"Dado um CPF válido: {cpf}" .Do(() => { }); "E o validator de CPF," .Do(() => validator = new CpfValidator()); "Quando valido se o CPF é válido, não pode lançar exceção." .Do(() => validator.Invoking(v => v.AssertValid(cpf)) .Should() .NotThrow <ValueObjectException>()); }
public void Invalid_Cpf_In_IsValid(string cpf, IValidator <string> validator, bool isValid) { $"Dado o CPF inválido: {cpf}" .Do(() => { }); "E o validator de CPF," .Do(() => validator = new CpfValidator()); "Quando testo se o CPF é válido," .Do(() => isValid = validator.IsValid(cpf)); "O resultado deve ser falso." .Do(() => isValid.Should().BeFalse()); }
public void Valid_Cpf_In_IsValid(string cpf, IValidator <string> validator, bool isValid) { $"Dado um CPF válido: {cpf}" .Do(() => { }); "E o validator de CPF," .Do(() => validator = new CpfValidator()); "Quando testo se o CPF é válido," .Do(() => isValid = validator.IsValid(cpf)); "O resultado deve ser verdadeiro." .Do(() => isValid.Should().BeTrue()); }
public void Invalid_Cpf_In_AssertValid(string cpf, string message, IValidator <string> validator) { $"Dado um CPF inválido: {cpf}" .Do(() => { }); "E o validator de CPF," .Do(() => validator = new CpfValidator()); $"Quando valido se o CPF é válido, deve lançar exceção com a seguinte mensagem: {message}." .Do(() => validator.Invoking(val => val.AssertValid(cpf)) .Should() .Throw <ValueObjectException>() .WithMessage(message)); }
public void Error_Messages_In_GetInvalidMessages_With_Invalid_Cpf(string cpf, string[] expectedMessage, IValidator <string> validator, List <string> messages) { $"Dado um CPF inválido: {cpf}" .Do(() => { }); "E o validator de CPF" .Do(() => validator = new CpfValidator()); "Buscar mensagens de erro desse CPF" .Do(() => messages = validator.GetInvalidMessage(cpf)); $"Que devem ser: {expectedMessage}." .Do(() => messages.Should().Equal(expectedMessage)); }
public void Error_Messages_In_GetInvalidMessages_With_Valid_Cpf(string cpf, IValidator <string> validator, List <string> messages) { $"Dado um CPF válido: {cpf}" .Do(() => { }); "E o validator de CPF" .Do(() => validator = new CpfValidator()); "Buscar mensagens de erro desse CPF" .Do(() => messages = validator.GetInvalidMessage(cpf)); "Que deve ser vazia." .Do(() => messages.Should().BeEmpty()); }
public async Task <IActionResult> Create([Bind("Prontuario,Nome,SobreNome,DtNasc,Genero,Cpf,Rg,UfRg,Email,Celular,Id_Convenio")] Paciente paciente) { if (ModelState.IsValid) { if (!CpfValidator.IsValid(paciente.Cpf)) { throw new InvalidOperationException("Cpf inválido!!!"); } _context.Add(paciente); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(paciente)); }
public HttpResponseMessage PostCpf(string cpf) { var cpfValido = CpfValidator.Validar(cpf); string mensagem = ""; if (cpfValido) { mensagem = "Cpf é valido"; } else { mensagem = "Cpf é invalido"; } return(Request.CreateResponse(HttpStatusCode.OK, mensagem)); }
public async Task <ActionResult <Bill> > Create([FromForm] DateTime dataVencimento, [FromForm] string cpf, [FromForm] double valorCobranca) { CpfValidator cpfValidator = new CpfValidator(); if (!cpfValidator.IsValid(cpf)) { return(BadRequest(new { errors = new { cpf = new[] { "Valor inválido" } } })); } cpf = cpfValidator .Format(cpf, CodeFormat.Trim | CodeFormat.WithoutDigitSeparator | CodeFormat.WithoutNumberSeparator); Bill bill = new Bill() { DueDate = dataVencimento.Date, PersonId = cpf, Value = valorCobranca }; bill = await _billService.CreateAsync(bill); return(Ok(bill)); }
public async void Login() { CpfValidator cpfValidator = new CpfValidator(); if (Person.cpf != null) { if (cpfValidator.ValidateCpf(Person.cpf)) { People = await PersonService.Get("getbyCpf?cpf=" + Person.cpf); if (People.Count == 0) { var navigateParam = new NavigationParameters { { "Person", Person } }; await _navigationService.NavigateAsync("SignUpPage", navigateParam); } else { var navigateParam = new NavigationParameters() { { "Person", People[0] }, }; await _navigationService.NavigateAsync("HomePage", navigateParam); } } else { await _pageDialogService.DisplayAlertAsync("Aviso", "Digite um CPF válido", "Ok"); } } else { await _pageDialogService.DisplayAlertAsync("Aviso", "Preencha o seu CPF", "Ok"); } }
public override bool IsValid(object value) { var cpf = (string)value; return(CpfValidator.IsValid(cpf)); }
public override bool IsValid(object value) { return(CpfValidator.Validate(value as string)); }
protected static bool IsValidCpf(string value) { return(CpfValidator.IsValid(value)); }
public void ShouldVerifyNullCpfAsInvalid() { CpfValidator cpfValidator = new CpfValidator(); Assert.False(cpfValidator.IsValid(null)); }
public void ShouldVerifyEmptyCpfAsInvalid() { CpfValidator cpfValidator = new CpfValidator(); Assert.False(cpfValidator.IsValid(String.Empty)); }
public void ShouldVerifyIfInvalidCpf() { CpfValidator cpfValidator = new CpfValidator(); Assert.False(cpfValidator.IsValid("907.518.060-8")); }
public void ShouldVerifyIfValidCpf() { CpfValidator cpfValidator = new CpfValidator(); Assert.True(cpfValidator.IsValid("907.518.060-80")); }
public CpfValidatorTest(ServerTestFixture <Startup> fixture) : base(fixture) { cpfValidator = new CpfValidator(); }
public CustomersController(ICustomerService customerService) { _customerService = customerService; _cpfValidator = new CpfValidator(); }