public async void CanDeleteBasketProduct() { DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("GetBasektProduct").Options; using (NurseryDbContext context = new NurseryDbContext(options)) { InventoryService inventoryService = new InventoryService(context); BasketProductService basketProductService = new BasketProductService(context); BasketService basketService = new BasketService(context); Basket basket = new Basket(); await basketService.CreateBasketAsync(basket); Product product = new Product(); await inventoryService.CreateProduct(product); await basketProductService.AddBasketProduct(product.ID, 3, basket.ID); var basketProduct = await basketProductService.GetBasketProductByID(basket.ID, product.ID); await basketProductService.DeleteBasketProductByID(basket.ID, product.ID); var actual = await basketProductService.GetBasketProductByID(basket.ID, product.ID); Assert.Null(actual); } }
public async void CanCreateBasket() { DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("test").Options; using (NurseryDbContext context = new NurseryDbContext(options)) { Basket basket = new Basket(); BasketService basketService = new BasketService(context); await basketService.CreateBasketAsync(basket); var expected = await context.Baskets.FirstOrDefaultAsync(b => b.ID == basket.ID); Assert.Equal(expected, basket); } }
public async void CanGetBasket() { DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("test").Options; using (NurseryDbContext context = new NurseryDbContext(options)) { Basket basket = new Basket(); basket.UserID = "userString"; BasketService basketService = new BasketService(context); await basketService.CreateBasketAsync(basket); var expected = await basketService.GetBasketByUserId("userString"); Assert.Equal(expected, basket); } }
public async void CanUpdateBasket() { DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("test").Options; using (NurseryDbContext context = new NurseryDbContext(options)) { Basket basket = new Basket(); basket.UserID = "userString"; BasketService basketService = new BasketService(context); await basketService.CreateBasketAsync(basket); basket.UserID = "new string"; await basketService.UpdateBasketAsync(basket); Assert.Equal("new string", basket.UserID); } }
public async void CanCreateBasketProduct() { DbContextOptions <NurseryDbContext> options = new DbContextOptionsBuilder <NurseryDbContext>().UseInMemoryDatabase("test").Options; using (NurseryDbContext context = new NurseryDbContext(options)) { InventoryService inventoryService = new InventoryService(context); BasketProductService basketProductService = new BasketProductService(context); BasketService basketService = new BasketService(context); Basket basket = new Basket(); await basketService.CreateBasketAsync(basket); Product product = new Product(); await inventoryService.CreateProduct(product); await basketProductService.AddBasketProduct(product.ID, 3, basket.ID); var expected = await context.BasketProducts.FirstOrDefaultAsync(p => p.BasketID == basket.ID && p.ProductID == product.ID); Assert.NotNull(expected); } }