public IActionResult Index(int?id)
        {
            if (!Util.IsLoggedIn(_cache))
            {
                return(RedirectToAction("Login", "Customer"));
            }

            List <ShoppingCart> shoppingCartProds = (List <ShoppingCart>)_cache.Get("shoppingCart");

            _cache.Set("StoreId", id);
            Store store = DbManipulation.GetStore(_db, id);

            _cache.Set("Store", store);

            List <Inventory> inventories = DbManipulation.GetInventoriesOfStore(_db, id).OrderBy(pid => pid.ProductId).ToList();
            List <Product>   prodList    = DbManipulation.GetProducts(_db).ToList();

            DbManipulation.SetShoppingCartStock(shoppingCartProds, inventories);

            ViewModel viewModel = new ViewModel();

            IEnumerable <ProductView> EProdViews = viewModel.CreateProductViews(prodList, inventories);


            return(View(EProdViews));
        }
        public void CreateProductViewsHasCorrectInventoryAmount()
        {
            var options = new DbContextOptionsBuilder <BookopolisDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreateProductViewsHasCorrectInventoryAmount")
                          .Options;

            using (var context = new BookopolisDbContext(options))
            {
                DbManipulation.SeedDb(context);

                List <Product>   products    = DbManipulation.GetProducts(context).ToList();
                List <Inventory> inventories = DbManipulation.GetInventoriesOfStore(context, 1).ToList();

                foreach (Inventory inventory in inventories)
                {
                    inventory.Amount = 1;
                }

                ViewModel viewModel = new ViewModel();

                List <ProductView> productViews = viewModel.CreateProductViews(products, inventories).ToList();

                foreach (ProductView productView in productViews)
                {
                    Assert.Equal(1, productView.Amount);
                }
            }
        }
        public void GetInventoryOfShoppingCartReturnsCorrectShoppingCart()
        {
            var options = new DbContextOptionsBuilder <BookopolisDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetInventoryOfShoppingCartReturnsCorrectShoppingCart")
                          .Options;

            using (var context = new BookopolisDbContext(options))
            {
                DbManipulation.SeedDb(context);

                List <Product>      products             = DbManipulation.GetProducts(context).ToList();
                List <ShoppingCart> shoppingCartProducts = new List <ShoppingCart>()
                {
                    new ShoppingCart()
                    {
                        Inventory = new Inventory()
                        {
                            InventoryId = 1
                        },
                        ProductId   = 1,
                        StoreId     = 1,
                        StockAmount = 1
                    },
                    new ShoppingCart()
                    {
                        Inventory = new Inventory()
                        {
                            InventoryId = 2
                        },
                        ProductId   = 1,
                        StoreId     = 1,
                        StockAmount = 0
                    },
                    new ShoppingCart()
                    {
                        Inventory = new Inventory()
                        {
                            InventoryId = 3
                        },
                        ProductId   = 1,
                        StoreId     = 2,
                        StockAmount = 2
                    }
                };

                List <ShoppingCart> result = DbManipulation.GetInventoryOfShoppingCart(shoppingCartProducts, 1, 1);

                foreach (ShoppingCart shoppingCart in result)
                {
                    Assert.Equal(1, shoppingCart.StoreId);
                    Assert.Equal(1, shoppingCart.ProductId);
                }
            }
        }
        public void GetProductsReturnsAllProducts()
        {
            var options = new DbContextOptionsBuilder <BookopolisDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetProductsReturnsAllProducts")
                          .Options;

            using (var context = new BookopolisDbContext(options))
            {
                DbManipulation.SeedDb(context);

                IEnumerable <Product> products     = DbManipulation.GetProducts(context);
                List <Product>        productsList = products.ToList();
                Assert.InRange(productsList.Count, 1, productsList.Count + 1);
            }
        }