public async Task CanOrderMenuItems(
            Guid tabId,
            int tableNumber,
            MenuItem[] itemsToOrder)
        {
            // Arrange
            await _helper.OpenTabOnTable(tabId, tableNumber);

            await _helper.AddMenuItems(itemsToOrder);

            var orderItemsCommand = new OrderMenuItems
            {
                TabId       = tabId,
                ItemNumbers = itemsToOrder.Select(i => i.Number).ToList()
            };

            // Act
            var result = await _fixture.SendAsync(orderItemsCommand);

            // Assert
            await _helper.AssertTabExists(
                orderItemsCommand.TabId,
                t => t.IsOpen == true &&
                t.OutstandingMenuItems.Any() &&
                orderItemsCommand.ItemNumbers.All(n => t.OutstandingMenuItems.Any(i => i.Number == n)));
        }
Exemple #2
0
        public Task OrderItemsShouldReturnProperHypermediaLinks(Guid tabId, MenuItem[] menuItems, Fixture fixture) =>
        _apiHelper.InTheContextOfAWaiter(
            waiter => async httpClient =>
        {
            // Arrange
            await _tabHelper.AddMenuItems(menuItems);

            var tableNumber = waiter.ServedTables[0].Number;
            await _tabHelper.OpenTabOnTable(tabId, tableNumber);

            var orderItemsCommand = new OrderMenuItems
            {
                TabId       = tabId,
                ItemNumbers = menuItems.Select(i => i.Number).ToList()
            };

            // Act
            var response = await httpClient
                           .PutAsJsonAsync(TabRoute("order"), orderItemsCommand);

            // Assert
            var expectedLinks = new List <string>
            {
                LinkNames.Self,
                LinkNames.Tab.GetTab,
                LinkNames.Tab.ServeItems,
                LinkNames.Tab.RejectItems,
                LinkNames.Tab.Close
            };

            await response.ShouldBeAResource <OrderMenuItemsResource>(expectedLinks);
        },
            fixture);
        public async Task CannotOrderItemsOnAClosedTab(
            Guid tabId,
            int tableNumber,
            MenuItem[] itemsToOrder)
        {
            // Arrange
            await _helper.AddMenuItems(itemsToOrder);

            await _helper.OpenTabOnTable(tabId, tableNumber);

            var closeTabCommand = new CloseTab
            {
                TabId      = tabId,
                AmountPaid = 0
            };

            await _fixture.SendAsync(closeTabCommand);

            var orderItemsCommand = new OrderMenuItems
            {
                TabId       = tabId,
                ItemNumbers = itemsToOrder.Select(i => i.Number).ToList()
            };

            // Act
            var result = await _fixture.SendAsync(orderItemsCommand);

            // Assert
            result.ShouldHaveErrorOfType(ErrorType.Validation);
        }
Exemple #4
0
        private OrderMenuItems SetNewMenuItem(int menuItemID, int orderInfoID, int menuItemQuantity)
        {
            OrderMenuItems newMenuItem = new OrderMenuItems();

            newMenuItem.MenuID             = menuItemID;
            newMenuItem.MenuItemQuantity   = menuItemQuantity;
            newMenuItem.OrderInformationID = orderInfoID;

            return(newMenuItem);
        }
Exemple #5
0
        public IActionResult BuyItem(int menuID, int itemQuantity, int supermarketID)
        {
            IncomeVM vM = new IncomeVM(Context);

            Order checkExistOrder = Context.Order.FirstOrDefault(o => o.Date.Hour == DateTime.Now.Hour && o.CustomerID == GetLoginCustomer());

            if (checkExistOrder != null)
            {
                OrderInformation checkExistOrderInfo = Context.OrderInformation.FirstOrDefault(o => o.PlaceID == supermarketID && o.OrderID == checkExistOrder.ID);

                if (checkExistOrderInfo == null)
                {
                    OrderInformation newOrderInfo = new OrderInformation();
                    newOrderInfo.PlaceID = supermarketID;

                    newOrderInfo.DelivaryCost = vM.DelivaryPlaceCost(supermarketID, vM.GetCustomerArea(GetLoginCustomer()).ID);
                    newOrderInfo.OrderID      = checkExistOrder.ID;
                    Context.OrderInformation.Add(newOrderInfo);
                    Context.SaveChanges();

                    OrderMenuItems menuItem = new OrderMenuItems();
                    menuItem.MenuID             = menuID;
                    menuItem.MenuItemQuantity   = itemQuantity;
                    menuItem.OrderInformationID = newOrderInfo.ID;
                    Context.OrderMenuItems.Add(menuItem);
                    Context.SaveChanges();
                }
                else
                {
                    OrderMenuItems menuItem = new OrderMenuItems();
                    menuItem.MenuID             = menuID;
                    menuItem.MenuItemQuantity   = itemQuantity;
                    menuItem.OrderInformationID = checkExistOrderInfo.ID;
                    Context.OrderMenuItems.Add(menuItem);
                    Context.SaveChanges();
                }
            }
            else
            {
                checkExistOrder = SetNewOrder();
                Context.Order.Add(checkExistOrder);
                Context.SaveChanges();

                OrderInformation newOrderInfo = SetNewOrderInfo(supermarketID, checkExistOrder.ID);
                Context.OrderInformation.Add(newOrderInfo);
                Context.SaveChanges();

                OrderMenuItems newOrderMenuItems = SetNewMenuItem(menuID, newOrderInfo.ID, itemQuantity);
                Context.OrderMenuItems.Add(newOrderMenuItems);
                Context.SaveChanges();
            }

            return(Content("Added to Shopping Card"));
        }
Exemple #6
0
        public async Task OrderMenuItems(Guid tabId, params MenuItem[] items)
        {
            var itemNumbers = items.Select(i => i.Number).ToList();

            var orderItems = new OrderMenuItems
            {
                TabId       = tabId,
                ItemNumbers = itemNumbers
            };

            var result = await _fixture.SendAsync(orderItems);
        }
        public async Task CannotOrderItemsOnAnUnexistingTab(
            MenuItem[] itemsToOrder,
            HireWaiter hireWaiterCommand,
            AddTable addTableCommand)
        {
            // Arrange
            await _helper.SetupWaiterWithTable(hireWaiterCommand, addTableCommand);

            // Purposefully not opening a tab
            var orderItemsCommand = new OrderMenuItems
            {
                TabId       = Guid.NewGuid(),
                ItemNumbers = itemsToOrder.Select(i => i.Number).ToList()
            };

            // Act
            var result = await _fixture.SendAsync(orderItemsCommand);

            // Assert
            result.ShouldHaveErrorOfType(ErrorType.NotFound);
        }
        public async Task CannotOrderUnexistingItems(
            Guid tabId,
            int tableNumber,
            int[] menuItemNumbersToOrder)
        {
            // Arrange
            await _helper.OpenTabOnTable(tabId, tableNumber);

            // Purposefully not adding any items
            var orderItemsCommand = new OrderMenuItems
            {
                TabId       = tabId,
                ItemNumbers = menuItemNumbersToOrder
            };

            // Act
            var result = await _fixture.SendAsync(orderItemsCommand);

            // Assert
            result.ShouldHaveErrorOfType(ErrorType.NotFound);
        }
Exemple #9
0
 public async Task <IActionResult> OrderMenuItems([FromBody] OrderMenuItems command) =>
 (await Mediator.Send(command)
  .MapAsync(_ => ToEmptyResourceAsync <OrderMenuItemsResource>(x => x.TabId = command.TabId)))
 .Match(Ok, Error);