Beispiel #1
0
        public NotificationResult Atualizar(Cliente entidade)
        {
            var notificationResult = new NotificationResult();

            try
            {
                if (entidade.idCliente <= 0)
                {
                    return(notificationResult.Add(new NotificationError("Código do Cliente Inválido!")));
                }

                if (EmailUtil.ValidarEmail(entidade.Email) == false)
                {
                    notificationResult.Add(new NotificationError("Email Inválido!", NotificationErrorType.USER));
                }

                if (CPFUtil.ValidarCPF(entidade.CPF) == false)
                {
                    notificationResult.Add(new NotificationError("CPF Do Cliente Inválido", NotificationErrorType.USER));
                }

                if (string.IsNullOrEmpty(entidade.TelefoneCelular))
                {
                    notificationResult.Add(new NotificationError("Telefone Inválido", NotificationErrorType.USER));
                }

                if (string.IsNullOrEmpty(entidade.Endereco))
                {
                    notificationResult.Add(new NotificationError("Endereço Informado Inválido", NotificationErrorType.USER));
                }

                if (string.IsNullOrEmpty(entidade.Nome))
                {
                    notificationResult.Add(new NotificationError("Nome Do Cliente Inválido", NotificationErrorType.USER));
                }

                if (string.IsNullOrEmpty(entidade.RG))
                {
                    notificationResult.Add(new NotificationError("RG Inválido", NotificationErrorType.USER));
                }

                if (string.IsNullOrEmpty(entidade.EnderecoImagem))
                {
                    notificationResult.Add(new NotificationError("Telefone Inválido", NotificationErrorType.USER));
                }

                if (notificationResult.IsValid)
                {
                    _clienteRepositorio.Atualizar(entidade);
                    notificationResult.Add("Cliente Atualizado com sucesso.");
                }

                return(notificationResult);
            }
            catch (Exception ex)
            {
                return(notificationResult.Add(new NotificationError(ex.Message)));
            }
        }
Beispiel #2
0
        public void WhenInvalidCPFWithoutMaskThenShouldReturnFalse(string cpf)
        {
            //Act
            bool result = CPFUtil.ValidateCPF(cpf);

            //Assert
            Assert.IsFalse(result);
        }
Beispiel #3
0
        public void WhenValidCPFWithMaskThenShouldReturnTrue(string cpf)
        {
            //Act
            bool result = CPFUtil.ValidateCPF(cpf);

            //Assert
            Assert.IsTrue(result);
        }
Beispiel #4
0
        public void WhenOnlyMaskCPFThenShouldReturnFalse()
        {
            //Act
            bool result = CPFUtil.ValidateCPF("..-");

            //Assert
            Assert.IsFalse(result);
        }
Beispiel #5
0
        public void WhenEmptyCPFThenShouldReturnFalse()
        {
            //Act
            bool result = CPFUtil.ValidateCPF(string.Empty);

            //Assert
            Assert.IsFalse(result);
        }
Beispiel #6
0
 public void WhenNullCPFThenShouldThrowException()
 {
     //Act
     Assert.ThrowsException <ArgumentNullException>(() => CPFUtil.ValidateCPF(null));
 }