예제 #1
0
        public Task <PagedList <Log> > Handle(ObterTodosOsLogsQuery request, CancellationToken cancellationToken)
        {
            Expression <Func <Log, bool> > filtro = log =>
                                                    (log.AmbienteId == request.AmbienteId || request.AmbienteId == Guid.Empty) &&
                                                    (log.Origem.Contains(request.Origem) || string.IsNullOrWhiteSpace(request.Origem)) &&
                                                    (log.Descricao.Contains(request.Descricao) || string.IsNullOrWhiteSpace(request.Descricao)) &&
                                                    (request.Arquivado.HasValue
                    ? request.Arquivado.Value ? log.ArquivadoEm != null : log.ArquivadoEm == null
                    : request.Arquivado == null);

            return(Task.FromResult(_logRepository.ObterTodos(request.PageNumber, request.PageSize, filtro)));
        }
예제 #2
0
        public async Task <PagedList <Log> > ObterTodos(LogQueryViewModel logQueryViewModel)
        {
            var query = new ObterTodosOsLogsQuery(
                logQueryViewModel.PageNumber,
                logQueryViewModel.PageSize,
                logQueryViewModel.AmbienteId,
                logQueryViewModel.Origem,
                logQueryViewModel.Descricao,
                logQueryViewModel.Arquivado
                );

            return(await _mediator.Send(query));
        }
        public async Task HandlerObterTodos_DeveRetornarTodosOsLogsSalvosNoBanco()
        {
            var usuario  = UsuarioFactory.GerarUsuario();
            var ambiente = AmbienteFactory.GerarAmbiente();
            var nivel    = NivelFactory.GerarNivel();
            var log1     = new Log(usuario.Id, ambiente.Id, nivel.Id, "título", "descrição", "0.0.0.0");
            var log2     = new Log(usuario.Id, ambiente.Id, nivel.Id, "título", "descrição", "0.0.0.0");
            await _context.AddRangeAsync(usuario, ambiente, nivel, log1, log2);

            await _context.SaveChangesAsync();

            var query        = new ObterTodosOsLogsQuery(1, 20, Guid.Empty, null, null, null);
            var queryHandler = new LogQueryHandler(_logRepository);

            var logs = await queryHandler.Handle(query, CancellationToken.None);

            logs.Should().HaveCount(2);
        }