public void DeleteCategoryFromRecipe() { 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(); Category testCategory1 = new Category("Dessert"); testCategory1.Save(); Category testCategory2 = new Category("Baking"); testCategory2.Save(); testRecipe.AddCategoryToJoinTable(testCategory1); testRecipe.AddCategoryToJoinTable(testCategory2); testRecipe.DeleteCategoryFromRecipe(testCategory1); List <Category> expectedList = new List <Category> { testCategory2 }; List <Category> actualList = testRecipe.GetCategories(); CollectionAssert.AreEqual(expectedList, actualList); }
public void AddCategory_AddsCategoryToJoinTable_CategoryList() { //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(); Category testCategory1 = new Category("Dessert"); testCategory1.Save(); Category testCategory2 = new Category("Baking"); testCategory2.Save(); //Act testRecipe.AddCategoryToJoinTable(testCategory1); testRecipe.AddCategoryToJoinTable(testCategory2); List <Category> result = testRecipe.GetCategories(); List <Category> testList = new List <Category> { testCategory1, testCategory2 }; //Assert CollectionAssert.AreEqual(testList, result); }
public ActionResult AddCategoryToRecipe() { Recipe recipe = Recipe.Find(Int32.Parse(Request.Form["recipe-id"])); Category category = Category.Find(Int32.Parse(Request.Form["category-id"])); recipe.AddCategoryToJoinTable(category); 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)); }
public void Delete_DeletesRecipeAssociationsFromDatabase_RecipeList() { //Arrange Category testCategory = new Category("Dessert"); testCategory.Save(); 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(); //Act testRecipe.AddCategoryToJoinTable(testCategory); testRecipe.Delete(); List <Recipe> resultCategoryRecipes = testCategory.GetRecipes(); List <Recipe> testCategoryRecipes = new List <Recipe> { }; //Assert CollectionAssert.AreEqual(testCategoryRecipes, resultCategoryRecipes); }