Exemple #1
0
 public void DeveApontarQueCnpjInValido(string cnpj)
 {
     Assert.False(CnpjHelper.Valido(cnpj));
 }
Exemple #2
0
        public void Armazenar(EmpresaDto dto)
        {
            if (!CnpjHelper.Valido(dto.Cnpj))
            {
                _notificationContext.AddNotification(TipoDeNotificacao.ErroDeServico, "Cnpj inválido");
                return;
            }

            dto.Cnpj = CnpjHelper.RemoveMascara(dto.Cnpj);

            Empresa empresa;

            if (dto.Id == 0)
            {
                empresa = EmpresaBuilder.Novo()
                          .ComNome(dto.Nome)
                          .ComCnpj(dto.Cnpj)
                          .ComDataFundacao(dto.DataFundacao)
                          .Build();
            }
            else
            {
                empresa = _empresaRepositorio.ObterPorId(dto.Id);
                if (empresa == null)
                {
                    _notificationContext.AddNotification(TipoDeNotificacao.ErroDeServico, "Empresa não encontrada");
                    return;
                }

                List <Empresa> empresas = _empresaRepositorio.ObterPorFiltro(string.Empty, dto.Cnpj, null);

                if (empresas.Count > 0 && empresas.Any(x => x.Id != empresa.Id))
                {
                    _notificationContext.AddNotification(TipoDeNotificacao.ErroDeServico, "CNPJ utilizado");
                    return;
                }

                empresa.Nome         = dto.Nome;
                empresa.Cnpj         = dto.Cnpj;
                empresa.DataFundacao = dto.DataFundacao;

                _empresaRepositorio.Put(empresa);
            }

            if (!empresa.Validar())
            {
                _notificationContext.AddNotification(TipoDeNotificacao.ErroDeServico, "Empresa inválida");
                return;
            }

            if (dto.Id == 0)
            {
                List <Empresa> empresas = _empresaRepositorio.ObterPorFiltro(string.Empty, dto.Cnpj, null);

                if (empresas.Count > 0)
                {
                    _notificationContext.AddNotification(TipoDeNotificacao.ErroDeServico, "CNPJ utilizado");
                    return;
                }

                _empresaRepositorio.Post(empresa);
            }
        }
Exemple #3
0
 public void DeveApontarQueCnpjValido(string cnpj)
 {
     Assert.True(CnpjHelper.Valido(cnpj));
 }