public async void DeleteBasketItemTest() { DbContextOptions <CerealDBContext> options = new DbContextOptionsBuilder <CerealDBContext>() .UseInMemoryDatabase("Baskets") .Options; using (CerealDBContext context = new CerealDBContext(options)) { //CREATE BasketItems basket = new BasketItems(); basket.ID = 4; basket.ProductID = 2; basket.Quantity = 2; basket.UserID = "userid"; basket.Purchased = false; context.BasketItems.Add(basket); await context.SaveChangesAsync(); //READ var myBasket = await context.BasketItems.FirstOrDefaultAsync(r => r.ID == basket.ID); //DELETE context.BasketItems.Remove(myBasket); context.SaveChanges(); var deletedBasketItems = await context.BasketItems.FirstOrDefaultAsync(r => r.ID == myBasket.ID); Assert.True(deletedBasketItems == null); } }
public async void UpdateBasketItemTest() { DbContextOptions <CerealDBContext> options = new DbContextOptionsBuilder <CerealDBContext>() .UseInMemoryDatabase("Baskets") .Options; using (CerealDBContext context = new CerealDBContext(options)) { //CREATE BasketItems basket = new BasketItems(); basket.ID = 3; basket.ProductID = 2; basket.Quantity = 2; basket.UserID = "userid"; basket.Purchased = false; context.BasketItems.Add(basket); await context.SaveChangesAsync(); //READ var myBasket = await context.BasketItems.FirstOrDefaultAsync(r => r.ID == basket.ID); //UPDATE myBasket.Quantity = 4; context.Update(myBasket); context.SaveChanges(); var newBasket = await context.BasketItems.FirstOrDefaultAsync(r => r.ID == myBasket.ID); Assert.Equal(4, newBasket.Quantity); } }
public async void CreateBasketItemTest() { DbContextOptions <CerealDBContext> options = new DbContextOptionsBuilder <CerealDBContext>() .UseInMemoryDatabase("Baskets") .Options; using (CerealDBContext context = new CerealDBContext(options)) { //CREATE BasketItems basket = new BasketItems(); basket.ID = 1; basket.ProductID = 2; basket.Quantity = 2; basket.UserID = "userid"; basket.Purchased = false; context.BasketItems.Add(basket); await context.SaveChangesAsync(); Assert.Equal(1, basket.ID); } }
public async Task AddItem(BasketItems basketItems) { _context.BasketItems.Add(basketItems); await _context.SaveChangesAsync(); }
public async Task CreateProduct(Product product) { _context.Product.Add(product); await _context.SaveChangesAsync(); }