public async Task <UpdateServerCommandResponse> Handle(UpdateServerCommand request, CancellationToken cancellationToken) { var validationResult = await _validator.ValidateAsync(request); if (!validationResult.IsValid) { var errors = validationResult.Errors .Select(x => x.ErrorMessage); return(new UpdateServerCommandResponse(null, errors)); } Server currentServer = await _serverRepository.GetAsync(request.Id); if (currentServer is null) { var errors = new List <string> { $"Servidor com identificador {request.Id} não encontrado." }; return(new UpdateServerCommandResponse(null, errors)); } _logger.LogInformation("Atualizando servidor com id {0}", currentServer.Id); currentServer.ChangeInfo(request.Name, request.IP, request.Port); _serverRepository.Update(currentServer); await _serverRepository.SaveChangesAsync(); _logger.LogInformation("Servidor com id {0} atualizado.", currentServer.Id); return(new UpdateServerCommandResponse(currentServer, null)); }
public async Task Validar_comando_correto() { var command = new UpdateServerCommand(Guid.NewGuid(), "teste", "127.0.0.1", 80); var result = await _validator.ValidateAsync(command); result.IsValid.Should().BeTrue(); }