public void GetsAllLocations() { //Arrange var options = BuildInMemoryDb("GetsAllLocations"); //Act using (var context = new P0DbContext(options)) { var store = new Store { Location = "Location1" }; context.Add(store); store = new Store { Location = "Location2" }; context.Add(store); store = new Store { Location = "Location3" }; context.Add(store); context.SaveChanges(); } //Assert using (var context = new P0DbContext(options)) { var backend = new StoreBackend(context); var stores = backend.GetAllLocations(); Assert.Equal(3, stores.Count); } }
public CustomerInfo AddNewCustomer(string fName, string lName, string email) { email = email.ToLower(); var customer = new Customer(fName, lName, email); db.Add(customer); db.SaveChanges(); return(new CustomerInfo(customer.CustomerId, fName, lName, email)); }
public void addSamples() { using (P0DbContext db = new P0DbContext()){ db.Add(new Store { Location = "Seattle" }); db.Add(new Store { Location = "Los Santos" }); db.Add(new Store { Location = "Velen" }); db.SaveChanges(); db.Add(new Product { Name = "SampleProduct11", StoreID = 1, Inventory = 5, Price = 2.50 }); db.Add(new Product { Name = "SampleProduct12", StoreID = 1, Inventory = 10, Price = 5.00 }); db.Add(new Product { Name = "SampleProduct21", StoreID = 2, Inventory = 15, Price = 10.00 }); db.Add(new Product { Name = "SampleProduct22", StoreID = 2, Inventory = 20, Price = 20.00 }); db.Add(new Product { Name = "SampleProduct31", StoreID = 3, Inventory = 25, Price = 50.00 }); db.Add(new Product { Name = "SampleProduct32", StoreID = 3, Inventory = 30, Price = 100.00 }); db.SaveChanges(); } }
public void GetsCustomerByEmail() { //Arrange var options = BuildInMemoryDb("GetsCustomer"); string fName = "Bob", lName = "Dole", email = "*****@*****.**"; //Act using (var context = new P0DbContext(options)) { var customer = new Customer { FirstName = fName, LastName = lName, Email = email }; context.Add(customer); context.SaveChanges(); } //Assert using (var context = new P0DbContext(options)) { var backend = new StoreBackend(context); var customerInfo = backend.GetCustomerInfo(email); Assert.Equal(fName, customerInfo.FirstName); Assert.Equal(lName, customerInfo.LastName); Assert.Equal(email, customerInfo.Email); } }
public void newCustomer() { using (P0DbContext db = new P0DbContext()) { try { Console.WriteLine("Please enter First and Last Name with space seperating them."); string input = Console.ReadLine(); string[] name = input.Split(' '); Console.WriteLine("Please enter a valid phone number"); input = Console.ReadLine(); int.TryParse(input, out int result); Customer newCustomer = new Customer(); newCustomer.FirstName = name[0]; newCustomer.LastName = name[1]; newCustomer.PhoneNumber = result; db.Add <Customer>(newCustomer); db.SaveChanges(); Console.WriteLine("Customer added. Press Enter to return to main menu."); Console.ReadLine(); } catch (Exception e) { Console.WriteLine($"Exception occurred: {e}"); Console.ReadLine(); return; } } }
public void GetsAllOrdersForCustomer() { //Arrange var options = BuildInMemoryDb("GetsCustomersOrders"); //Act using (var context = new P0DbContext(options)) { CreateOneCustomer(context); CreateTwoproducts(context); var store = new Store { StoreId = 1, Location = "Location1" }; context.Add(store); context.SaveChanges(); var order = new Order { CusomerId = 1, OrderDateTime = DateTime.Now, OrderId = 1, StoreId = 1, }; context.Add(order); order = new Order { CusomerId = 1, OrderDateTime = DateTime.Now, OrderId = 2, StoreId = 1, }; context.Add(order); context.SaveChanges(); } //Assert using (var context = new P0DbContext(options)) { var backend = new StoreBackend(context); var orders = backend.GetCustomerOrderHistory(1); Assert.Equal(2, orders.Count); } }
public void CancelsOrderOnNegativeInventory() { //Arrange var options = BuildInMemoryDb("CancelsOrder"); //Act using (var context = new P0DbContext(options)) { CreateOneCustomer(context); CreateTwoproducts(context); var store = new Store { StoreId = 1, Location = "Location1", AvailableProducts = new List <Inventory> { new Inventory { ProductId = 1, StoreId = 1, Quantity = 10 }, new Inventory { ProductId = 2, StoreId = 1, Quantity = 50 } } }; context.Add(store); context.SaveChanges(); try { var backend = new StoreBackend(context); var prods = new List <ProductQuantity>() { new ProductQuantity() { ProductId = 1, Quantity = 12 } }; backend.PlaceNewOrder(1, 1, prods); } catch { } } //Assert using (var context = new P0DbContext(options)) { var orders = (from o in context.Orders select o).ToList(); Assert.Empty(orders); } }
public void DecrementsInventoryOnOrder() { //Arrange var options = BuildInMemoryDb("DecrementsInventory"); int orderId; //Act using (var context = new P0DbContext(options)) { CreateOneCustomer(context); CreateTwoproducts(context); var store = new Store { StoreId = 1, Location = "Location1", AvailableProducts = new List <Inventory> { new Inventory { ProductId = 1, StoreId = 1, Quantity = 10 }, new Inventory { ProductId = 2, StoreId = 1, Quantity = 50 } } }; context.Add(store); context.SaveChanges(); var backend = new StoreBackend(context); var prods = new List <ProductQuantity>() { new ProductQuantity() { ProductId = 1, Quantity = 2 } }; orderId = backend.PlaceNewOrder(1, 1, prods).OrderId; } //Assert using (var context = new P0DbContext(options)) { var item = (from inv in context.StoreInventories where inv.StoreId == 1 && inv.ProductId == 1 select inv).Take(1).FirstOrDefault(); Assert.Equal(8, item.Quantity); } }
private void CreateTwoproducts(P0DbContext context) { var product = new Product { PoductId = 1, Price = 2.99, ProductDescription = "Prod1" }; context.Add(product); product = new Product { PoductId = 2, Price = 5.99, ProductDescription = "Prod2" }; context.Add(product); context.SaveChanges(); }
private void CreateOneCustomer(P0DbContext context) { var customer = new Customer { CustomerId = 1, FirstName = "Jim", LastName = "Bob", Email = "*****@*****.**" }; context.Add(customer); context.SaveChanges(); }
public void ThrowsOnNegativeInventory() { //Arrange var options = BuildInMemoryDb("ThrowsException"); //Act using (var context = new P0DbContext(options)) { CreateOneCustomer(context); CreateTwoproducts(context); var store = new Store { StoreId = 1, Location = "Location1", AvailableProducts = new List <Inventory> { new Inventory { ProductId = 1, StoreId = 1, Quantity = 10 }, new Inventory { ProductId = 2, StoreId = 1, Quantity = 50 } } }; context.Add(store); context.SaveChanges(); } //Assert using (var context = new P0DbContext(options)) { var backend = new StoreBackend(context); var prods = new List <ProductQuantity>() { new ProductQuantity() { ProductId = 1, Quantity = 12 } }; Assert.Throws <ArgumentOutOfRangeException>(() => backend.PlaceNewOrder(1, 1, prods)); } }
public void GetsCorrectInventoryCount() { //Arrange var options = BuildInMemoryDb("GetsInventoryCount"); //Act using (var context = new P0DbContext(options)) { CreateTwoproducts(context); var store = new Store { StoreId = 1, Location = "Location1", AvailableProducts = new List <Inventory> { new Inventory { ProductId = 1, StoreId = 1, Quantity = 10 }, new Inventory { ProductId = 2, StoreId = 1, Quantity = 50 } } }; context.Add(store); context.SaveChanges(); } //Assert using (var context = new P0DbContext(options)) { var backend = new StoreBackend(context); var items = backend.GetAllLocations().FirstOrDefault().AvailableProducts; Assert.Equal(2, items.Count); } }
public void newStore() { using (P0DbContext db = new P0DbContext()) { try { Console.WriteLine("Please enter a store location"); string loc = Console.ReadLine(); Store newStore = new Store(); newStore.Location = loc; db.Add <Store>(newStore); db.SaveChanges(); Console.WriteLine("Store added. Press Enter to return to main menu."); Console.ReadLine(); } catch (Exception e) { Console.WriteLine($"Exception occurred: {e}"); return; } } }
public void placeOrder() { using (P0DbContext db = new P0DbContext()){ int storeID = 0; Order newOrder = new Order(); CustomerQueries customers = new CustomerQueries(); StoreQueries stores = new StoreQueries(); #region get storeID Console.WriteLine("Please enter a StoreID for the location you would like to place your order at"); string input = Console.ReadLine(); bool invalid = true; int result; while (invalid) { if (!int.TryParse(input, out result) || !stores.existsStore(result)) { Console.WriteLine("Invalid Input, Please try again."); input = Console.ReadLine(); } else { storeID = result; invalid = false; } } #endregion #region get customerID Console.WriteLine("Please enter the CustomerID of whose placing the order"); input = Console.ReadLine(); invalid = true; while (invalid) { if (!int.TryParse(input, out result) || !customers.existsCustomer(result)) { Console.WriteLine("Invalid Input, Please try again."); input = Console.ReadLine(); } else { newOrder.CustomerID = result; invalid = false; } } #endregion #region display products ProductQueries products = new ProductQueries(); var productList = products.getProducts(storeID); Console.Clear(); Console.WriteLine("ID\tStore\t\tName\t\tInventory\tPrice"); foreach (var p in productList) { Console.WriteLine($"{p.ProductID}\t{p.Store.Location}\t{p.Name}" + $"\t{p.Inventory}\t\t{p.Price}"); } #endregion bool ordering = true; int time = 0; while (ordering) { #region productID Console.WriteLine("Please enter the productID what you want"); input = Console.ReadLine(); invalid = true; while (invalid) { if (!int.TryParse(input, out result) || !products.existsProduct(result)) { Console.WriteLine("Invalid Input, Please try again."); input = Console.ReadLine(); } else { newOrder.ProductID = result; invalid = false; } } #endregion #region count Console.WriteLine("Please enter the amount that you want"); input = Console.ReadLine(); invalid = true; while (invalid) { if (!int.TryParse(input, out result) || !products.checkCount(newOrder.ProductID, result)) { Console.WriteLine("Invalid Input, Please try again."); input = Console.ReadLine(); } else { newOrder.Count = result; invalid = false; } } #endregion #region keep ordering do { Console.WriteLine("Would you like to keep ordering? Yes : No"); input = Console.ReadLine(); } while (!(input == "Yes" || input == "No")); if (input == "Yes") { ordering = true; } else { ordering = false; } time++; if (time == 1) { newOrder.Time = DateTime.Now; } db.Add <Order>(newOrder); db.SaveChanges(); StoreQueries update = new StoreQueries(); update.placeOrder(newOrder); newOrder.OrderID++; #endregion } Console.WriteLine("Press enter to return to the menu"); Console.ReadLine(); } }
public void AddsOrderToDb() { //Arrange var options = BuildInMemoryDb("AddsOrderToDb"); int orderId; //Act using (var context = new P0DbContext(options)) { CreateOneCustomer(context); CreateTwoproducts(context); var store = new Store { StoreId = 1, Location = "Location1", AvailableProducts = new List <Inventory> { new Inventory { ProductId = 1, StoreId = 1, Quantity = 10 }, new Inventory { ProductId = 2, StoreId = 1, Quantity = 50 } } }; context.Add(store); context.SaveChanges(); var backend = new StoreBackend(context); var prods = new List <ProductQuantity>() { new ProductQuantity() { ProductId = 1, Quantity = 2 }, new ProductQuantity() { ProductId = 2, Quantity = 5 } }; orderId = backend.PlaceNewOrder(1, 1, prods).OrderId; } //Assert using (var context = new P0DbContext(options)) { var orders = from ord in context.Orders where ord.OrderId == orderId select ord; Assert.Single(orders); } }