Exemple #1
0
 public CheckIfCanalIsValidRuleTests()
 {
     _mocker  = new AutoMoqer();
     _model   = new UpdateContatoModel();
     _rule    = new CheckIfCanalIsValidRule();
     _command = _mocker.Create <UpdateContatoCommand>();
 }
Exemple #2
0
        public bool IsValid(UpdateContatoModel model, ICommand command)
        {
            if (string.IsNullOrEmpty(model.canal))
            {
                return(true);
            }

            if (!model.canal.Equals("Celular") && !model.canal.Equals("E-mail") && !model.canal.Equals("Telefone"))
            {
                command.AddNotification(new Notification {
                    key = "canal", value = string.Format("Apenas Celular, E-mail e Telefone são considerados válidos como canal.", model.canal)
                });
                return(false);
            }

            return(true);
        }
Exemple #3
0
        public bool IsValid(UpdateContatoModel model, ICommand command)
        {
            if (string.IsNullOrEmpty(model.id))
            {
                return(true);
            }

            var resultFrom = _repository.Get(model.id).Result;

            if (resultFrom == null)
            {
                command.AddNotification(new Notification {
                    key = "id", value = "O Contato informado não existe"
                });
                return(false);
            }

            return(true);
        }
Exemple #4
0
        public async Task <IActionResult> Put(string id, [FromBody] UpdateContatoModel value)
        {
            value.id = id;
            await _updateCommand.Execute(value);

            if (_createCommand.HasNotifications())
            {
                var notifications = _createCommand.GetNotifications();
                if (notifications.Any(x => x.key.Equals("id")))
                {
                    return(NotFound(notifications));
                }
                else
                {
                    return(BadRequest(notifications));
                }
            }

            return(NoContent());
        }
Exemple #5
0
        public bool IsValid(UpdateContatoModel model, ICommand command)
        {
            if (string.IsNullOrEmpty(model.canal) || string.IsNullOrEmpty(model.valor))
            {
                return(true);
            }

            if (model.canal.Equals("Telefone") || model.valor.Equals("Celular"))
            {
                var   regex = @"^(([1-9]{1}[0-9]{1}[9]{1}[0-9]{4}[0-9]{4})|([1-9]{1}[0-9]{1}[1-8]{1}[0-9]{3}[0-9]{4}))$";
                Match match = Regex.Match(model.valor, regex, RegexOptions.IgnoreCase);
                if (!match.Success)
                {
                    command.AddNotification(new Notification {
                        key = "valor", value = string.Format("O valor não corresponde a um {0}", model.canal)
                    });
                    return(false);
                }
            }

            return(true);
        }
Exemple #6
0
        public bool IsValid(UpdateContatoModel model, ICommand command)
        {
            if (string.IsNullOrEmpty(model.canal) || string.IsNullOrEmpty(model.valor))
            {
                return(true);
            }

            if (model.canal.Equals("E-mail"))
            {
                var   regex = @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$";
                Match match = Regex.Match(model.valor, regex, RegexOptions.IgnoreCase);
                if (!match.Success)
                {
                    command.AddNotification(new Notification {
                        key = "valor", value = "O valor informado não corresponde a um E-mail"
                    });
                    return(false);
                }
            }

            return(true);
        }
Exemple #7
0
 public CheckIfValorIsAnTelefoneOrCelularRuleTests()
 {
     _rule   = new CheckIfValorIsAnTelefoneOrCelularRule();
     _model  = new UpdateContatoModel();
     _mocker = new AutoMoqer();
 }
Exemple #8
0
 public CheckIfValorIsAnEmailRuleTests()
 {
     _rule   = new CheckIfValorIsAnEmailRule();
     _model  = new UpdateContatoModel();
     _mocker = new AutoMoqer();
 }
Exemple #9
0
 public CheckIfContatoExistRuleTests()
 {
     _mocker  = new AutoMoqer();
     _model   = new UpdateContatoModel();
     _command = _mocker.Create <UpdateContatoCommand>();
 }