Esempio n. 1
0
        public void AddIngredientToRecipe_BothNotFound_ReturnsFalse()
        {
            //add an ingredient where recipe and ingredient are not found
            var added = ingredientRepository.AddIngredientToRecipe(12245, 456456);

            //should return false
            Assert.IsFalse(added);
        }
Esempio n. 2
0
        public void AddIngredientToRecipe_IngredientFoundRecipeNotFound_ReturnsFalse()
        {
            var ingredient = new Ingredient()
            {
                Name = "Beef"
            };


            //add the ingredient to the database
            var ingredientRepository = new IngredientRepository(Context);

            ingredientRepository.Add(ingredient);

            var foundIngredient = ingredientRepository.GetAll().ToList();

            //there should only be one added record in the database
            Assert.AreEqual(1, foundIngredient.Count());

            //add an ingredient where recipe is not found and the ingredient is
            if (foundIngredient != null)
            {
                var added = ingredientRepository.AddIngredientToRecipe(456456, foundIngredient[0].IngredientId);
                //should return false
                Assert.IsFalse(added);
            }
        }
Esempio n. 3
0
        public void GetIngredients_RecipeFound_ReturnsIngredients()
        {
            //create the new recipe
            var recipe = new Recipe()
            {
                Name = "Butter Chicken"
            };

            //find the added recipe
            var foundRecipe = recipeRepository.Find(recipe => recipe.Name == "Butter Chicken")
                              .FirstOrDefault();
            //create ingredients
            var ingredients = new List <Ingredient>()
            {
                new Ingredient()
                {
                    Name = "Whole Chicken"
                },
                new Ingredient()
                {
                    Name = "Sour Cream"
                },
                new Ingredient()
                {
                    Name = "Gee"
                }
            };

            //add the ingredients
            var ingredientRepository = new IngredientRepository(Context);

            ingredientRepository.AddRange(ingredients);

            //get all ingredients and now add it to the recipe
            var ingredientsList = ingredientRepository.GetAll().ToList();

            //three ingredients should be added to the database
            Assert.AreEqual(3, ingredientsList.Count());

            //found the recipe and ingredients list
            if (foundRecipe != null && ingredientsList != null)
            {
                var addedToRecipe = false;


                foreach (var ingredient in ingredientsList)
                {
                    //add the ingredients to the recipe
                    addedToRecipe = ingredientRepository.AddIngredientToRecipe(foundRecipe.RecipeId, ingredient.IngredientId);
                    Assert.IsTrue(addedToRecipe);
                }

                //Insure that the foundRecipe has the same count as the ingredients list
                Assert.AreEqual(foundRecipe.Ingredients.Count(), ingredientsList.Count());
            }
        }
        /// <summary>
        /// Method to add an ingredient to a recipe
        /// </summary>
        /// <param name="recipe">The recipe to add the ingredient to</param>
        /// <param name="ingredient">The ingredient to add the recipe to</param>
        /// <returns></returns>
        public async Task <bool> AddIngredientToRecipeAsync(RecipeDTO recipe, IngredientDTO ingredient)
        {
            var ingredientAdded = true;

            try
            {
                await Task.Run(() => ingredientRepository.AddIngredientToRecipe(recipe.RecipeId, ingredient.IngredientId));
            }
            catch (Exception ex)
            {
                ingredientAdded = false;
            }

            return(ingredientAdded);
        }