Example #1
0
        public void Test_GetCategory_ReturnsAllRecipeCategories()
        {
            //Arrange
            Recipe testRecipe = new Recipe("Spicy Yaki Soba", "Spicy, Soba", "Pour Spicy into Soba");

            testRecipe.Save();

            Category testCategory1 = new Category("Asian");

            testCategory1.Save();

            Category testCategory2 = new Category("Mexican");

            testCategory2.Save();

            //Act
            testRecipe.AddCategory(testCategory1);
            List <Category> result   = testRecipe.GetCategories();
            List <Category> testList = new List <Category> {
                testCategory1
            };

            //Assert
            Assert.Equal(testList, result);
        }
Example #2
0
        public void Test_AddCategory_AddCategoryToRecipe()
        {
            string url        = "www.epicodus.com";
            Recipe testRecipe = new Recipe("Chicken Tandoori", "Chicken,Onions,Tomato", "Roast Chicken", "30 minutes", 5, url);

            testRecipe.Save();

            Category testCategory = new Category("Mexican");

            testCategory.Save();

            Category testCategory2 = new Category("Italian");

            testCategory2.Save();

            testRecipe.AddCategory(testCategory);
            testRecipe.AddCategory(testCategory2);

            List <Category> testList = new List <Category> {
                testCategory, testCategory2
            };
            List <Category> result = testRecipe.GetCategories();

            Assert.Equal(result, testList);
        }
Example #3
0
        public void Test_GetCategories_ReturnsAllRecipeCategories()
        {
            //Arrange
            Recipe testRecipe = new Recipe("Mac and cheese", "cheese and noodles", "cook it", 5);

            testRecipe.Save();

            Category testCategory1 = new Category("Mexican");

            testCategory1.Save();

            Category testCategory2 = new Category("Thai");

            testCategory2.Save();

            //Act
            testRecipe.AddCategory(testCategory1);
            List <Category> result   = testRecipe.GetCategories();
            List <Category> testList = new List <Category> {
                testCategory1
            };

            //Assert
            Assert.Equal(testList, result);
        }
Example #4
0
        public void Test_AddCategory_AddsCategoryToRecipe()
        {
            //Arrange
            Recipe testRecipe = new Recipe("Spicy Yaki Soba", "Spicy, Soba", "Pour Spicy into Soba");

            testRecipe.Save();

            Category testCategory = new Category("Asian");

            testCategory.Save();

            //Act
            testRecipe.AddCategory(testCategory);

            List <Category> result   = testRecipe.GetCategories();
            List <Category> testList = new List <Category> {
                testCategory
            };

            //Assert
            Assert.Equal(testList, result);
        }
Example #5
0
        public void Test_AddCategory_AddsCategoryToRecipe()
        {
            //Arrange
            Recipe testRecipe = new Recipe("Mac and cheese", "cheese and noodles", "cook it", 5);

            testRecipe.Save();

            Category testCategory = new Category("Mexican");

            testCategory.Save();

            //Act
            testRecipe.AddCategory(testCategory);

            List <Category> result   = testRecipe.GetCategories();
            List <Category> testList = new List <Category> {
                testCategory
            };

            //Assert
            Assert.Equal(testList, result);
        }
Example #6
0
        public void Test_Delete_DeletesCategoryAssociationsFromDatabase()
        {
            //Arrange
            Recipe testRecipe = new Recipe("Mac and cheese", "cheese and noodles", "cook it", 5);

            testRecipe.Save();

            Category testCategory = new Category("Mexican");

            testCategory.Save();

            //Act
            testCategory.AddRecipe(testRecipe);
            testCategory.Delete();

            List <Category> resultRecipesCategories = testRecipe.GetCategories();
            List <Category> testRecipesCategories   = new List <Category> {
            };

            //Assert
            Assert.Equal(testRecipesCategories, resultRecipesCategories);
        }
        public void Test_Delete_DeletesCategoryAssociationsFromDatabase()
        {
            //Arrange
            Recipe testRecipe = new Recipe("Spicy Yaki Soba", "Spicy, Soba", "Pour Spicy into Soba");

            testRecipe.Save();

            string   testName     = "Asian";
            Category testCategory = new Category(testName);

            testCategory.Save();

            //Act
            testCategory.AddRecipe(testRecipe);
            testCategory.Delete();

            List <Category> resultRecipeCategories = testRecipe.GetCategories();
            List <Category> testRecipeCategories   = new List <Category> {
            };

            //Assert
            Assert.Equal(testRecipeCategories, resultRecipeCategories);
        }
Example #8
0
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["index.cshtml", AllCategories]);
            };

            Get["/recipes"] = _ => {
                List <Recipe> AllRecipes = Recipe.GetAll();
                return(View["recipes.cshtml", AllRecipes]);
            };
            Get["/categories"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["categories.cshtml", AllCategories]);
            };

            Get["/categories/new"] = _ => {
                return(View["categories_form.cshtml"]);
            };
            Post["/categories/new"] = _ => {
                Category newCategory = new Category(Request.Form["category-name"]);
                newCategory.Save();
                return(View["categories.cshtml", Category.GetAll()]);
            };

            Get["/recipes/new"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["recipes_form.cshtml", AllCategories]);
            };
            Post["/recipes/new"] = _ => {
                Recipe newRecipe = new Recipe(Request.Form["recipe-name"], Request.Form["recipe-ingredient"], Request.Form["recipe-instruction"], Request.Form["recipe-rating"]);
                newRecipe.Save();
                return(View["recipes.cshtml", Recipe.GetAll()]);
            };

            Get["recipes/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Recipe          SelectedRecipe    = Recipe.Find(parameters.id);
                List <Category> RecipeCategories  = SelectedRecipe.GetCategories();
                List <Category> AllCategories     = Category.GetAll();
                model.Add("recipe", SelectedRecipe);
                model.Add("recipeCategories", RecipeCategories);
                model.Add("allCategories", AllCategories);
                return(View["recipe.cshtml", model]);
            };
            Get["/categories/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var           SelectedCategory    = Category.Find(parameters.id);
                var           CategoryRecipes     = SelectedCategory.GetRecipes();
                List <Recipe> AllRecipes          = Recipe.GetAll();
                model.Add("category", SelectedCategory);
                model.Add("categoryRecipes", CategoryRecipes);
                model.Add("allRecipes", AllRecipes);
                return(View["category.cshtml", model]);
            };

            Post["/recipe/add_category"] = _ => {
                Category category = Category.Find(Request.Form["category-id"]);
                Recipe   recipe   = Recipe.Find(Request.Form["recipe-id"]);
                recipe.AddCategory(category);
                return(View["category-list.cshtml", recipe.GetCategories()]);
            };
            Post["/category/add_recipe"] = _ => {
                Category category = Category.Find(Request.Form["category-id"]);
                Recipe   recipe   = Recipe.Find(Request.Form["recipe-id"]);
                category.AddRecipe(recipe);
                return(View["recipe-list.cshtml", category.GetRecipes()]);
            };

            Patch["/category/edit/{id}"] = parameters => {
                Category SelectedCategory = Category.Find(parameters.id);
                SelectedCategory.UpdateCategories(Request.Form["new-category-name"]);
                return(View["categories.cshtml", Category.GetAll()]);
            };
            Patch["/recipe/edit/{id}"] = parameters => {
                Recipe SelectedRecipe = Recipe.Find(parameters.id);
                SelectedRecipe.UpdateRecipes(Request.Form["new-recipe-name"], Request.Form["new-recipe-ingredient"], Request.Form["new-recipe-instruction"], Request.Form["new-recipe-rating"]);
                return(View["recipes.cshtml", Recipe.GetAll()]);
            };

            Get["/recipes/detail/{id}"] = parameters =>
            {
                Recipe recipe = Recipe.Find(parameters.id);
                return(View["recipe-detail.cshtml", recipe]);
            };

            Delete["/categories/{id}"] = parameters =>
            {
                Category targetCategory = Category.Find(parameters.id);
                targetCategory.Delete();
                return(View["categories.cshtml", Category.GetAll()]);
            };
            Delete["/recipes/{id}"] = parameters =>
            {
                Recipe targetRecipe = Recipe.Find(parameters.id);
                targetRecipe.Delete();
                return(View["recipes.cshtml", Recipe.GetAll()]);
            };

            Post["/recipe/search/results"] = _ => {
                List <Recipe> FoundList = new List <Recipe> {
                };
                Recipe foundRecipe      = Recipe.FindByIngredient(Request.Form["recipe-search"]);
                FoundList.Add(foundRecipe);
                return(View["search.cshtml", FoundList]);
            };

            Post["/categories/delete"] = _ => {
                Category.DeleteAll();
                Recipe.DeleteAll();
                return(View["index.cshtml"]);
            };
            Post["/recipes/delete"] = _ => {
                Recipe.DeleteAll();
                return(View["index.cshtml"]);
            };
        }
Example #9
0
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["index.cshtml", AllCategories]);
            };

            Get["/recipe/new"] = _ => {
                return(View["category_recipes.cshtml"]);
            };

            Post["/"] = _ => {
                Category newCategory = new Category(Request.Form["category-name"]);
                newCategory.Save();
                return(View["index.cshtml", Category.GetAll()]);
            };

            Post["/category/{id}/recipe/new"] = parameters => {
                Recipe newRecipe = new Recipe(Request.Form["recipe-name"], Request.Form["recipe-ingredients"], Request.Form["recipe-instructions"]);
                newRecipe.Save();
                Category SelectedCategory = Category.Find(parameters.id);
                SelectedCategory.AddRecipe(newRecipe);
                Dictionary <string, object> model = new Dictionary <string, object>();
                List <Recipe> RecipeList          = SelectedCategory.GetRecipes();
                model.Add("category", SelectedCategory);
                model.Add("recipes", RecipeList);

                return(View["category_recipes.cshtml", model]);
            };

            Get["/category/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category      SelectedCategory    = Category.Find(parameters.id);
                List <Recipe> RecipeList          = SelectedCategory.GetRecipes();
                model.Add("category", SelectedCategory);
                model.Add("recipes", RecipeList);
                return(View["category_recipes.cshtml", model]);
            };

            Get["/recipe/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Recipe          SelectedRecipe    = Recipe.Find(parameters.id);
                List <Category> RecipeCategory    = SelectedRecipe.GetCategories();
                model.Add("recipe", SelectedRecipe);
                return(View["index.cshtml"]);
            };

            Delete["/category/delete/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category SelectedCategory         = Category.Find(parameters.id);
                SelectedCategory.Delete();
                model.Add("category", SelectedCategory);
                return(View["success.cshtml", model]);
            };

            Get["/recipe/delete/{id}"] = parameters => {
                Recipe SelectedRecipe = Recipe.Find(parameters.id);
                return(View["category_recipes.cshtml", SelectedRecipe]);
            };

            Patch["/recipe/edit/{id}"] = parameters => {
                Recipe SelectedRecipe = Recipe.Find(parameters.id);
                SelectedRecipe.UpdateRecipe(Request.Form["recipe-name"], Request.Form["recipe-ingredients"], Request.Form["recipe-instructions"]);
                return(View["success.cshtml", Recipe.GetAll()]);
            };


            Delete["/recipe/delete/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Recipe SelectedRecipe             = Recipe.Find(parameters.id);
                SelectedRecipe.Delete();
                model.Add("recipe", SelectedRecipe);
                return(View["success.cshtml", model]);
            };
        }