public IActionResult MostExpensive() { var list = new ShopServices(); var mostExpensive = list.ShopItems.OrderByDescending(i => i.Price).Select(i => i.Name).FirstOrDefault(); return(View("MostExpensive", mostExpensive)); }
public IActionResult GetByUserId(int id) { ShopServices shs = new ShopServices(_config, _logger); var model = shs.GetByUserId(id); return(Ok(new ResponseResult(200, StatusMessage.Completed.ToString(), "", model))); }
public IActionResult AverageStock() { var list = new ShopServices(); var averageStock = list.ShopItems.Average(i => i.Quantity); return(View("AverageStock", averageStock)); }
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 IActionResult GetAll() { _logger.LogInformation("Shop/GetAll"); ShopServices shs = new ShopServices(_config, _logger); var list = shs.GetAll(); return(Ok(new ResponseResult(200, StatusMessage.Completed.ToString(), "", list))); }
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 ActionResult ManageProducts() { //get all product list and return that product list to manage product view ProductViewModel productModel = new ProductViewModel(); ShopServices service = new ShopServices(); //get product list from database productModel.ProductList = service.GetProductDetails(); return(View(productModel)); }
public ActionResult ManageOrders() { //get all order list and return that order list to manage order view OrderViewModel productModel = new OrderViewModel(); ShopServices service = new ShopServices(); //get order list from database productModel.OrderList = service.GetOrders(); return(View(productModel)); }
public async Task TestIfGetLastCheckoutDetailsAsyncThrowsErrorForInvalidUser(string username) { var context = PCHUBDbContextInMemoryInitializer.InitializeContext(); var productService = new ProductServices(context); var shopService = new ShopServices(context, productService); await Assert.ThrowsAsync <NullReferenceException>(async() => { await shopService.GetLastCheckoutDetailsAsync(username); }); }
public async Task TestIfCheckoutSignedInUserThrowsWhenInvalidUser() { var context = PCHUBDbContextInMemoryInitializer.InitializeContext(); var productService = new ProductServices(context); var shopService = new ShopServices(context, productService); var shippingCompany = ShippingCompany.Econt; await Assert.ThrowsAsync <NullReferenceException>(async() => { await shopService.CheckoutSignedInUserAsync(null, shippingCompany); }); }
public async Task AddNewShopServiceAsync(ShopServicesParam param) { var entity = new ShopServices() { ServicesName = param.ServicesName, PriceService = param.PriceService, DescriptionService = param.DescriptionService, ShopId = 1 }; await shopServicesRepository.AddAsync(entity); }
public async Task <IActionResult> AddOrUpdate(int?id, string name, string address, string phoneNo, string latitude, string longitude, bool?isActive, string updatedBy, IFormFile file) { _logger.LogInformation("Shop/AddOrUpdate"); _logger.LogInformation("id: {0} name: {1} file: {2} type: {3} len: {4}", id, name, file.FileName, file.ContentType, file.Length); int userId = !id.HasValue ? 0 : id.Value; string imageUrl = ""; ShopServices shs = new ShopServices(_config, _logger); string lat = latitude; string lng = longitude; string createdBy = updatedBy; DateTime? createdDate = DateTime.Now; Shop local = shs.GetByUserId(userId); if (local != null) { _logger.LogInformation("local.userid=" + local.UserId); imageUrl = await FileHelpers.FileUpload(userId, file) ?? local.ImageUrl; lat = !string.IsNullOrEmpty(latitude) ? latitude : local.Latitude; lng = !string.IsNullOrEmpty(longitude) ? longitude : local.Longitude; createdBy = local.CreatedBy; createdDate = local.CreatedDate; } else { _logger.LogInformation("New"); imageUrl = await FileHelpers.FileUpload(userId, file); } Shop model = new Shop() { UserId = userId, Name = name, Address = address, PhoneNo = phoneNo, ImageUrl = imageUrl, Latitude = lat, Longitude = lng, IsActive = isActive == null ? true : isActive, IsDelete = false, UpdatedDate = DateTime.Now, UpdatedBy = updatedBy, CreatedDate = createdDate, CreatedBy = createdBy }; shs.AddOrUpdate(model); return(Ok(new ResponseResult(200, StatusMessage.Completed.ToString(), "", model))); }
public ShopPage(Shop shop = null) { InitializeComponent(); services = new ShopServices(); if (shop != null) { BindingContext = shop; } Id = shop.Id; }
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 TestIfRemoveProductFromCartThrowsException(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.SaveChangesAsync(); await Assert.ThrowsAsync <NullReferenceException>(async() => { await shopService.RemoveProductFromCartAsync(username, product2); }); }
public async Task TestIfProductQuantityIncreasesThrowsErrorUserNull() { 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 Assert.ThrowsAsync <NullReferenceException>(async() => { await shopService.IncreaseProductQuantityAsync(null, "Product1", 3); }); }
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)); }
public bool CreateShopService(ShopServiceCreate model) { var entity = new ShopServices() { ShopID = _userId, ServiceName = model.ServiceName, Description = model.Description, Duration = model.Duration, Price = model.Price, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.ShopServices.Add(entity); return(ctx.SaveChanges() == 1); } }
public async Task TestIfReturnsZero() { var context = PCHUBDbContextInMemoryInitializer.InitializeContext(); var productService = new ProductServices(context); var shopService = new ShopServices(context, productService); await context.Users.AddAsync(new User { UserName = "******", Email = "*****@*****.**", LastLoginDate = DateTime.UtcNow, }); await context.SaveChangesAsync(); var result = await shopService.GetNumberOfProductsAsync("Test"); Assert.Equal(0, result); }
// GET: Shop public ActionResult Index() { ShopServices service = new ShopServices(); ShopModel shopmodel = new ShopModel(); HomeController homeController = new HomeController(); if (Session[SessionConstants.SESSION_CONTEXT_INSTANCE] != null) { User user = (User)(Session[SessionConstants.SESSION_CONTEXT_INSTANCE]); //get wishlist and cart details of the logged user shopmodel.headerDetails = homeController.CreateSessionModel(user.UserId, user.FullName); } else { shopmodel.headerDetails = null; } //get all product details to shop page shopmodel.ProductList = service.GetProductDetails(); return(View(shopmodel)); }
public async Task CheckoutAnonumousUserWorksAsExected() { var context = PCHUBDbContextInMemoryInitializer.InitializeContext(); var productService = new ProductServices(context); var shopService = new ShopServices(context, productService); var products = new List <PurchaseProductsAnonymousViewModel>(); products.Add(new PurchaseProductsAnonymousViewModel { Id = "randomId", Quantity = 1, Title = "Laptop Acer 31", Price = 2000, }); var anonymousCartViewModel = new AnonymousCartViewModel { FirstName = "Sensei", LastName = "Senseev", Address = "SenseiTv never purchase dot com", City = "Senseevo", ShippingCompany = View.Models.ShoppingCartViewModels.Enums.ShippingCompany.Econt, Email = "*****@*****.**", PhoneNumber = "023231233", Products = products, }; await shopService.ChechoutAnonymousAsync(anonymousCartViewModel); var user = await context.Users.FirstOrDefaultAsync(x => x.FirstName == "Sensei"); Assert.NotNull(user); var userShipmentsExist = user.Shipments.Any(); Assert.True(userShipmentsExist); }
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 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")); }
static void Main(string[] args) { int yourChoice = 0; bool checkInput; Shop coffeShop = new Shop(); ShopServices coffeShopServices = new ShopServices(ref coffeShop); while (true) { backToMainMenu: MenuProgramServices.DisplayMainMenu(); do { Console.Write("Your option: "); checkInput = ConvertServices.ToIntByTryParse(Console.ReadLine(), out yourChoice); } while (!checkInput || yourChoice <= 0 || yourChoice > 6); switch (yourChoice) { #region Add more tables case 1: int numberTableToCreate; Console.WriteLine($"Shop now have {coffeShop.ListTables.Count} tables (maximum is 50)"); do { Console.Write("Please enter number of tables you want to add(max 20): "); checkInput = ConvertServices.ToIntByTryParse(Console.ReadLine(), out numberTableToCreate); } while (!checkInput || numberTableToCreate < 0 || numberTableToCreate > 20); if (numberTableToCreate + coffeShop.ListTables.Count > 50) { Console.WriteLine("Your shop can't have to much tables"); goto backToMainMenu; //Back to main menu } coffeShopServices.AddMoreTable(numberTableToCreate); break; #endregion #region Add Item to Menu of Shop case 2: backToMenuAddItem: MenuProgramServices.DisplayMenuCreateItem(); do { Console.Write("Your Option: "); checkInput = ConvertServices.ToIntByTryParse(Console.ReadLine(), out yourChoice); } while (!checkInput || yourChoice <= 0 || yourChoice > 3); if (yourChoice == 3) { goto backToMenuAddItem; } coffeShopServices.AddItemToMenuShop(); string choiceContinue = string.Empty; do { Console.Write("Do you want add more item? (Y/N): "); choiceContinue = Console.ReadLine().Trim(); } while (choiceContinue != "Y" && choiceContinue != "y" && choiceContinue != "Y" && choiceContinue != "n"); if (choiceContinue == "Y" || choiceContinue == "y") { goto backToMenuAddItem; } break; #endregion #region Order case 3: if (coffeShopServices.CanMakeOrder()) { Console.WriteLine("Shop have no table or menu is empty to order"); goto backToMainMenu; } else { coffeShopServices.DisplayProductsMenu(); int id, qty, tableNumber; if (!coffeShopServices.InputDataOrder(out id, out qty, out tableNumber)) { goto backToMainMenu; } ItemOfMenu itemOrder = null; Table tableOrder = null; if (coffeShopServices.GetItemById(id) != null) { itemOrder = coffeShopServices.GetItemById(id); } if (coffeShopServices.GetTable(tableNumber) != null) { tableOrder = coffeShopServices.GetTable(tableNumber); } if (itemOrder != null && tableOrder != null) { coffeShopServices.OrderDrinksOrFoods(itemOrder, tableOrder, qty); Console.Write("Your order has success\n"); } else { Console.WriteLine("Please check again your input"); } } break; #endregion #region Create Payment case 4: int tableNumberCheckout = -1; Console.WriteLine("Enter 0 for back to main Program"); do { Console.Write("Please enter table number to create payment: "); checkInput = ConvertServices.ToIntByTryParse(Console.ReadLine(), out tableNumberCheckout); } while (!checkInput); if (tableNumberCheckout == 0) { goto backToMainMenu; } coffeShopServices.CreateBill(tableNumberCheckout); coffeShopServices.ChangeTableStatus(tableNumberCheckout); break; #endregion case 5: coffeShopServices.ShowTablesFree(); break; case 6: Environment.Exit(0); break; } } }
public ShopsPage() { InitializeComponent(); s_services = new ShopServices(); }
public CreateShopPage() { InitializeComponent(); services = new ShopServices(); }
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); }