示例#1
0
        public async Task TestIfCheckoutSignedInUserDetailsNotPresentReturnsFalse(string username, string product1,
                                                                                  string product2, string product3)
        {
            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        = product1,
                Price     = 300,
                Title     = "Test Product",
                IsDeleted = false,
                CreatedOn = DateTime.Now,
            });


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

            productsInsideUserCart.Add(new Product
            {
                Id        = product3,
                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, product1);

            await shopService.BuyProductAsync(username, product2);

            await shopService.BuyProductAsync(username, product3);

            var shippingCompany = ShippingCompany.Econt;

            Assert.False(await shopService.CheckoutSignedInUserAsync(username, shippingCompany));
        }
示例#2
0
        public async Task TestIfReturnsCorrectNumberOfProducts(string username)
        {
            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 numberOfProducts = await shopService.GetNumberOfProductsAsync(username);

            Assert.Equal(3, numberOfProducts);
        }
示例#3
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")));
        }
示例#4
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));
        }
示例#5
0
        public async Task TestIfWhenInvalidUserOrCart()
        {
            // 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.SaveChangesAsync();

            await shopService.BuyProductAsync(null, null);

            await shopService.BuyProductAsync("asdasd", null);

            await Assert.ThrowsAsync <NullReferenceException>(async() =>
            {
                await shopService.BuyProductAsync("asdasd", "Product1");
            });
        }
示例#6
0
        public async Task TestIfGetLastCheckoutDetailsAsyncReturnsCorrectModel(string username, string product1,
                                                                               string product2, string product3)
        {
            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          = product1,
                Price       = 300,
                Title       = "Test Product",
                IsDeleted   = false,
                CreatedOn   = DateTime.Now,
                MainPicture = new Picture
                {
                    Url = "dsadasdasdasdasd",
                }
            });


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

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

            await context.Products.AddRangeAsync(productsInsideUserCart);

            var user = new User
            {
                UserName      = username,
                Email         = "*****@*****.**",
                LastLoginDate = DateTime.UtcNow,
                FirstName     = "Sdasdsd",
                LastName      = "Adsdfsdf",
                PhoneNumber   = "231233423",
                Address       = "dasdasdasdasdasd",
                City          = "Sofia",
            };

            await context.Users.AddAsync(user);

            await context.SaveChangesAsync();

            await shopService.BuyProductAsync(username, product1);

            await shopService.BuyProductAsync(username, product2);

            await shopService.BuyProductAsync(username, product3);

            var shippingCompany = ShippingCompany.Econt;

            await shopService.CheckoutSignedInUserAsync(username, shippingCompany);

            //Assert
            var result = await shopService.GetLastCheckoutDetailsAsync(username);

            Assert.Equal(user.FirstName, result.FirstName);
            Assert.Equal(user.LastName, result.LastName);
            Assert.Equal(user.Address, result.Address);
            Assert.Equal(user.City, result.City);

            Assert.True(result.Products.Any(x => x.Title == "Test Product2"));
            Assert.True(result.Products.Any(x => x.Title == "Test Product1"));
            Assert.True(result.Products.Any(x => x.Title == "Test Product"));
        }
示例#7
0
        public async Task TestIfRemoveProductFromCartAsyncRemovesProductsFromCart(string username, string product1,
                                                                                  string product2, string product3)
        {
            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        = product1,
                Price     = 300,
                Title     = "Test Product",
                IsDeleted = false,
                CreatedOn = DateTime.Now,
            });


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

            productsInsideUserCart.Add(new Product
            {
                Id        = product3,
                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, product1);

            await shopService.BuyProductAsync(username, product2);

            await shopService.BuyProductAsync(username, product3);

            await shopService.RemoveProductFromCartAsync(username, product1);

            var user = await context.Users.FirstOrDefaultAsync(x => x.UserName == username);

            var cartProductsCount = user.Cart.ProductCarts.Count();

            Assert.Equal(2, cartProductsCount);
        }
示例#8
0
        public async Task TestIfProductQuantityIncreases(string username, int quantity)
        {
            //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");

            await shopService.IncreaseProductQuantityAsync(username, "Product1", quantity);

            var user = await context.Users.FirstOrDefaultAsync(x => x.UserName == username);

            var productCart = user.Cart.ProductCarts.FirstOrDefault(x => x.Product.Id == "Product1");

            Assert.Equal(productCart.Quantity, quantity);
        }
示例#9
0
        public async Task TestIfUserShoppingCartHasChanged()
        {
            // 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      = "******",
                Email         = "*****@*****.**",
                LastLoginDate = DateTime.UtcNow,
            });

            await context.SaveChangesAsync();

            //Act
            await shopService.BuyProductAsync("Test1", "Product2");

            //Assert

            var user = await context.Users.FirstOrDefaultAsync(x => x.UserName == "Test1");

            var cart = user.Cart;

            Assert.True(cart.ProductCarts.Count == 1);

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

            var user1 = await context.Users.FirstOrDefaultAsync(x => x.UserName == "Test1");

            var cart1 = user.Cart;

            Assert.True(cart1.ProductCarts.Count == 2);

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

            var user2 = await context.Users.FirstOrDefaultAsync(x => x.UserName == "Test1");

            var cart2 = user.Cart;

            Assert.True(cart2.ProductCarts.Count == 3);

            Assert.True(cart2.ProductCarts.Any(x => x.Product.Id.Contains("Product")));
        }
示例#10
0
        public async Task TestIfGetAllShipmentsReturnsCorrectResult(string username)
        {
            var context            = PCHUBDbContextInMemoryInitializer.InitializeContext();
            var productService     = new ProductServices(context);
            var userProfileService = new UserProfileServices(context, TestUserManager <User>(), productService);
            var shopService        = new ShopServices(context, productService);

            var productsInsideUserCart = new List <Product>();

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


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

            productsInsideUserCart.Add(new Product
            {
                Id        = "TestProduct3",
                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,
                FirstName     = "Sdasdsd",
                LastName      = "Adsdfsdf",
                PhoneNumber   = "231233423",
                Address       = "dasdasdasdasdasd",
                City          = "Sofia",
            });

            await context.SaveChangesAsync();

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

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

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


            var shippingCompany = ShippingCompany.Econt;

            Assert.True(await shopService.CheckoutSignedInUserAsync(username, shippingCompany));

            var result = await userProfileService.GetAllShipmentsAsync(username);

            Assert.Equal(3, result.Count());
        }