public GenericResult Exec(NaturezaUpdateCommand command) { NaturezaModel model = _repository.GetById(command.Id); if (model == null) { command.AddNotification("Id", "Recurso Inexistente"); } command.Validate(); if (command.Invalid) { return(new GenericResult(400, "Recurso Inválido", command.Notifications)); } model.Atualizar(command.Nome, command.Ponto, command.Valor, command.PercentualDeDesconto); try { _repository.Update(model); return(new GenericResult(200, "Recurso Atualizado", model)); } catch (System.Exception ex) { return(new GenericResult(503, ex.GetBaseException().Message, null)); } }
public void UpdateCommand_valido() { var command = new NaturezaUpdateCommand(1, "Leve", 1, 1500, 20); command.Validate(); var validacao = command.Invalid; Assert.False(validacao); }
public IActionResult Update( [FromBody] NaturezaUpdateCommand command, [FromServices] NaturezaService service, [FromServices] IMemoryCache cache ) { GenericResult result = service.Exec(command); if (result.Status == 200) { cache.Remove(command.Id); } return(StatusCode(result.Status, result)); }
public void UpdateCommand_Invalido() { var command = new NaturezaUpdateCommand(0, "Leve", 1, 10, 10); command.Validate(); var validacaoNome = command.Invalid; command = new NaturezaUpdateCommand(1, "Leve", 8, 10, 10); command.Validate(); var validacaoPonto = command.Invalid; command = new NaturezaUpdateCommand(1, "Leve", 7, 0, 10); command.Validate(); var validacaoValor = command.Invalid; command = new NaturezaUpdateCommand(1, "Leve", 7, 10, 35); command.Validate(); var validacaoPercentual = command.Invalid; Assert.True(validacaoNome); Assert.True(validacaoPonto); Assert.True(validacaoValor); Assert.True(validacaoPercentual); }