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 IActionResult StoreOrders(int id) { if (!Util.IsLoggedIn(_cache)) { return(RedirectToAction("Login", "Customer")); } ViewData["StoreOrders"] = "active"; ViewModel viewModel = new ViewModel(); var orderProducts = DbManipulation.GetOrdersFromStore(_db, id); List <Store> stores = DbManipulation.GetStores(_db).ToList(); if (id == 0) { ViewData["CurrentStore"] = "none"; } else { ViewData["CurrentStore"] = stores.FirstOrDefault(s => s.StoreId == id).State; } if (orderProducts.ToList().Count == 0) { OrderView orderViewNone = viewModel.CreateEmptyOrderView(stores); return(View(orderViewNone)); } var orders = DbManipulation.GetOrdersFromOrderProducts(_db, orderProducts); OrderView orderView = viewModel.CreateOrderView(orders, stores); return(View(orderView)); }
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 IActionResult CustomerOrders(int?id) { if (!Util.IsLoggedIn(_cache)) { return(RedirectToAction("Login", "Customer")); } ViewData["CustomerOrders"] = "active"; ViewModel viewModel = new ViewModel(); var orderProducts = DbManipulation.GetCustomerOrderProducts(_db, id); var customers = DbManipulation.GetCustomers(_db).ToList(); if (id == 0 || id == null) { ViewData["CurrentCustomer"] = "none"; } else { ViewData["CurrentCustomer"] = customers.FirstOrDefault(c => c.CustomerId == id).UserName; } if (orderProducts.ToList().Count == 0) { OrderView orderViewNone = viewModel.CreateEmptyOrderView(customers); return(View("CustomerOrders", orderViewNone)); } List <Order> orders = DbManipulation.GetOrdersFromOrderProducts(_db, orderProducts); OrderView orderView = viewModel.CreateOrderView(orders, customers); return(View("CustomerOrders", orderView)); }
public IActionResult Details(int?id) { if (!Util.IsLoggedIn(_cache)) { return(RedirectToAction("Login", "Customer")); } if (id == null) { return(NotFound()); } Inventory inv = DbManipulation.GetInventoryOfStoreProduct(_db, (int)_cache.Get("StoreId"), id); Product prod = DbManipulation.GetProduct(_db, id); if (prod == null) { return(NotFound()); } ViewModel viewModel = new ViewModel(); List <ShoppingCart> shoppingCartInvs = DbManipulation.GetInventoryOfShoppingCart(shoppingCartProducts, (int)_cache.Get("StoreId"), id); ProductView productView = viewModel.CreateProductView(shoppingCartInvs, inv, prod); return(View(productView)); }
public void CreateShoppingCartHasCorrectInventoryAmount() { var options = new DbContextOptionsBuilder <BookopolisDbContext>() .UseInMemoryDatabase(databaseName: "CreateShoppingCartHasCorrectInventoryAmount") .Options; using (var context = new BookopolisDbContext(options)) { DbManipulation.SeedDb(context); ProductView productView = new ProductView() { ProductViewId = 1, Title = "Catch-22", Author = "Joseph Heller", Description = "Catch-22 is a satirical war novel by American author Joseph Heller.", Price = 12.50, Amount = 2, ProductId = 1, IsInCart = true, }; ViewModel viewModel = new ViewModel(); ShoppingCart shoppingCart = viewModel.CreateShoppingCart(productView, 1, "Missouri"); Assert.Equal(1, shoppingCart.StockAmount); Assert.Equal("Missouri", shoppingCart.State); } }
public IActionResult Index() { if (!DbManipulation.IsSeeded(_db)) { DbManipulation.SeedDb(_db); } ViewData["IsLoggedIn"] = "false"; return(View("Index")); }
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 IsSeededReturnsFalseWhenEmpty() { var options = new DbContextOptionsBuilder <BookopolisDbContext>() .UseInMemoryDatabase(databaseName: "IsSeededReturnsFalseWhenEmpty") .Options; using (var context = new BookopolisDbContext(options)) { Assert.False(DbManipulation.IsSeeded(context)); } }
public IActionResult Index() { if (!Util.IsLoggedIn(_cache)) { return(RedirectToAction("Login", "Customer")); } IEnumerable <Store> storeList = DbManipulation.GetStores(_db); return(View(storeList)); }
public void IsSeededReturnsTrueWhenSeeded() { var options = new DbContextOptionsBuilder <BookopolisDbContext>() .UseInMemoryDatabase(databaseName: "IsSeededReturnsTrueWhenSeeded") .Options; using (var context = new BookopolisDbContext(options)) { DbManipulation.SeedDb(context); Assert.True(DbManipulation.IsSeeded(context)); } }
public IActionResult StoreProducts(int?id) { if (id == null) { return(NotFound()); } if (!DbManipulation.IsStore(_db, id)) { return(NotFound()); } return(RedirectToAction("Index", "Product", new { id })); }
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); } }
public void IsStoreIsInRange() { var options = new DbContextOptionsBuilder <BookopolisDbContext>() .UseInMemoryDatabase(databaseName: "IsStoreIsInRange") .Options; using (var context = new BookopolisDbContext(options)) { DbManipulation.SeedDb(context); Assert.InRange(4, 1, 5); Assert.False(DbManipulation.IsStore(context, 5)); Assert.True(DbManipulation.IsStore(context, 4)); } }
public void SeedDbAddsAllData() { var options = new DbContextOptionsBuilder <BookopolisDbContext>() .UseInMemoryDatabase(databaseName: "SeedDbAddsAllData") .Options; using (var context = new BookopolisDbContext(options)) { DbManipulation.SeedDb(context); SeedData seedData = new SeedData(); Assert.Equal(seedData.Products.Count, context.Products.Count()); Assert.Equal(seedData.Stores.Count, context.Stores.Count()); } }
public void GetInventoriesReturnsAllInventories() { var options = new DbContextOptionsBuilder <BookopolisDbContext>() .UseInMemoryDatabase(databaseName: "GetInventoriesReturnsAllInventories") .Options; using (var context = new BookopolisDbContext(options)) { DbManipulation.SeedDb(context); IEnumerable <Inventory> inventories = DbManipulation.GetInventories(context); List <Inventory> inventoriesList = inventories.ToList(); Assert.InRange(inventoriesList.Count, 1, inventoriesList.Count + 1); } }
public void GetStoreReturnsCorrectStore() { var options = new DbContextOptionsBuilder <BookopolisDbContext>() .UseInMemoryDatabase(databaseName: "GetStoreReturnsCorrectStore") .Options; using (var context = new BookopolisDbContext(options)) { DbManipulation.SeedDb(context); Store store = DbManipulation.GetStore(context, 2); Assert.IsType <Store>(store); Assert.Equal(2, store.StoreId); Assert.NotEqual(3, store.StoreId); } }
public void GetProductReturnsCorrectProduct() { var options = new DbContextOptionsBuilder <BookopolisDbContext>() .UseInMemoryDatabase(databaseName: "GetProductReturnsCorrectProduct") .Options; using (var context = new BookopolisDbContext(options)) { DbManipulation.SeedDb(context); Product product = DbManipulation.GetProduct(context, 7); Assert.IsType <Product>(product); Assert.Equal(7, product.ProductId); Assert.NotEqual(3, product.ProductId); } }
public void GetInventoriesOfStoreReturnsCorrectInventories() { var options = new DbContextOptionsBuilder <BookopolisDbContext>() .UseInMemoryDatabase(databaseName: "GetInventoriesOfStoreReturnsCorrectInventories") .Options; using (var context = new BookopolisDbContext(options)) { DbManipulation.SeedDb(context); IEnumerable <Inventory> inventories = DbManipulation.GetInventoriesOfStore(context, 3); int count = inventories.ToList().Select(inv => inv.StoreId).Count(); Assert.Equal(context.Products.Count(), count); } }
public void CreateProductViewHasCorrectInventoryAmount() { var options = new DbContextOptionsBuilder <BookopolisDbContext>() .UseInMemoryDatabase(databaseName: "CreateProductViewHasCorrectInventoryAmount") .Options; using (var context = new BookopolisDbContext(options)) { DbManipulation.SeedDb(context); Inventory inv = DbManipulation.GetInventoryOfStoreProduct(context, 1, 3); Product prod = DbManipulation.GetProduct(context, 3); List <ShoppingCart> shoppingCartProducts = new List <ShoppingCart>() { new ShoppingCart() { ShoppingCartId = 1, StoreId = 1, ProductId = 3, StockAmount = 2 }, new ShoppingCart() { ShoppingCartId = 2, StoreId = 1, ProductId = 3, StockAmount = 1 }, new ShoppingCart() { ShoppingCartId = 3, StoreId = 1, ProductId = 3, StockAmount = 0 }, }; List <ShoppingCart> shoppingCartInvs = DbManipulation.GetInventoryOfShoppingCart(shoppingCartProducts, 1, 3); ViewModel viewModel = new ViewModel(); ProductView productView = viewModel.CreateProductView(shoppingCartInvs, inv, prod); Assert.Equal(0, productView.Amount); } }
public IActionResult AddToCart(ProductView p) { int id = (int)_cache.Get("StoreId"); Store store = (Store)_cache.Get("Store"); ViewModel viewModel = new ViewModel(); ShoppingCart shoppingCart = viewModel.CreateShoppingCart(p, id, store.State); shoppingCart.Inventory = DbManipulation.GetInventoryOfStoreProduct(_db, shoppingCart.StoreId, shoppingCart.ProductId); shoppingCartProducts.Add(shoppingCart); _cache.Set("shoppingCart", shoppingCartProducts); return(RedirectToAction("Index", "Product", new { id })); }
public IActionResult MyOrders() { if (!Util.IsLoggedIn(_cache)) { return(RedirectToAction("Login", "Customer")); } ViewData["MyOrders"] = "active"; ViewModel viewModel = new ViewModel(); Customer tempCust = (Customer)_cache.Get("LoggedInCustomer"); IEnumerable <OrderProduct> orderProducts = DbManipulation.GetCustomerOrderProducts(_db, tempCust.CustomerId); List <Order> orders = DbManipulation.GetOrdersFromOrderProducts(_db, orderProducts); OrderView orderView = viewModel.CreateOrderView(orders); return(View(orderView)); }
public void GetInventoryOfStoreProductReturnsCorrectInventory() { var options = new DbContextOptionsBuilder <BookopolisDbContext>() .UseInMemoryDatabase(databaseName: "GetInventoryOfStoreProductReturnsCorrectInventory") .Options; using (var context = new BookopolisDbContext(options)) { DbManipulation.SeedDb(context); Inventory inventory1 = DbManipulation.GetInventoryOfStoreProduct(context, 4, 2); Inventory expectedInv1 = context.Inventories.FirstOrDefault(inv => inv.StoreId == 4 && inv.ProductId == 2); Inventory inventory2 = DbManipulation.GetInventoryOfStoreProduct(context, 4, 2); Inventory expectedInv2 = context.Inventories.FirstOrDefault(inv => inv.StoreId == 3 && inv.ProductId == 2); Assert.Equal(expectedInv1, inventory1); Assert.NotEqual(expectedInv2, inventory2); } }
public void SetShoppingCartStockSetsCorrectStock() { var options = new DbContextOptionsBuilder <BookopolisDbContext>() .UseInMemoryDatabase(databaseName: "SetShoppingCartStockSetsCorrectStock") .Options; using (var context = new BookopolisDbContext(options)) { DbManipulation.SeedDb(context); List <ShoppingCart> shoppingCartProducts = new List <ShoppingCart>() { new ShoppingCart() { Inventory = new Inventory() { InventoryId = 1 }, StockAmount = 0 }, new ShoppingCart() { Inventory = new Inventory() { InventoryId = 2 }, StockAmount = 1 } }; List <Inventory> inventories = DbManipulation.GetInventoriesOfStore(context, 1).OrderBy(pid => pid.ProductId).ToList(); DbManipulation.SetShoppingCartStock(shoppingCartProducts, inventories); Inventory correctStockAmount1 = inventories.FirstOrDefault(inv => inv.InventoryId == 1); Inventory correctStockAmount2 = inventories.FirstOrDefault(inv => inv.InventoryId == 2); Assert.Equal(0, correctStockAmount1.Amount); Assert.Equal(1, correctStockAmount2.Amount); } }
public IActionResult PlaceOrder([Bind("StreetAddress,Country,City,State,ZIP")] CustomerAddress customerAddress) { Customer tempCust = (Customer)_cache.Get("LoggedInCustomer"); Customer customer = DbManipulation.GetCustomer(_db, tempCust.CustomerId); List <CustomerAddress> customerAddresses = DbManipulation.GetCustomerAddresses(_db, tempCust.CustomerId).ToList(); if (customerAddresses.Count > 0) { customerAddress = Util.CheckForRepeatAddress(customerAddresses, customerAddress); } Dictionary <int, int> myDict = Util.GetShoppingCartInventoryAmounts(shoppingCart); DbManipulation.UpdateInventoryAmounts(_db, myDict); Order order = new Order(); order.TimeOfOrder = DateTime.Now; order.OrderProducts = Util.CreateOrderProducts(shoppingCart, customer, customerAddress); order.Total = shoppingCart.Sum(sh => sh.Price); List <Order> orders = new List <Order>(); orders.Add(order); customerAddresses.Add(customerAddress); //add new address to customer customer.CustomerAddresses = customerAddresses; _db.Orders.Add(order); _db.SaveChanges(); _cache.Set("shoppingCart", new List <ShoppingCart>()); shoppingCart = new List <ShoppingCart>(); return(RedirectToAction("MyOrders", "Order")); }