Exemplo n.º 1
0
        public async Task GetCountShouldReturnProperCount()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            AutoMapperConfig.RegisterMappings(Assembly.Load("CookingBook.Web.ViewModels"));
            var dbContext = new ApplicationDbContext(options);

            dbContext.Recipes.Add(new Recipe());
            dbContext.Recipes.Add(new Recipe());
            dbContext.Recipes.Add(new Recipe());
            await dbContext.SaveChangesAsync();

            var recipeRepo    = new EfDeletableEntityRepository <Recipe>(dbContext);
            var nutritionRepo = new EfDeletableEntityRepository <NutritionValue>(dbContext);
            var productRepo   = new EfDeletableEntityRepository <Product>(dbContext);
            var userRepo      = new EfDeletableEntityRepository <ApplicationUser>(dbContext);
            var service       = new RecipesService(recipeRepo, nutritionRepo, productRepo, userRepo);

            Assert.Equal(3, service.GetCount());
        }