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); }
public async Task <IActionResult> Post([FromBody] RegisterOrderCommand command) { var customer = User.Identity.Name; var result = _handler.Handle(command); return(await Response(result, _handler.Notifications)); }
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); }
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); }
private static void GenerateOrder( ICustomerRepository customerRepository, IProductRepository productRepository, IOrderRepository orderRepository, RegisterOrderCommand command) { var handler = new OrderCommandHandler(customerRepository, productRepository, orderRepository); handler.Handle(command); }
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"); } }
public IActionResult Post([FromBody] CreateNewOrderCommand command) { command.Validate(); if (command.Invalid) { return(BadRequest(command.Notifications)); } var commandResult = orderCommandHandler.Handle(command); return(Ok(commandResult)); }
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); } }
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")); } }
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!"); } }
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"); }
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)); }
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)); }