public void EnoughIngredientsWorks() { var options = new DbContextOptionsBuilder <_1811proj0Context>().UseInMemoryDatabase("enoughingredients_test").Options; bool order1EnoughIngredients = false; bool order2EnoughIngredients = true; bool order3EnoughIngredients = true; // Arrange using (var db = new _1811proj0Context(options)) { // Add locations to in-memory database to be referenced db.Locations.Add(new Locations { LId = 1, City = "", State = "" }); db.Locations.Add(new Locations { LId = 2, City = "", State = "" }); db.SaveChanges(); // Add user to in-memory database to be referenced db.Users.Add(new Users { UId = 1, FirstName = "", LastName = "", DefaultLocation = 1 }); db.SaveChanges(); // Add pizzas to in-memory database to be referenced db.Pizzas.Add(new Pizzas { PId = 1, Name = "", Price = 0 }); db.Pizzas.Add(new Pizzas { PId = 2, Name = "", Price = 0 }); db.SaveChanges(); // Add toppings to be referenced db.Toppings.Add(new Toppings { TId = 1, Name = "" }); db.Toppings.Add(new Toppings { TId = 2, Name = "" }); db.Toppings.Add(new Toppings { TId = 3, Name = "" }); db.Toppings.Add(new Toppings { TId = 4, Name = "" }); db.SaveChanges(); // Add toppings to pizzas db.PizzaToppings.Add(new PizzaToppings { PtId = 1, Pizza = 1, Topping = 1, Quantity = 2 }); db.PizzaToppings.Add(new PizzaToppings { PtId = 2, Pizza = 1, Topping = 2, Quantity = 2 }); db.PizzaToppings.Add(new PizzaToppings { PtId = 3, Pizza = 1, Topping = 3, Quantity = 2 }); db.PizzaToppings.Add(new PizzaToppings { PtId = 4, Pizza = 1, Topping = 4, Quantity = 2 }); db.PizzaToppings.Add(new PizzaToppings { PtId = 5, Pizza = 2, Topping = 2, Quantity = 6 }); db.PizzaToppings.Add(new PizzaToppings { PtId = 6, Pizza = 2, Topping = 4, Quantity = 6 }); db.SaveChanges(); // Add location inventories db.LocationInventory.Add(new LocationInventory { LiId = 1, Location = 1, Topping = 1, Quantity = 10 }); db.LocationInventory.Add(new LocationInventory { LiId = 2, Location = 1, Topping = 2, Quantity = 10 }); db.LocationInventory.Add(new LocationInventory { LiId = 3, Location = 1, Topping = 3, Quantity = 10 }); db.LocationInventory.Add(new LocationInventory { LiId = 4, Location = 1, Topping = 4, Quantity = 10 }); db.LocationInventory.Add(new LocationInventory { LiId = 5, Location = 2, Topping = 1, Quantity = 10 }); db.LocationInventory.Add(new LocationInventory { LiId = 6, Location = 2, Topping = 2, Quantity = 10 }); db.LocationInventory.Add(new LocationInventory { LiId = 7, Location = 2, Topping = 3, Quantity = 1 }); db.LocationInventory.Add(new LocationInventory { LiId = 8, Location = 2, Topping = 4, Quantity = 7 }); db.SaveChanges(); // Add orders to in-memory database // This one will order from a location with enough ingredients and should return valid db.Orders.Add(new Orders { OId = 1, OrderFor = 1, OrderedFrom = 1, OrderedAt = DateTime.Now, TotalPrice = 0M }); // This one will order from a location without enough ingredients and should return invalid db.Orders.Add(new Orders { OId = 2, OrderFor = 1, OrderedFrom = 2, OrderedAt = DateTime.Now, TotalPrice = 0M }); // This one will order from a location without enough ingredients for all piizas and should return invalid db.Orders.Add(new Orders { OId = 3, OrderFor = 1, OrderedFrom = 2, OrderedAt = DateTime.Now, TotalPrice = 0M }); db.SaveChanges(); // Add order entries to in-memory database db.OrderEntries.Add(new OrderEntries { OeId = 1, OnOrder = 1, Pizza = 1, Quantity = 1 }); db.OrderEntries.Add(new OrderEntries { OeId = 2, OnOrder = 2, Pizza = 1, Quantity = 1 }); db.OrderEntries.Add(new OrderEntries { OeId = 3, OnOrder = 3, Pizza = 1, Quantity = 1 }); db.OrderEntries.Add(new OrderEntries { OeId = 4, OnOrder = 3, Pizza = 2, Quantity = 1 }); db.SaveChanges(); } // Act using (var db = new _1811proj0Context(options)) { var repo = new PizzaRepository(db); order1EnoughIngredients = repo.EnoughIngredients(db.Orders.Find(1)); order2EnoughIngredients = repo.EnoughIngredients(db.Orders.Find(2)); order3EnoughIngredients = repo.EnoughIngredients(db.Orders.Find(3)); } // Assert using (var db = new _1811proj0Context(options)) { Assert.True(order1EnoughIngredients); Assert.False(order2EnoughIngredients); Assert.False(order3EnoughIngredients); } }