Esempio n. 1
0
        public List <AlteracaoStatusNotificacaoDto> MarcarComoLida(IList <long> notificacoesId)
        {
            if (notificacoesId == null)
            {
                throw new NegocioException("A lista de notificações deve ser informada.");
            }
            var resultado = new List <AlteracaoStatusNotificacaoDto>();

            foreach (var notificacaoId in notificacoesId)
            {
                try
                {
                    Notificacao notificacao = ObterPorIdENotificarCasoNaoExista(notificacaoId);

                    notificacao.MarcarComoLida();
                    repositorioNotificacao.Salvar(notificacao);
                    resultado.Add(new AlteracaoStatusNotificacaoDto($"Notificação com Código: '{notificacao.Codigo}' alterada com sucesso.", true));
                }
                catch (NegocioException nex)
                {
                    resultado.Add(new AlteracaoStatusNotificacaoDto(nex.Message, false));
                }
                catch (Exception)
                {
                    resultado.Add(new AlteracaoStatusNotificacaoDto($"Não foi possível alterar o status da notificação com id: '{notificacaoId}'", false));
                }
            }
            return(resultado);
        }
Esempio n. 2
0
        public void DeveDispararExcecaoAoMarcarComoLidaNotificacaoDiferenteDeAlerta()
        {
            var notificacao = new Notificacao()
            {
                Categoria = NotificacaoCategoria.Aviso
            };

            Assert.Throws <NegocioException>(() => notificacao.MarcarComoLida());
            Assert.True(notificacao.Status == NotificacaoStatus.Pendente);
        }
Esempio n. 3
0
        public void DeveMarcarComoLida()
        {
            var notificacao = new Notificacao()
            {
                Categoria = NotificacaoCategoria.Alerta
            };

            notificacao.MarcarComoLida();
            Assert.True(notificacao.Status == NotificacaoStatus.Lida);
        }