public async Task <OrderModel> Handle(AddItemToOrderCommand request, CancellationToken cancellationToken) { var ordersInMemory = OrdersInMemory.GetInstance(); var order = ordersInMemory.OrderList.Where(x => x.OrderId == request.Id).FirstOrDefault(); var menu = MockData.GetInstance(); var menuItem = menu.MenuList.Where(item => item.MenuItemId == request.MenuItemId).FirstOrDefault(); var orderItem = new OrderItem { OrderItemId = Guid.NewGuid(), MenuItemId = request.MenuItemId, Cost = menuItem.Cost, Name = menuItem.Name, Type = menuItem.Type }; order.TotalPrice += menuItem.Cost; if (menuItem.Type == "Pizza") { orderItem.Ingredients = menuItem.Ingredients; } order.Items.Add(orderItem); return(await Task.FromResult(order)); }
public async Task <List <OrderModel> > Handle(GetInProgressOrdersQuery request, CancellationToken cancellationToken) { var ordersInMemory = OrdersInMemory.GetInstance(); var orderById = ordersInMemory.OrderList.Where(x => x.Status == OrderStatus.InProgress).ToList(); return(await Task.FromResult(orderById)); }
public async Task <OrderModel> Handle(GetOrderQuery request, CancellationToken cancellationToken) { var ordersInMemory = OrdersInMemory.GetInstance(); var orderById = ordersInMemory.OrderList.Where(x => x.OrderId == request.OrderId).FirstOrDefault(); return(await Task.FromResult(orderById)); }
public async Task <OrderModel> Handle(CompleteOrderCommand request, CancellationToken cancellationToken) { var ordersInMemory = OrdersInMemory.GetInstance(); var order = ordersInMemory.OrderList.Where(x => x.OrderId == request.Id).FirstOrDefault(); order.Status = OrderStatus.Done; return(await Task.FromResult(order)); }
public async Task <Response <OrderModel> > Handle(RemoveProductFromOrderCommand request, CancellationToken cancellationToken) { var ordersInMemory = OrdersInMemory.GetInstance(); var orderById = ordersInMemory.OrderList.Where(x => x.OrderId == request.OrderId).FirstOrDefault(); var itemToRemove = orderById.Items.Where(x => x.OrderItemId == request.MenuId).FirstOrDefault(); orderById.TotalPrice -= itemToRemove.Cost; orderById.Items.Remove(itemToRemove); return(await Task.FromResult(Response.Ok(orderById, " success"))); }
public async Task <Response <OrderModel> > Handle(RemoveOrderCommand request, CancellationToken cancellationToken) { var ordersInMemory = OrdersInMemory.GetInstance(); var orderById = ordersInMemory.OrderList.Where(x => x.OrderId == request.id).FirstOrDefault(); ordersInMemory.OrderList.Remove(orderById); return(await Task.FromResult(Response.Ok(orderById, " success"))); }
public async void GetInProgressOrderHandlerFailure() { var mockOrder = new MockOrderData(); var createOrder = mockOrder.CreateOrder(); GetInProgressOrdersQuery getInProgressOrdersQuery = new GetInProgressOrdersQuery(); GetInProgressOrdersHandler getInProgressOrdersHandler = new GetInProgressOrdersHandler(); var actual = await getInProgressOrdersHandler.Handle(getInProgressOrdersQuery, new CancellationToken()); var actualInProgress = actual.Where(x => x.Status == OrderStatus.InProgress).Count(); var orders = OrdersInMemory.GetInstance(); var expected = orders.OrderList.Where(x => x.Status == OrderStatus.InProgress).Count() + 1; Assert.NotEqual(expected, actualInProgress); }
public async void GetAllOrdersHandlerSuccess() { var mockOrder = new MockOrderData(); mockOrder.CreateOrder(); mockOrder.CreateOrder(); GetAllOrderQuery getAllOrderQuery = new GetAllOrderQuery(); GetAllOrderHandler getAllOrderHandler = new GetAllOrderHandler(); var actualHandle = await getAllOrderHandler.Handle(getAllOrderQuery, new CancellationToken()); var actual = actualHandle.Select(x => x.OrderId).Count(); var orderList = OrdersInMemory.GetInstance(); var expected = orderList.OrderList.Count(); Assert.Equal(expected, actual); }
public async Task <Response <OrderModel> > Handle(CreateNewOrderCommand request, CancellationToken cancellationToken) { var ordersInMemory = OrdersInMemory.GetInstance(); var order = new OrderModel { OrderId = Guid.NewGuid(), Name = request.Name, Items = new List <OrderItem>(), Created = DateTime.Now, Status = OrderStatus.InProgress }; ordersInMemory.OrderList.Add(order); return(await Task.FromResult(Response.Ok(order, "OrderCreated"))); }
public async void AddItemToOrderHandlerSuccess() { AddItemToOrderHandler addItemToOrderHandler = new AddItemToOrderHandler(); var ordersInMemory = OrdersInMemory.GetInstance(); var mockOrder = new MockOrderData(); var request = mockOrder.CreateOrder(); var order = ordersInMemory.OrderList.Where(x => x.OrderId == request.OrderId).FirstOrDefault(); AddItemToOrderCommand addItemToOrderCommand = new AddItemToOrderCommand(request.OrderId, 3); var actual = await addItemToOrderHandler.Handle(addItemToOrderCommand, new CancellationToken()); var actualName = actual.Items.Select(x => x.MenuItemId).FirstOrDefault(); var expected = 3; Assert.Equal(expected, actualName); }
public OrderModel CreateOrder() { var ordersInMemory = OrdersInMemory.GetInstance(); var order = new OrderModel { OrderId = Guid.NewGuid(), Name = "Johan", Items = new List <OrderItem>(), Created = DateTime.Now, Status = OrderStatus.InProgress }; ordersInMemory.OrderList.Add(order); return(order); }
public async Task <Response <OrderModel> > Handle(AddIngredientsCommand request, CancellationToken cancellationToken) { var ordersInMemory = OrdersInMemory.GetInstance(); var order = ordersInMemory.OrderList.Where(x => x.OrderId == request.OrderId).FirstOrDefault(); var menuItem = order.Items.Where(x => x.OrderItemId == request.PizzaId).FirstOrDefault(); var ingredients = MockData.GetInstance(); var pickIngredients = ingredients.IngredientsList.Where(x => x.IngredientId == request.IngredientId).FirstOrDefault(); order.TotalPrice += pickIngredients.Cost; if (menuItem.Type == "Pizza") { menuItem.Ingredients.Add(pickIngredients); return(await Task.FromResult(Response.Ok(order, " success"))); } return(await Task.FromResult(Response.Fail("Need to be a pizza to add ingredients", order))); }
public async Task <List <OrderModel> > Handle(GetAllOrderQuery request, CancellationToken cancellationToken) { var ordersInMemory = OrdersInMemory.GetInstance(); return(await Task.FromResult(ordersInMemory.OrderList)); }