public async Task DeletesProductFromDb() { //Arrange - create an object to configure your inmemory DB. var options = new DbContextOptionsBuilder <MSDbContext>() .UseInMemoryDatabase(databaseName: "DeletesProductFromDb") .Options; //Act - send in the configure object to the DbContext constructor to be used in configuring the DbContext using (var db = new MSDbContext(options)) { Product product = new Product { Id = 26, Name = "drum", }; db.Add(product); await db.SaveChangesAsync(); db.Remove(product); await db.SaveChangesAsync(); } //Assert using (var context = new MSDbContext(options)) { Assert.Equal(0, context.Products.Count()); } }
public async Task DeletesOrderFromDb() { //Arrange - create an object to configure your inmemory DB. var options = new DbContextOptionsBuilder <MSDbContext>() .UseInMemoryDatabase(databaseName: "DeletesOrderFromDb") .Options; //Act - send in the configure object to the DbContext constructor to be used in configuring the DbContext using (var db = new MSDbContext(options)) { Order order = new Order { Id = 43, StoreId = 4 }; db.Add(order); await db.SaveChangesAsync(); db.Remove(order); await db.SaveChangesAsync(); } //Assert using (var context = new MSDbContext(options)) { Assert.Equal(0, context.Orders.Count()); } }
public async Task DeletesCustomerFromDb() { //Arrange - create an object to configure your inmemory DB. var options = new DbContextOptionsBuilder <MSDbContext>() .UseInMemoryDatabase(databaseName: "DeletesCustomerToDb") .Options; //Act - send in the configure object to the DbContext constructor to be used in configuring the DbContext using (var db = new MSDbContext(options)) { CustomerAddress customerAddress = new CustomerAddress { Id = 1, Street = "8286 Clay Ave.", City = "Spokane", State = "WA", Zip = "11111" }; Customer customer = new Customer { Id = 6, FirstName = "Maribeth", LastName = "Fontenot", Email = "*****@*****.**", PhoneNo = "1234112233", Password = "******", UserTypeId = 2, CustomerAddress = customerAddress }; db.Add(customer); await db.SaveChangesAsync(); db.Remove(customer); await db.SaveChangesAsync(); } //Assert using (var context = new MSDbContext(options)) { Assert.Equal(0, context.Customers.Count()); } }