public void AddIngredient_AddsIngredientToJoinTable_IngredientList() { //Arrange Recipe testRecipe = new Recipe("Chocolate Chip Cookies", "Melt butter, mix with sugar, eggs, flour, salt, baking soda, chocolate chips. Bake for 10 minutes", 4); testRecipe.Save(); Ingredient testIngredient1 = new Ingredient("Chocolate"); testIngredient1.Save(); Ingredient testIngredient2 = new Ingredient("Sugar"); testIngredient2.Save(); //Act testRecipe.AddIngredientToJoinTable(testIngredient1); testRecipe.AddIngredientToJoinTable(testIngredient2); List <Ingredient> result = testRecipe.GetIngredients(); List <Ingredient> testList = new List <Ingredient> { testIngredient1, testIngredient2 }; //Assert CollectionAssert.AreEqual(testList, result); }
public ActionResult AddIngredients(int id) { // string ingredient = Request.Form["ingredient"]; // //Ingredient.Search(string) needs to return either an Ingredient object, or null // Ingredient newIngredient = Ingredient.Search(ingredient); // if (newIngredient = null) // { // Ingredient newIngredient = new Ingredient(ingredient); // newIngredient.Save(); // } string ingredient = Request.Form["ingredient"]; Ingredient newIngredient = new Ingredient(ingredient); Recipe thisRecipe = Recipe.Find(id); newIngredient.Save(); thisRecipe.AddIngredientToJoinTable(newIngredient); Dictionary <string, object> model = new Dictionary <string, object>(); List <Category> allCategories = Category.GetAll(); List <Ingredient> ingredientsRecipes = thisRecipe.GetIngredients(); List <Category> categoriesRecipes = thisRecipe.GetCategories(); List <Ingredient> allIngredients = Ingredient.GetAll(); model.Add("thisRecipe", thisRecipe); model.Add("allCategories", allCategories); model.Add("ingredientsRecipes", ingredientsRecipes); model.Add("categoriesRecipes", categoriesRecipes); model.Add("allIngredients", allIngredients); return(View("RecipeDetails", model)); }
public ActionResult SelectIngredient() { Recipe recipe = Recipe.Find(int.Parse(Request.Form["recipe-id"])); Ingredient thisIngredient = Ingredient.Find(int.Parse(Request.Form["ingredient-id"])); recipe.AddIngredientToJoinTable(thisIngredient); Dictionary <string, object> model = new Dictionary <string, object>(); Recipe thisRecipe = Recipe.Find(recipe.GetId()); List <Category> allCategories = Category.GetAll(); List <Ingredient> ingredientsRecipes = thisRecipe.GetIngredients(); List <Category> categoriesRecipes = thisRecipe.GetCategories(); List <Ingredient> allIngredients = Ingredient.GetAll(); model.Add("thisRecipe", thisRecipe); model.Add("allCategories", allCategories); model.Add("ingredientsRecipes", ingredientsRecipes); model.Add("categoriesRecipes", categoriesRecipes); model.Add("allIngredients", allIngredients); return(View("RecipeDetails", model)); }