Example #1
0
        public async Task Update_AtualizarClienteTest()
        {
            #region Arrange

            var resource = $"api/Cliente";

            var command = new UpdadeClienteCommand
            {
                Id             = 1004,
                Nome           = "Gustavo C. Santanna",
                Cpf            = "00425718719",
                Idade          = 46,
                DataNascimento = new DateTime(1974, 06, 25)
            };

            #endregion

            #region Act

            var request = new StringContent(JsonConvert.SerializeObject(command),
                                            Encoding.UTF8, "application/json");

            var response = await httpClient.PutAsync(resource, request);

            #endregion

            #region Assert

            response.StatusCode.Should().Be(HttpStatusCode.OK);

            #endregion
        }
Example #2
0
        public IActionResult Put(UpdadeClienteCommand command)
        {
            try
            {
                clienteApplicationService.Update(command);

                return(Ok(new { Message = "Cliente atualizado com sucesso" }));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));;
            }
        }
Example #3
0
        public void Update(UpdadeClienteCommand command)
        {
            var cliente = clienteRepository.GetById(command.Id);

            if (cliente == null)
            {
                throw new Exception("Cliente não encontrado.");
            }

            cliente.Nome           = command.Nome;
            cliente.Cpf            = command.Cpf;
            cliente.Idade          = command.Idade;
            cliente.DataNascimento = command.DataNascimento;

            var validation = new ClienteValidation().Validate(cliente);

            if (!validation.IsValid)
            {
                throw new ValidationException(validation.Errors.ToString());
            }

            clienteRepository.Update(cliente);
        }