public void GetHighestOrderIDReturnsInt()
        {
            var options = new DbContextOptionsBuilder <SGDB2Context>()
                          .UseInMemoryDatabase(databaseName: "SGDB2")
                          .Options;

            using (var context = new SGDB2Context(options))
            {
                var orderId = StoreMethods.GetAllOrderIds(context);
                var result  = StoreMethods.GetNewOrderId(orderId);
                Assert.IsType <int>(result);
            }
        }//16
        public void GetHighestOrderIdIncrements()
        {
            var options = new DbContextOptionsBuilder <SGDB2Context>()
                          .UseInMemoryDatabase(databaseName: "SGDB2")
                          .Options;

            using (var context = new SGDB2Context(options))
            {
                var orderId = StoreMethods.GetAllOrderIds(context);
                var result  = StoreMethods.GetNewOrderId(orderId);
                orderId.Add(result);
                var result1 = StoreMethods.GetNewOrderId(orderId);

                Assert.True(result1 != result);
            }
        }//17
        /// <summary>
        /// Creates a new order item, calculates order total and updates inventory
        /// </summary>
        public IActionResult Checkout()
        {
            //Takes our Cart, creates a new order item, calculates orderTotal, and updates the inventory

            //get the logged in customer
            var loggedIn = _cache.Get("loggedInCustomer");

            loggedInCustomer = (Customers)loggedIn;

            //Retrieve the cart contents
            var itemCart = _cache.Get("Cart");
            List <OrderInformation> cart = new List <OrderInformation>();

            cart = (List <OrderInformation>)itemCart;

            //Get new order id
            var orderList  = StoreMethods.GetAllOrderIds(_db);
            int newOrderId = StoreMethods.GetNewOrderId(orderList);

            if (cart.Count == 0)
            {
                _logger.LogInformation("Cart was empty");
                return(View("_Checkout"));
            }
            else //Begin checkout
            {
                _logger.LogInformation("Cart had items, beginning checkout...");
                decimal orderTotal = 0;
                foreach (var product in cart)
                {
                    //Update the item quantities
                    var allItemsInventory = StoreMethods.GetAllProducts(_db);

                    var storeInventory = (from Inventory in _db.Inventory
                                          where Inventory.StoreInventory == loggedInCustomer.DefaultStore && Inventory.ItemInInventory == product.OrderedProduct
                                          select new { Inventory.InventoryId,
                                                       Inventory.ItemInInventory,
                                                       Inventory.StoreInventory,
                                                       Inventory.ProductCurrentQuantity }).ToList();  //Gets only the user's default store's inventory
                    //var allInventories = (from Inventory in _db.Inventory
                    //                      select new
                    //                      {
                    //                          Inventory.InventoryId,
                    //                          Inventory.ItemInInventory,
                    //                          Inventory.StoreInventory,
                    //                          Inventory.ProductCurrentQuantity
                    //                      }).ToList();
                    foreach (var Inventory in _db.Inventory) //Update the ordered product's quantity
                    {
                        foreach (var storeInv in storeInventory)
                        {
                            if (storeInv.StoreInventory == Inventory.StoreInventory && Inventory.ItemInInventory == product.OrderedProduct)
                            {
                                Inventory.ProductCurrentQuantity -= product.OrderedProductAmount; //New quantity set for ordered product
                                _logger.LogInformation($"Amount decremented");
                            }
                        }
                    }
                    _db.SaveChanges();
                    if (product.IsBundle == true) //if the ordered product is a bundle, update associated items
                    {
                        foreach (var inventory in _db.Inventory)
                        {
                            foreach (var items in allItemsInventory)
                            {
                                if (items.BundleId == product.BundleId && inventory.ItemInInventory == items.Skunum && items.IsInBundle == true && inventory.StoreInventory == loggedInCustomer.DefaultStore) //if the item is InBundle, is part of the orderedProduct's bundle, and available at the same store
                                {
                                    inventory.ProductCurrentQuantity -= product.OrderedProductAmount;                                                                                                         //Decrement items that are a part of the bundle as well
                                    _logger.LogInformation("Bundle included item decremented");
                                }
                            }
                        }
                    }
                    _db.SaveChanges();
                    //Because the 'unit price' of each item is calculated with ordered# and discount, just add item totals
                    orderTotal += product.UnitPrice;
                    orderTotal  = Math.Round(orderTotal, 2); //2 decimal points
                }
                //Need a uniform order total, so we need another foreach loop
                foreach (var product in cart)
                {
                    Orders newOrder = new Orders();
                    newOrder.OrderDate            = DateTime.Now;
                    newOrder.OrderedProduct       = product.OrderedProduct;
                    newOrder.OrderedProductAmount = product.OrderedProductAmount;
                    newOrder.OrderTotal           = orderTotal;
                    newOrder.StoreOrderedFrom     = loggedInCustomer.DefaultStore;
                    newOrder.WhoOrdered           = loggedInCustomer.CustomerId;
                    newOrder.OrderId = newOrderId;
                    _db.Orders.Add(newOrder);
                    _db.SaveChanges();
                }
                //Empty out the cart, set the cache's cart to be the new empty cart, then return the checkout screen
                List <OrderInformation> emptyCart    = new List <OrderInformation>();
                List <OrderInformation> checkoutCart = new List <OrderInformation>();
                foreach (var item in cart)
                {
                    OrderInformation purchased = new OrderInformation();
                    purchased            = item;
                    purchased.OrderDate  = DateTime.Now;
                    purchased.OrderTotal = orderTotal;
                    checkoutCart.Add(purchased);
                }
                _cache.Set("Cart", emptyCart);
                return(View("_Checkout", checkoutCart));
            }
        }