public ICommandResult Handle(UpdateServerCommand command) { command.Validate(); if (command.IsInvalid) { return(new DefaultCommandResult(CommandResultStatus.InvalidCommand, command.Notifications)); } try { var server = _serverRepository.GetById(command.Id); if (server == null) { return(new DefaultCommandResult(CommandResultStatus.InvalidData, "Nenhum servidor foi localizado")); } server.Name = command.Name; server.Ip = command.Ip; server.Port = command.Port; _serverRepository.Update(server); return(new DefaultCommandResult(server.Id)); } catch (Exception e) { Console.WriteLine($"Fail to execute UpdateServerHandler. Fail stack ===> {e.ToString()}"); return(new DefaultCommandResult(CommandResultStatus.Exception)); } }
public void Should_Be_Valid_Command() { _validCommand.Validate(); Assert.True(!_validCommand.IsInvalid); }