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