[DataRow("42.630.193/0001-05")] //DocumentoCNPJ Mudei um Numero no Digito public void RetornaFalsoQuandoDocumentoIsInvalid(string cpf) { //DocumentoCPF is Null or Empty var cliente = new Cliente("Nome Cliente", cpf, "Endereço Cliente Maior que 20"); var validator = new ClienteValidator(); var validRes = validator.Validate(cliente); Assert.IsFalse(validRes.IsValid); }
public void RetornaFalsoQuandoEnderecoIsInvalid() { //Endereco menor que 20 caracteres var cliente = new Cliente("Nome Cliente", "179.506.820-51", "Endereço Cliente"); var validator = new ClienteValidator(); var validRes = validator.Validate(cliente); Assert.IsFalse(validRes.IsValid); }
public void RetornaFalsoQuandoClienteIsInvalid() { //Nome = NULL or Empty var cliente = new Cliente("", "179.506.820-51", "Endereço Cliente Maior que 20"); var validator = new ClienteValidator(); var validRes = validator.Validate(cliente); Assert.IsFalse(validRes.IsValid); }
public void CriacaoInstancia_DadosValidos_RetornaVerdadeiro() { var _cliente = new Cliente("João", "363.348.820-07", "*****@*****.**"); _cliente.AdicionarEnderecos( new Endereco("Av. São Jorge", 50, "Cidade Salvador", "Jacareí", "SP", "Brasil", "12312000")); _cliente.AdicionarTelefones( new Telefone(12985654585)); ValidationResult _clienteValidation = _clienteValidator.Validate(_cliente); Assert.True(_clienteValidation.IsValid, _clienteValidation.GetValidationMessage()); }
private int cadastraCliente() { this.cliente._cpfCliente = txtCPF.Text; this.cliente._nomeCliente = txtNome.Text; this.cliente._fone1Cliente = txtFone1.Text; this.cliente._fone2Cliente = txtFone2.Text; this.cliente._emailCliente = txtEmail.Text; this.cliente._cepCliente = txtCEP.Text; this.cliente._enderecoCliente = txtEndereco.Text; this.cliente._bairroCliente = txtBairro.Text; this.cliente._cidadeCliente = txtCidade.Text; this.cliente._estadoCliente = txtEstado.Text; this.cliente._observacaoCliente = txtObservacao.Text; ClienteValidator cliente_validator = new ClienteValidator(); ValidationResult resultado = cliente_validator.Validate(this.cliente); if (resultado.IsValid == false) { foreach (ValidationFailure failure in resultado.Errors) { MessageBox.Show(failure.ErrorMessage, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(1); } else { if (DateTime.TryParse(mskDataCadastro.Text, out DateTime data_cadastro)) { this.cliente._dataCadastro = Convert.ToDateTime(mskDataCadastro.Text); if (ClienteDAO.obterClientePorCPF(this.cliente._cpfCliente) == -1) { ClienteDAO.cadastraCliente(this.cliente); MessageBox.Show("Cliente cadastrado", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information); this.limparCampos(); return(0); } else { MessageBox.Show("CPF já cadastrado", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(1); } } else { MessageBox.Show("Data inválida", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(1); } } }
public JsonResult Incluir(ClienteModel model) { BoCliente bo = new BoCliente(); if (!this.ModelState.IsValid) { List <string> erros = (from item in ModelState.Values from error in item.Errors select error.ErrorMessage).ToList(); Response.StatusCode = 400; return(Json(string.Join(Environment.NewLine, erros))); } var objToAdd = new Cliente() { CEP = model.CEP, Cidade = model.Cidade, Email = model.Email, Estado = model.Estado, Logradouro = model.Logradouro, Nacionalidade = model.Nacionalidade, Nome = model.Nome, Sobrenome = model.Sobrenome, Telefone = model.Telefone, Cpf = model.Cpf }; var validador = clienteValidator.Validate(objToAdd); if (!validador.IsValid) { return(Json(string.Join(Environment.NewLine, validador.Errors))); } if (bo.VerificarExistencia(model.Cpf)) { Response.StatusCode = 400; return(Json("CPF já Existente!")); } model.Id = bo.Incluir(objToAdd); return(Json("Cadastro efetuado com sucesso")); }
public ActionResult Update(Cliente cliente) { ClienteValidator validator = new ClienteValidator(); var result = validator.Validate(cliente); if (!result.IsValid) { var errors = new Dictionary <string, string>(); foreach (var error in result.Errors) { string message = error.ErrorMessage; string property = error.PropertyName; errors.Add(property, message); } return(BadRequest(Json(errors))); } return(Json(new { id = repository.Update(cliente) })); }
public async ValueTask Incluir(dynamic json) { try { string jsonString = Convert.ToString(json); Console.WriteLine(jsonString); dynamic data = JObject.Parse(jsonString); //------------ //Verificando Campo Cliente Cliente cliente = new Cliente(Convert.ToString(data.cliente.nome), Convert.ToString(data.cliente.documentoCpf), Convert.ToString(data.cliente.endereco)); var validatorCliente = new ClienteValidator(); var validResCliente = validatorCliente.Validate(cliente); //cd . Console.WriteLine("CPF Cliente OK SQLite? => " + (new CpfValidador(cliente.DocumentoCpf)).EstaValido()); Console.WriteLine("Cliente OK SQLite? => " + validResCliente.IsValid); Console.WriteLine(cliente.Nome); if (validResCliente.IsValid) { var parameters = new { clienteNome = cliente.Nome, clienteDocumentoCPF = cliente.DocumentoCpf, clienteEndereco = cliente.Endereco }; string query = "INSERT INTO cliente ( Nome, DocumentoCPF, Endereco ) VALUES ( @clienteNome, @clienteDocumentoCPF, @clienteEndereco ) ON CONFLICT(DocumentoCPF) DO UPDATE SET Nome=excluded.Nome,Endereco=excluded.Endereco"; Console.WriteLine(@query, parameters); using (var cnn = SimpleDbConnection()) { await cnn.OpenAsync(); await cnn.ExecuteAsync(query, parameters); await cnn.CloseAsync(); Console.WriteLine("Cliente Incluido SQLite Corretamente!"); } } else { Console.WriteLine("Cliente Com Dados Incorretos!"); } } catch (Exception e) { Console.WriteLine($"Error no JSON Input {e}"); } }
public void Cliente_DeveSerValido() { //Arrange var clienteValidator = new ClienteValidator(); var cliente = new Faker <Cliente>("pt_BR") .RuleFor(m => m.Id, f => System.Guid.NewGuid()) .RuleFor(m => m.Nome, f => f.Person.FirstName) .RuleFor(m => m.Sobrenome, f => f.Person.LastName) .RuleFor(m => m.Cpf, f => f.Person.Cpf(false)) .RuleFor(m => m.Email, f => f.Person.Email.ToLower()) .RuleFor(m => m.DataNascimento, f => f.Date.Past(90, System.DateTime.Now.AddYears(-18))) .RuleFor(m => m.Senha, f => f.Random.AlphaNumeric(6)) .RuleFor(m => m.Ativo, f => f.Random.Bool()) .RuleFor(m => m.DataCriacao, f => f.Date.Recent()) .Generate(1)[0]; //Act var result = clienteValidator.Validate(cliente); //Assert result.Errors.Count.Should().Be(0); }
public async Task <Cliente> Cadastrar(Cliente cliente) { ValidationResult _clienteValidation = _clienteValidator.Validate(cliente); if (!_clienteValidation.IsValid) { throw new ApiException(StatusCodes.Status400BadRequest, _clienteValidation.GetValidationMessageAsList()); } if (await _clienteRepository.CPFJaEmUsoAsync(cliente.CPF.SemPontuacao)) { throw new ApiException( StatusCodes.Status409Conflict, "Já existe um cadastro com o CPF informado"); } if (await _clienteRepository.EmailJaEmUsoAsync(cliente.Email.Value)) { throw new ApiException( StatusCodes.Status409Conflict, "Já existe um cadastro com o e-mail informado"); } if (CPFConstaNaBlacklist(cliente.CPF.SemPontuacao)) { throw new ApiException( StatusCodes.Status403Forbidden, "CPF não permitido"); } cliente = _clienteRepository.Create(cliente); await _uow.CommitAsync(); return(cliente); }
public ValidationResult Validar() { var validator = new ClienteValidator(); return(validator.Validate(this)); }
private void ValidateCliente(ref Models.Cliente cliente, ClienteValidator validator) { cliente.ValidationResult = validator.Validate(cliente); }
private void BtnAlterar_Click(object sender, EventArgs e) { ModeloCliente cliente = new ModeloCliente(); cliente._idCliente = Convert.ToInt32(txtID.Text); cliente._cpfCliente = txtCPF.Text; cliente._nomeCliente = txtNome.Text; cliente._fone1Cliente = txtFone1.Text; cliente._fone2Cliente = txtFone2.Text; cliente._emailCliente = txtEmail.Text; cliente._cepCliente = txtCEP.Text; cliente._enderecoCliente = txtEndereco.Text; cliente._bairroCliente = txtBairro.Text; cliente._cidadeCliente = txtCidade.Text; cliente._estadoCliente = txtEstado.Text; cliente._observacaoCliente = txtObservacao.Text; ClienteValidator cliente_validator = new ClienteValidator(); ValidationResult resultado = cliente_validator.Validate(cliente); if (resultado.IsValid == false) { foreach (ValidationFailure failure in resultado.Errors) { MessageBox.Show(failure.ErrorMessage, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { if (DateTime.TryParse(mskDataCadastro.Text, out DateTime data_cadastro)) { cliente._dataCadastro = Convert.ToDateTime(mskDataCadastro.Text); int clienteBD = ClienteDAO.obterClientePorCPF(cliente._cpfCliente); if (clienteBD == -1) { ClienteDAO.alterarCliente(cliente); Clientes clientes = new Clientes(); clientes.Show(); this.Hide(); } else { if (clienteBD != cliente._idCliente) { MessageBox.Show("CPF já cadastrado", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { ClienteDAO.alterarCliente(cliente); Clientes clientes = new Clientes(); clientes.Show(); this.Hide(); } } } else { MessageBox.Show("Data inválida", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
public FluentValidation.Results.ValidationResult validate() { _validator = new ClienteValidator(); return(_validator.Validate(this)); }