public void AddsQuantityToInventory(int quantity) { var options = new DbContextOptionsBuilder <StoreDbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options; Inventory inventory = new Inventory(); StoreLocation store = new StoreLocation(); Product product = new Product(); using (var context = new StoreDbContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); StoreDataLayer repo = new StoreDataLayer(context); store = repo.CreateStore("TargWal", "San Diego"); product = repo.CreateProduct("name", "desc", 26.00M, false); inventory = repo.AssignInventory(product, store, quantity); } using (var context = new StoreDbContext(options)) { StoreDataLayer repo = new StoreDataLayer(context); Inventory invResult = repo.AssignInventory(product, store, 20); int result = quantity + 20; Assert.Equal(invResult.ProductQuantity, result); } }
public void CreatesNewProductEachTime(string name, string desc, decimal price, bool restricted) { var options = new DbContextOptionsBuilder <StoreDbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options; Product p = new Product(); using (var context = new StoreDbContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); StoreDataLayer repo = new StoreDataLayer(context); p = repo.CreateProduct(name, desc, price, restricted); } using (var context = new StoreDbContext(options)) { StoreDataLayer repo = new StoreDataLayer(context); Product result = repo.CreateProduct("name", "desc", 26.00M, false); Assert.NotEqual(p.ProductID, result.ProductID); } }
public void CreatesNewStoreEachTime(string name, string address) { var options = new DbContextOptionsBuilder <StoreDbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options; StoreLocation s = new StoreLocation(); using (var context = new StoreDbContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); StoreDataLayer repo = new StoreDataLayer(context); s = repo.CreateStore(name, address); } using (var context = new StoreDbContext(options)) { StoreDataLayer repo = new StoreDataLayer(context); StoreLocation result = repo.CreateStore("TargWal", "San Diego"); Assert.NotEqual(s.StoreLocationId, result.StoreLocationId); } }
public void CreateStoreSavesAndAddsProductToDb(string name, string address) { var options = new DbContextOptionsBuilder <StoreDbContext>().UseInMemoryDatabase(databaseName: "TestDb").Options; StoreLocation s = new StoreLocation(); using (var context = new StoreDbContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); StoreDataLayer repo = new StoreDataLayer(context); s = repo.CreateStore(name, address); } using (var context = new StoreDbContext(options)) { StoreDataLayer repo = new StoreDataLayer(context); StoreLocation result = repo.CreateStore(name, address); Assert.Equal(s.StoreLocationId, result.StoreLocationId); } }