Example #1
0
        public ActionResult <List <Meal> > mealsFromFile()
        {
            ParserCsv parser = new ParserCsv();

            List <Meal> meals = parser.parseMealsCsv();

            foreach (Meal meal in meals)
            {
                ICollection <IngredientQuantity> ingredients = meal.ingredients;

                foreach (IngredientQuantity ingredientQuantity in ingredients)
                {
                    Ingredient ingredient = ingredientQuantity.ingredient;

                    Ingredient ingredientFromDb = _ingredientsRepository.GetByName(ingredient.name);

                    if (ingredientFromDb == null)
                    {
                        ingredientFromDb = _ingredientsRepository.Create(ingredient);
                    }

                    ingredientQuantity.ingredient = ingredientFromDb;
                }
            }

            return(_mealRepository.CreateMany(meals));
        }
        public void GetByIngredientsIncAndExc_Should_Work_Ok()
        {
            RunOnDatabase(async s =>
            {
                DestroyDatabase();
                // Arrange
                var fridgeRepo    = new FridgeRepository(s);
                var ingredCatRepo = new IngredientsCategoryRepository(s);
                var ingredRepo    = new IngredientsRepository(s, ingredCatRepo, fridgeRepo);
                var recipeRepo    = new RecipesRepository(s, fridgeRepo, ingredRepo);
                // Act
                Populate(s);
                List <Ingredient> igToAdd     = new List <Ingredient>();
                List <Ingredient> igToExclude = new List <Ingredient>();
                igToAdd.Add(ingredRepo.GetByName("i1").Result.First());
                igToAdd.Add(ingredRepo.GetByName("i3").Result.First());
                var res = await recipeRepo.GetByIngredients(igToAdd, igToExclude, recipeRepo.GetAll());

                // Assert
                Assert.AreEqual(1, res.ToList().Count);
            });
        }
Example #3
0
        public void Given_Repository_When_Get_By_Ingredient_ShouldBe_Correct()
        {
            RunOnDatabase(async s =>
            {
                DestroyDatabase();
                // Arrange
                var fridgeRepos    = new FridgeRepository(s);
                var categoryRepo   = new IngredientsCategoryRepository(s);
                var ingredientRepo = new IngredientsRepository(s, categoryRepo, fridgeRepos);
                var recipeRepo     = new RecipesRepository(s, fridgeRepos, ingredientRepo);

                // Act
                Populate(s);
                var data = await fridgeRepos.GetByIngredient(ingredientRepo.GetByName("i1").Result.First().Id);

                // Assert
                Assert.AreEqual(2, data.ToList().Count);
            });
        }
        public void ExcludesIngredients_Should_Work_Ok()
        {
            RunOnDatabase(async s =>
            {
                DestroyDatabase();
                // Arrange
                var fridgeRepo    = new FridgeRepository(s);
                var ingredCatRepo = new IngredientsCategoryRepository(s);
                var ingredRepo    = new IngredientsRepository(s, ingredCatRepo, fridgeRepo);
                var recipeRepo    = new RecipesRepository(s, fridgeRepo, ingredRepo);
                // Act
                Populate(s);
                List <Ingredient> igToAdd = new List <Ingredient>();
                igToAdd.Add(ingredRepo.GetByName("i1").Result.First());
                var res = await recipeRepo.ExcludesTheseIngredients(recipeRepo.GetByName("r1", recipeRepo.GetAll()).Result.First().Id, igToAdd);

                // Assert
                Assert.AreEqual(false, res);
            });
        }
Example #5
0
        public void AddIngredientsToProduct(Product product, IEnumerable <Ingredient> ingredients)
        {
            foreach (var ingredient in ingredients)
            {
                if (ingredient == null || ingredient?.Name == null)
                {
                    continue;
                }

                var ingredientFromDb = _ingredientsRepository.GetByName(ingredient.Name);

                if (ingredientFromDb == null)
                {
                    ingredientFromDb = new Ingredient()
                    {
                        Name = ingredient.Name
                    };
                }

                product.Ingredients.Add(ingredientFromDb);
            }
        }
 public void ContainsIngredient_Should_Work_Ok()
 {
     RunOnDatabase(async s =>
     {
         DestroyDatabase();
         // Arrange
         var fridgeRepo    = new FridgeRepository(s);
         var ingredCatRepo = new IngredientsCategoryRepository(s);
         var ingredRepo    = new IngredientsRepository(s, ingredCatRepo, fridgeRepo);
         var recipeRepo    = new RecipesRepository(s, fridgeRepo, ingredRepo);
         // Act
         Populate(s);
         var res = await recipeRepo.ContainsIngredient(recipeRepo.GetByName("r1", recipeRepo.GetAll()).Result.First().Id, ingredRepo.GetByName("i1").Result.First().Id);
         // Assert
         Assert.IsTrue(res);
     });
 }