Пример #1
0
        public async Task <IActionResult> AddItemInOrderItemList([FromBody] AddItemCommand command)
        {
            if (command == null)
            {
                return(await Respond(null, new List <Notification> {
                    new Notification("Order", "Parameters is invalid.")
                }));
            }

            var result = _orderCommandHandler.Handle(command);

            return(await Respond(result, _orderCommandHandler.Notifications));
        }
        public async void AddOrderItem_NewOrder_ShouldAddItem()
        {
            // Arrange
            var command = new AddOrderItemCommand(Guid.NewGuid(), Guid.NewGuid(), "item x", 2, 100);

            _mocker.GetMock <IOrderRepository>().Setup(r => r.UnitOfWork.Commit()).Returns(Task.FromResult(true));

            // Act
            var result = await _orderCommandHandler.Handle(command, CancellationToken.None);

            // Assert
            Assert.True(result);
            _mocker.GetMock <IOrderRepository>().Verify(r => r.Add(It.IsAny <Order>()), Times.Once);
            _mocker.GetMock <IOrderRepository>().Verify(r => r.UnitOfWork.Commit(), Times.Once);
        }
Пример #3
0
        public async Task <IActionResult> Post([FromBody] RegisterOrderCommand command)
        {
            var customer = User.Identity.Name;
            var result   = _handler.Handle(command);

            return(await Response(result, _handler.Notifications));
        }
Пример #4
0
        public async Task ShoudPlaceValidOrder()
        {
            var orderItems = new List <OrderItemCommand>();

            _products.ForEach(x => { orderItems.Add(new OrderItemCommand {
                    Product = x.Id, Quantity = 4
                }); });

            var result = await _commandHanddler.Handle(new PlaceOrderCommand
            {
                CustomerId    = _customer.Id,
                OrderItems    = orderItems,
                CreditCard    = _creditCardCommand,
                DiscountCupon = "XPTO1",
            }, CancellationToken.None);

            Assert.AreEqual(result, true);
        }
Пример #5
0
        void Should_Calculate_Total_Price_And_TimeToPrepare_When_Pizza_Is_Simple_And_Small()
        {
            var command = new CreateNewOrderCommand(pizzaFixture.PizzaSmallCalabresa);

            var result = orderCommandHandler.Handle(command);

            Assert.NotNull(result);
            Assert.Equal(20, result.TotalPrice);
            Assert.Equal(15, result.TimeToPrepare);
        }
Пример #6
0
        private static void GenerateOrder(
            ICustomerRepository customerRepository,
            IProductRepository productRepository,
            IOrderRepository orderRepository,
            RegisterOrderCommand command)
        {
            var handler = new OrderCommandHandler(customerRepository, productRepository, orderRepository);

            handler.Handle(command);
        }
Пример #7
0
        public static void GenerateOrder(ICustomerRepository customerRepository, IProductRepository productRepository, IOrderRepository orderRepository, RegisterOrderCommand command)
        {
            var handler = new OrderCommandHandler(customerRepository, productRepository, orderRepository);

            handler.Handle(command);

            if (handler.IsValid())
            {
                Console.WriteLine("Your order has been submitted");
            }
        }
Пример #8
0
        public IActionResult Post([FromBody] CreateNewOrderCommand command)
        {
            command.Validate();

            if (command.Invalid)
            {
                return(BadRequest(command.Notifications));
            }

            var commandResult = orderCommandHandler.Handle(command);

            return(Ok(commandResult));
        }
Пример #9
0
 public void Checkout(CheckoutParameter checkoutParameter)
 {
     foreach (var product in checkoutParameter.CartParameter.Products)
     {
         var orderCommand = new OrderCommand
         {
             CustomerId = checkoutParameter.CustomerId,
             CartId     = checkoutParameter.CartParameter.CartId,
             ProductId  = product.ProductId,
             ItemCount  = product.ItemCount
         };
         _orderCommandHandler.Handle(orderCommand);
     }
 }
Пример #10
0
        public ActionResult Order(OrderCommand order, [FromServices] OrderCommandHandler handler)
        {
            var result = handler.Handle(order);

            if (result.PaymentOk)
            {
                ViewData["Message"] = "Thank you. Your order has been placed.";
                return(View(result));
            }
            else
            {
                return(RedirectToAction("PaymentFailed"));
            }
        }
Пример #11
0
        public static void GenerateOrder(
            ICustomerRepository customerRepository,
            IProductRepository productRepository,
            IOrderRepository orderRepository,
            RegisterOrderCommand command)
        {
            var handler = new OrderCommandHandler(customerRepository, productRepository, orderRepository);

            handler.Handle(command);

            if (handler.IsValid())
            {
                System.Console.WriteLine("Customer registrado com sucesso!");
            }
        }
Пример #12
0
        public static void GenerateOrder(ICustomerRepository customerRepository, IProductRepository productRepository, IOrderRepository orderRepository, RegisterOrderCommand command)
        {
            var handler = new OrderCommandHandler(customerRepository, productRepository, orderRepository);

            handler.Handle(command);

            //Console.WriteLine($"Anterior {mouse.QuantityOnHand} mouse");
            //Console.WriteLine($"Anterior {mousePad.QuantityOnHand} mousePad");
            //Console.WriteLine($"Anterior {teclado.QuantityOnHand} teclado");
            //order.AddItem(new OrderItem(mouse, 2));
            //order.AddItem(new OrderItem(mousePad, 2));
            //order.AddItem(new OrderItem(teclado, 2));
            //Console.WriteLine($"Depois {mouse.QuantityOnHand} mouse");
            //Console.WriteLine($"Depois {mousePad.QuantityOnHand} mousePad");
            //Console.WriteLine($"Depois {teclado.QuantityOnHand} teclado");
        }
Пример #13
0
 public ICommandResult AddOrder(CreateOrderCommand createOrderCommand)
 {
     return(_orderCommandHandler.Handle(createOrderCommand));
 }
        public async Task <IActionResult> Post([FromBody] RegisterOrderCommand command)
        {
            var result = _handler.Handle(command);

            return(await ResponseAsync(result, _handler.Notifications));
        }
Пример #15
0
 public async Task <IActionResult> Post([FromBody] RegisterOrderCommand command) =>
 await Response(_handler.Handle(command), _handler.Notifications);
 private void PlaceOrder(IList <KeyValuePair <StroopwafelType, int> > orderDetails, string supplier)
 {
     _orderCommandHandler.Handle(new OrderCommand(orderDetails, supplier));
 }