Esempio n. 1
0
        public IResult Handle(ChangeCustomerCommand command)
        {
            //Criar ValueObjects
            var name  = new NameVo(command.Nome, command.Sobrenome);
            var cpf   = new CpfVo(command.Documento);
            var email = new Email(command.Email);
            //Criar
            var customer = new Customer(name, cpf, email, command.Telefone);

            //Validar
            AddNotifications(name.Notifications);
            AddNotifications(cpf.Notifications);
            AddNotifications(email.Notifications);

            if (Invalid)
            {
                return(new ApiContract(false,
                                       "Erro, corrija os seguintes problemas:",
                                       Notifications));
            }

            try
            {
                _repository.Save(customer, command.Id);
            }
            catch (Exception ex)
            {
                //TO-DO: implementar log real
                throw new Exception("Erro - Handler CustomerHandler" + ex.Message);
            }

            return(new ApiContract(true, "Customer criado com sucesso", null));
        }
        public void ShouldUpdateTheCustomersName()
        {
            var cust = new Customer {
                Id = 5, Name = "John Doe"
            };
            var cmd     = new ChangeCustomerCommand(cust);
            var newName = "Billy Bob";

            cmd.Execute(newName);
            Assert.Equal(newName, cmd.Customer.Name);
        }
        public void ShouldRollBackTheChange()
        {
            var originalName = "John Doe";
            var cust         = new Customer {
                Id = 5, Name = originalName
            };
            var cmd     = new ChangeCustomerCommand(cust);
            var newName = "Billy Bob";

            cmd.Execute(newName);
            cmd.UnExecute();
            Assert.Equal(originalName, cmd.Customer.Name);
            Assert.Equal(5, cmd.Customer.Id);
        }
        public void ShouldUpdateTheCustomersName()
        {
            // Arrange
            var cust = new Customer {
                Id = 5, Name = "John Doe"
            };
            var cmd      = new ChangeCustomerCommand(cust);
            var expected = "Billy Bob";

            // Action
            cmd.Execute(expected);

            // Assert
            Assert.AreEqual(expected, cmd.Customer.Name);
        }
        public void ShouldRollBackTheChange()
        {
            // Arrange
            var expectedName = "John Doe";
            var expectedId   = 5;
            var cust         = new Customer {
                Id = expectedId, Name = expectedName
            };
            var cmd     = new ChangeCustomerCommand(cust);
            var newName = "Billy Bob";

            cmd.Execute(newName);

            // Action
            cmd.UnExecute();

            // Assert
            Assert.AreEqual(expectedName, cmd.Customer.Name);
            Assert.AreEqual(expectedId, cmd.Customer.Id);
        }
 public IActionResult Put([FromBody] ChangeCustomerCommand command)
 {
     return(StatusCode(204, _commandHandler.Handle(command)));
 }