Ejemplo n.º 1
0
        public void AllFavoriteShouldReturnAllFavoriteProducts()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "All_Favorites_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var username = "******";

            dbContext.Users.Add(new XeonUser {
                UserName = username
            });

            var products = new List <Product>
            {
                new Product {
                    Name = "USB"
                },
                new Product {
                    Name = "Phone Samsung"
                },
                new Product {
                    Name = "Phone Nokia"
                },
                new Product {
                    Name = "Phone Iphone"
                },
                new Product {
                    Name = "Tablet Galaxy"
                }
            };

            dbContext.Products.AddRange(products);
            dbContext.SaveChanges();

            var favoriteService = new FavoritesService(dbContext);

            foreach (var product in products.Take(3))
            {
                favoriteService.Add(product.Id, username);
            }

            var favoriteProducts = favoriteService.All(username);

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