public void AnyProductsShouldReturnTrueWhenThereAreProducts() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: $"CartService") .Options; var dbContext = new ApplicationDbContext(options); var user = new User { UserName = "******", Cart = new Cart() }; dbContext.Users.Add(user); var product = new Product { Name = "USB Cable" }; dbContext.Products.Add(product); dbContext.SaveChanges(); var userService = new Mock <IUsersService>(); userService.Setup(r => r.GetUserByUsername(user.UserName)) .Returns(user); var productService = new Mock <IProductsSerivce>(); productService.Setup(p => p.GetProductById(product.Id)) .Returns(product); var cartsService = new CartService(dbContext, productService.Object, userService.Object); cartsService.AddProductToCart(product.Id, user.UserName); var areThereAnyProducts = cartsService.AnyProducts(user.UserName); Assert.True(areThereAnyProducts); }