public void TestTakeFromInventory() { //Arrange var options = new DbContextOptionsBuilder <Store_DbContext>() .UseInMemoryDatabase(databaseName: "TestStore") .Options; Product testProd = new Product(); Inventory testInv = new Inventory(); Order testOrder = new Order(); String prodName = "Device"; int num = 9; //Act using (var context = new Store_DbContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); StoreRepositoryLayer repo = new StoreRepositoryLayer(context); testProd.Description = prodName; testInv.inventoryProduct = testProd; repo.TakeFromInventoryAddToOrder(testInv, num, testOrder); context.SaveChanges(); } //Assert using (var context = new Store_DbContext(options)) { Assert.Equal(num, testOrder.orderQuantity); } }
public void TestInvalidQuantity(int value) { //Arrange var options = new DbContextOptionsBuilder <Store_DbContext>() .UseInMemoryDatabase(databaseName: "TestStore") .Options; Product testProd = new Product(); Inventory testInv = new Inventory(); String prodName = "Corn"; bool canCheckout; //Act using (var context = new Store_DbContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); StoreRepositoryLayer repo = new StoreRepositoryLayer(context); testProd.Description = prodName; testInv.inventoryProduct = testProd; canCheckout = repo.CheckIfQuantityAvailable(testInv, value); context.SaveChanges(); } //Assert using (var context = new Store_DbContext(options)) { Assert.False(canCheckout); } }