Пример #1
0
        public async Task TestIfReturnsSpecificProductsForUserCart(string username)
        {
            //Arrange
            var context        = PCHUBDbContextInMemoryInitializer.InitializeContext();
            var productService = new ProductServices(context);
            var shopService    = new ShopServices(context, productService);

            var productsInsideUserCart = new List <Product>();

            productsInsideUserCart.Add(new Product
            {
                Id        = "Product",
                Price     = 300,
                Title     = "Test Product",
                IsDeleted = false,
                CreatedOn = DateTime.Now,
            });


            productsInsideUserCart.Add(new Product
            {
                Id        = "Product1",
                Price     = 300,
                Title     = "Test Product1",
                IsDeleted = false,
                CreatedOn = DateTime.Now,
            });

            productsInsideUserCart.Add(new Product
            {
                Id        = "Product2",
                Price     = 300,
                Title     = "Test Product2",
                IsDeleted = false,
                CreatedOn = DateTime.Now,
            });

            await context.Products.AddRangeAsync(productsInsideUserCart);

            await context.Users.AddAsync(new User
            {
                UserName      = username,
                Email         = "*****@*****.**",
                LastLoginDate = DateTime.UtcNow,
            });

            await context.SaveChangesAsync();

            await shopService.BuyProductAsync(username, "Product2");

            await shopService.BuyProductAsync(username, "Product");

            await shopService.BuyProductAsync(username, "Product1");

            var result = await shopService.GetAllCartProductsAsync(username);

            Assert.Equal(3, result.Count);
            Assert.True(result.Any(x => x.Product.Title.Contains("Test Product")));
        }
Пример #2
0
        public async Task TestIfThrowsErrorForInvalidUser(string username)
        {
            //Arrange
            var context        = PCHUBDbContextInMemoryInitializer.InitializeContext();
            var productService = new ProductServices(context);
            var shopService    = new ShopServices(context, productService);

            await Assert.ThrowsAsync <NullReferenceException>(async() =>
            {
                await shopService.GetAllCartProductsAsync(username);
            });
        }