Пример #1
0
        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);
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        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);
            }
        }