public async Task HandlerArquivar_DeveInvalidarCommandQuandoIdForVazio() { var commandVazio = new ArquivarLogCommand(); var commandHandler = new LogCommandHandler(_mediatorMock.Object, _logRepository); await commandHandler.Handle(commandVazio, CancellationToken.None); commandVazio.ValidationResult.IsValid.Should().Be(false); }
public async Task HandlerArquivar_DeveLancarNotificacaoQuandoLogNaoExistir() { var command = new ArquivarLogCommand(Guid.NewGuid()); var commandHandler = new LogCommandHandler(_mediatorMock.Object, _logRepository); await commandHandler.Handle(command, CancellationToken.None); _mediatorMock.Verify(mediator => mediator.Publish(It.IsAny <DomainNotification>(), CancellationToken.None)); }
public async Task HandlerArquivar_DeveAtualizarCampoArquivadoEm() { var log = LogFactory.GerarLog(); await _context.Logs.AddAsync(log); await _context.SaveChangesAsync(); var command = new ArquivarLogCommand(log.Id); var commandHandler = new LogCommandHandler(_mediatorMock.Object, _logRepository); await commandHandler.Handle(command, CancellationToken.None); var logSalvo = await _context.Logs.FirstOrDefaultAsync(); logSalvo.ArquivadoEm.Should().BeCloseTo(DateTime.UtcNow, 1000); }
public async Task <Unit> Handle(ArquivarLogCommand request, CancellationToken cancellationToken) { if (!await ValidarCommando(request)) { return(Unit.Value); } var logs = await _logRepository.ObterPorIds(request.Ids); if (!logs.Any()) { await _mediator.Publish(new DomainNotification("log", "Log não encontrado")); return(Unit.Value); } var logsNaoArquivados = logs.Where(log => log.ArquivadoEm == null).ToList(); logsNaoArquivados.ForEach(log => log.Arquivar()); await _logRepository.Atualizar(logsNaoArquivados.ToArray()); return(Unit.Value); }
public async Task Arquivar(params Guid[] ids) { var command = new ArquivarLogCommand(ids); await _mediator.Send(command); }