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)); }
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); }
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"))); }
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)); }
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"); }); }
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")); }
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); }
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); }
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"))); }
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()); }