public void OrderTests_PlaceOrder_ReturnOrderNumber()
        {
            PlaceOrderUseCase _placeOrder = new PlaceOrderUseCase(
                new FakeCustomerReadOnlyRepository(),
                new FakeOrderWriteRepository(),
                new FakeKafkaProducer());

            Guid customerId = Guid.NewGuid();

            var orderInput = new PlaceOrderInput()
            {
                CustomerId  = customerId,
                ProductItem = new PlaceOrderProductInput()
                {
                    Description = "O melhor teclado da Microsoft",
                    Image       = "teclado.png",
                    Price       = 10M,
                    Title       = "Teclado Microsoft",
                    Quantity    = 5
                }
            };

            string order = _placeOrder.Execute(orderInput);

            AddNotifications(_placeOrder.Notifications);

            Assert.AreEqual(true, !Invalid);
        }
Esempio n. 2
0
        public IActionResult Post([FromBody] PlaceOrderInput input)
        {
            var order = _placeOrderService.Execute(input);

            Console.WriteLine("Ordem criada: " + order);//apenas para efeito de demo
            return(Ok(new { Message = "Ordem criada: " + order }));;
        }
Esempio n. 3
0
        //To-DO: criar uma padrão para retorno com smart notification
        public string Execute(PlaceOrderInput order)
        {
            #region Obter dados do banco
            //Customer customer = _customerReadOnlyRepository.Get(customerId);
            //if (customer == null)
            //{
            //    AddNotification("Customer", "Customer does not exist.");
            //}
            #endregion

            //Simulando dados, não implementei acesso a dados
            var name  = new NameVo("Ray", "Carneiro");
            var cpf   = new CpfVo("15366015006");
            var email = new EmailVo("*****@*****.**");
            _customer = new Customer(name, cpf, email, "11-5555-5555");

            if (_customer.Invalid)
            {
                AddNotification("Cliente", "Erros identificados nos dados de cliente: ");
                return(_customer.Notifications.FirstOrDefault().Message);
            }

            _order = new Order(_customer);
            var product = new Product(order.ProductItem.Title, order.ProductItem.Description, order.ProductItem.Image, order.ProductItem.Price, 10);
            _order.AddItem(product, order.ProductItem.Quantity);

            if (_order.Invalid)
            {
                AddNotification("Pedido", "Erros identificados nos dados do seu pedido: ");
                return(_order.Notifications.FirstOrDefault().Message);
            }

            string orderId;

            try
            {
                orderId = _orderWriteOnlyRepository.PlaceOrder(_customer, _order);

                _kafkaProducer.Produce(orderId);
            }
            catch (Exception ex)
            {
                //TO-DO: Implement log
                throw;
            }

            return("Número do pedido: " + orderId);
        }
        public string Execute(PlaceOrderInput order)
        {
            //Simulação de dados e regras de negócios
            var name  = new NameVo("Ray", "Carneiro");
            var cpf   = new CpfVo("15366015006");
            var email = new EmailVo("*****@*****.**");

            _customer = new Customer(name, cpf, email, "11-5555-5555");

            if (_customer.Invalid)
            {
                AddNotification("Cliente", "Erros identificados nos dados de cliente: ");
                return(_customer.Notifications.FirstOrDefault().Message);
            }

            _order = new Order(_customer);
            var product = new Product(order.ProductItem.Title, order.ProductItem.Description, order.ProductItem.Image, order.ProductItem.Price, 10);

            _order.AddItem(product, order.ProductItem.Quantity);

            if (_order.Invalid)
            {
                AddNotification("Pedido", "Erros identificados nos dados do seu pedido: ");
                return(_order.Notifications.FirstOrDefault().Message);
            }

            string orderId;

            try
            {
                //Salva ordem no banco de dados
                orderId = _orderWriteOnlyRepository.PlaceOrder(_customer, _order);

                //Envia mensagem para Kafka
                _kafkaAdapter.Produce(orderId);
            }
            catch
            {
                throw;
            }

            return("Número do pedido: " + orderId);
        }
Esempio n. 5
0
 public Task Execute(PlaceOrderInput placeOrderInput)
 {
     //return Task.CompletedTask;
     throw new Exception();
 }
Esempio n. 6
0
        public Task Execute(PlaceOrderInput placeOrderInput)
        {
            _bus.PublishOrder(placeOrderInput);

            return(Task.CompletedTask);
        }
Esempio n. 7
0
 public IActionResult Post([FromBody] PlaceOrderInput input)
 {
     return(Ok(new { Message = _placeOrderService.Execute(input) }));
 }
Esempio n. 8
0
        public void PublishOrder(PlaceOrderInput placeOrderInput)
        {
            string json = JsonConvert.SerializeObject(placeOrderInput);

            Publish(typeof(PlaceOrderInput).Name, json);
        }