示例#1
0
        public async Task TestIfIsCartEmptyOrNonExistingReturnsFalse(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");

            Assert.False(await shopService.IsCartEmptyOrNonExistingAsync(username));
        }
示例#2
0
        public async Task TestIfIsCartEmptyOrNonExistingReturnsTrue(string username)
        {
            //Arrange
            var context        = PCHUBDbContextInMemoryInitializer.InitializeContext();
            var productService = new ProductServices(context);
            var shopService    = new ShopServices(context, productService);

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

            await context.SaveChangesAsync();

            Assert.True(await shopService.IsCartEmptyOrNonExistingAsync(username));
        }