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 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 AddsCustomerToDb() { //Arrange var options = BuildInMemoryDb("AddsCustomer"); string fName = "Bob", lName = "Dole", email = "*****@*****.**"; CustomerInfo customerInfo = null; //Act using (var context = new P0DbContext(options)) { var backend = new StoreBackend(context); customerInfo = backend.AddNewCustomer(fName, lName, email); } //Assert using (var context = new P0DbContext(options)) { var customer = (from c in context.Customers where c.FirstName == fName && c.LastName == lName select c).Take(1).FirstOrDefault(); Assert.Equal(customer.CustomerId, customerInfo.CustomerId); Assert.Equal(fName, customer.FirstName); Assert.Equal(lName, customer.LastName); Assert.Equal(email, customer.Email); } }
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); } }
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 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 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 AdminUI() { db = new StoreBackend(); }
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); } }
public CustomerUI() { this.db = new StoreBackend(); }