Example #1
0
        public void Test_Update_UpdateRecipe()
        {
            string url         = "www.epicodus.com";
            string name        = "Spaghetti";
            Recipe testRecipe1 = new Recipe(name, "Noodles, Sauce", "Boil noodles", "20 Minutes", 5, url);

            testRecipe1.Save();

            string newName         = "Chicken Tandoori";
            string newIngredients  = "Chicken,Onions,Tomato";
            string newInstructions = "Roast Chicken";
            string newCookTime     = "30 minutes";
            int    newRating       = 5;
            string newUrl          = "www.google.com";

            testRecipe1.Update(newName, newIngredients, newInstructions, newCookTime, newRating, newUrl);
            Recipe actualResult = Recipe.GetAll()[0];

            Assert.Equal(newName, actualResult.GetName());
            Assert.Equal(newIngredients, actualResult.GetIngredients());
            Assert.Equal(newInstructions, actualResult.GetInstructions());
            Assert.Equal(newCookTime, actualResult.GetTime());
            Assert.Equal(newRating, actualResult.GetRating());
            Assert.Equal(newUrl, actualResult.GetUrl());
        }
Example #2
0
 public override bool Equals(System.Object randomRecipe)
 {
     if (!(randomRecipe is Recipe))
     {
         return(false);
     }
     else
     {
         Recipe newRecipe            = (Recipe)randomRecipe;
         bool   idEquality           = (this.GetId() == newRecipe.GetId());
         bool   nameEquality         = (this.GetName() == newRecipe.GetName());
         bool   ingredientsEquality  = (this.GetIngredients() == newRecipe.GetIngredients());
         bool   instructionsEquality = (this.GetInstructions() == newRecipe.GetInstructions());
         bool   rateEquality         = (this.GetRate() == newRecipe.GetRate());
         bool   timeEquality         = (this.GetTime() == newRecipe.GetTime());
         return(idEquality && nameEquality && ingredientsEquality && instructionsEquality && rateEquality && timeEquality);
     }
 }
Example #3
0
 public override bool Equals(System.Object otherRecipe)
 {
     if (!(otherRecipe is Recipe))
     {
         return(false);
     }
     else
     {
         Recipe newRecipe           = (Recipe)otherRecipe;
         bool   idEquality          = (this.GetId() == newRecipe.GetId());
         bool   nameEquality        = (this.GetName() == newRecipe.GetName());
         bool   ingredientEquality  = (this.GetIngredients() == newRecipe.GetIngredients());
         bool   instructionEquality = (this.GetInstructions() == newRecipe.GetInstructions());
         bool   cookTimeEquality    = (this.GetTime() == newRecipe.GetTime());
         bool   ratingEquality      = (this.GetRating() == newRecipe.GetRating());
         bool   urlEquality         = (this.GetUrl() == newRecipe.GetUrl());
         return(idEquality && nameEquality && ingredientEquality && instructionEquality && cookTimeEquality && ratingEquality && urlEquality);
     }
 }
Example #4
0
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Recipe> allRecipes = Recipe.GetAll();
                return(View["index.cshtml", allRecipes]);
            };
            Get["/new-recipe"] = _ => {
                return(View["recipe_form.cshtml"]);
            };

            Post["/recipe/added"] = _ => {
                Recipe newRecipe = new Recipe(Request.Form["recipe-name"], "", "", 0, "");
                newRecipe.Save();
                List <String> IngredientNames = new List <String> {
                };
                string Ingredients            = newRecipe.GetIngredients();
                if (Ingredients != "")
                {
                    string[] IngredientsArray = Ingredients.Split(' ');
                    foreach (string name in IngredientsArray)
                    {
                        IngredientNames.Add(name.Substring(1, name.Length - 1));
                    }
                }
                else
                {
                    IngredientNames = new List <String> {
                        "You have no ingredients so far"
                    };
                }
                List <String> Instructions = new List <String> {
                };
                string InstructionsString  = newRecipe.GetInstructions();
                if (InstructionsString != "")
                {
                    string[] InstructionsArray = InstructionsString.Split(' ');
                    foreach (string name in  InstructionsArray)
                    {
                        Console.WriteLine(name);
                        Instructions.Add(name.Substring(1, name.Length - 2));
                    }
                }
                else
                {
                    Instructions = new List <String> {
                        "You have no steps of instructions so far"
                    };
                }
                Dictionary <string, object> model = new Dictionary <string, object> {
                    { "recipe", newRecipe }, { "ingredients", IngredientNames }, { "instructions", Instructions }
                };
                return(View["recipe.cshtml", model]);
            };

            Post["/{id}/ingredient/added"] = parameters => {
                Recipe thisRecipe = Recipe.Find(parameters.id);
                Console.WriteLine("ingredient-name");
                thisRecipe.AddIngredient(Request.Form["ingredient-name"]);
                List <String> IngredientNames = new List <String> {
                };
                string   Ingredients          = thisRecipe.GetIngredients();
                string[] IngredientsArray     = Ingredients.Split(' ');
                foreach (string name in IngredientsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        IngredientNames.Add(name.Substring(1, name.Length - 2));
                    }
                }
                List <String> Instructions  = new List <String> {
                };
                string   InstructionsString = thisRecipe.GetInstructions();
                string[] InstructionsArray  = InstructionsString.Split('|');
                foreach (string name in  InstructionsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        Instructions.Add(name.Substring(1, name.Length - 2));
                    }
                }
                Dictionary <string, object> model = new Dictionary <string, object> {
                    { "recipe", thisRecipe }, { "ingredients", IngredientNames }, { "instruction", Instructions }
                };
                return(View["recipe.cshtml", model]);
            };

            Post["/{id}/instructions/added"] = parameters =>
            {
                Recipe thisRecipe = Recipe.Find(parameters.id);
                thisRecipe.AddInstruction(Request.Form["instructions"]);
                List <String> IngredientNames = new List <String> {
                };
                string   Ingredients          = thisRecipe.GetIngredients();
                string[] IngredientsArray     = Ingredients.Split(' ');
                foreach (string name in IngredientsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        IngredientNames.Add(name.Substring(1, name.Length - 2));
                    }
                }
                List <String> Instructions  = new List <String> {
                };
                string   InstructionsString = thisRecipe.GetInstructions();
                string[] InstructionsArray  = InstructionsString.Split('|');
                foreach (string name in  InstructionsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        Instructions.Add(name.Substring(1, name.Length - 2));
                    }
                }
                Dictionary <string, object> model = new Dictionary <string, object> {
                    { "recipe", thisRecipe }, { "ingredients", IngredientNames }, { "instruction", Instructions }
                };
                return(View["recipe.cshtml", model]);
            };
            Post["/recipe/{id}"] = parameters => {
                Recipe thisRecipe = Recipe.Find(parameters.id);
                thisRecipe.Update(null, null, null, int.Parse(Request.Form["star"]), Request.Form["time"]);
                List <String> IngredientNames = new List <String> {
                };
                string   Ingredients          = thisRecipe.GetIngredients();
                string[] IngredientsArray     = Ingredients.Split(' ');
                foreach (string name in IngredientsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        IngredientNames.Add(name.Substring(1, name.Length - 2));
                    }
                }
                List <String> Instructions  = new List <String> {
                };
                string   InstructionsString = thisRecipe.GetInstructions();
                string[] InstructionsArray  = InstructionsString.Split('|');
                foreach (string name in  InstructionsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        Instructions.Add(name.Substring(1, name.Length - 2));
                    }
                }
                Dictionary <string, object> Model = new Dictionary <string, object> {
                };
                Model.Add("recipe", thisRecipe);
                Model.Add("ingredients", IngredientNames);
                Model.Add("instructions", Instructions);
                Model.Add("rate", thisRecipe.GetRate());
                Model.Add("time", thisRecipe.GetTime());
                return(View["recipe-info.cshtml", Model]);
            };
            Delete["/deleteall"] = _ => {
                Recipe.DeleteAll();
                List <Recipe> allRecipes = Recipe.GetAll();
                return(View["index.cshtml", allRecipes]);
            };
            Get["/recipe/{id}/info"] = parameters => {
                Recipe        thisRecipe      = Recipe.Find(parameters.id);
                List <String> IngredientNames = new List <String> {
                };
                string   Ingredients          = thisRecipe.GetIngredients();
                string[] IngredientsArray     = Ingredients.Split(' ');
                foreach (string name in IngredientsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        IngredientNames.Add(name.Substring(1, name.Length - 2));
                    }
                }
                List <String> Instructions  = new List <String> {
                };
                string   InstructionsString = thisRecipe.GetInstructions();
                string[] InstructionsArray  = InstructionsString.Split('|');
                foreach (string name in  InstructionsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        Instructions.Add(name.Substring(1, name.Length - 2));
                    }
                }
                Dictionary <string, object> Model = new Dictionary <string, object> {
                };
                Model.Add("recipe", thisRecipe);
                Model.Add("ingredients", IngredientNames);
                Model.Add("instructions", Instructions);
                Model.Add("rate", thisRecipe.GetRate());
                Model.Add("time", thisRecipe.GetTime());
                return(View["recipe-info.cshtml", Model]);
            };

            Delete["/recipe/{id}/delete"] = parameters => {
                Recipe thisRecipe = Recipe.Find(parameters.id);
                thisRecipe.Delete();
                List <Recipe> allRecipes = Recipe.GetAll();
                return(View["index.cshtml", allRecipes]);
            };

            Get["/recipe/{id}/update"] = parameters => {
                Recipe        thisRecipe      = Recipe.Find(parameters.id);
                List <String> IngredientNames = new List <String> {
                };
                string   Ingredients          = thisRecipe.GetIngredients();
                string[] IngredientsArray     = Ingredients.Split(' ');
                foreach (string name in IngredientsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        IngredientNames.Add(name.Substring(1, name.Length - 2));
                    }
                }
                List <String> Instructions  = new List <String> {
                };
                string   InstructionsString = thisRecipe.GetInstructions();
                string[] InstructionsArray  = InstructionsString.Split('|');
                foreach (string name in  InstructionsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        Instructions.Add(name.Substring(1, name.Length - 2));
                    }
                }
                Dictionary <string, object> Model = new Dictionary <string, object> {
                };
                Model.Add("recipe", thisRecipe);
                Model.Add("ingredients", IngredientNames);
                Model.Add("instructions", Instructions);
                Model.Add("rate", thisRecipe.GetRate());
                Model.Add("time", thisRecipe.GetTime());
                return(View["recipe_update_form.cshtml", Model]);
            };
            Patch["/{id}/update/ingredient/{IngredientName}"] = parameters => {
                Recipe        thisRecipe      = Recipe.Find(parameters.id);
                List <String> IngredientNames = new List <String> {
                };
                string   Ingredients          = thisRecipe.GetIngredients();
                string[] IngredientsArray     = Ingredients.Split(' ');
                foreach (string name in IngredientsArray)
                {
                    if (!((String.IsNullOrEmpty(name)) || (name.Substring(1, name.Length - 2) == (string)parameters.IngredientName)))
                    {
                        IngredientNames.Add(name.Substring(1, name.Length - 2));
                    }
                }
                thisRecipe.AddIngredients(IngredientNames);
                List <String> Instructions  = new List <String> {
                };
                string   InstructionsString = thisRecipe.GetInstructions();
                string[] InstructionsArray  = InstructionsString.Split('|');
                foreach (string name in  InstructionsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        Instructions.Add(name.Substring(1, name.Length - 2));
                    }
                }
                Dictionary <string, object> Model = new Dictionary <string, object> {
                };
                Model.Add("recipe", thisRecipe);
                Model.Add("ingredients", IngredientNames);
                Model.Add("instructions", Instructions);
                Model.Add("rate", thisRecipe.GetRate());
                Model.Add("time", thisRecipe.GetTime());
                return(View["recipe_update_form.cshtml", Model]);
            };
            Post["/{id}/ingredient/update/added"] = parameters => {
                Recipe thisRecipe = Recipe.Find(parameters.id);
                Console.WriteLine("ingredient-name");
                thisRecipe.AddIngredient(Request.Form["ingredient-name"]);
                List <String> IngredientNames = new List <String> {
                };
                string   Ingredients          = thisRecipe.GetIngredients();
                string[] IngredientsArray     = Ingredients.Split(' ');
                foreach (string name in IngredientsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        IngredientNames.Add(name.Substring(1, name.Length - 2));
                    }
                }
                List <String> Instructions  = new List <String> {
                };
                string   InstructionsString = thisRecipe.GetInstructions();
                string[] InstructionsArray  = InstructionsString.Split('|');
                foreach (string name in  InstructionsArray)
                {
                    if ((!(String.IsNullOrEmpty(name))))
                    {
                        Instructions.Add(name.Substring(1, name.Length - 2));
                    }
                }
                Dictionary <string, object> Model = new Dictionary <string, object> {
                };
                Model.Add("recipe", thisRecipe);
                Model.Add("ingredients", IngredientNames);
                Model.Add("instructions", Instructions);
                Model.Add("rate", thisRecipe.GetRate());
                Model.Add("time", thisRecipe.GetTime());
                return(View["recipe_update_form.cshtml", Model]);
            };
            Patch["/{id}/update/instructions/{InstructionName}"] = parameters => {
                Recipe        thisRecipe      = Recipe.Find(parameters.id);
                List <String> IngredientNames = new List <String> {
                };
                string   Ingredients          = thisRecipe.GetIngredients();
                string[] IngredientsArray     = Ingredients.Split(' ');
                foreach (string name in IngredientsArray)
                {
                    if (!(String.IsNullOrEmpty(name)))
                    {
                        IngredientNames.Add(name.Substring(1, name.Length - 2));
                    }
                }
                thisRecipe.AddIngredients(IngredientNames);
                List <String> Instructions  = new List <String> {
                };
                string   InstructionsString = thisRecipe.GetInstructions();
                string[] InstructionsArray  = InstructionsString.Split('|');
                foreach (string name in  InstructionsArray)
                {
                    if (!((String.IsNullOrEmpty(name)) || (name.Substring(1, name.Length - 2) == (string)parameters.InstructionName)))
                    {
                        Instructions.Add(name.Substring(1, name.Length - 2));
                    }
                }
                thisRecipe.AddInstructions(Instructions);
                Dictionary <string, object> Model = new Dictionary <string, object> {
                };
                Model.Add("recipe", thisRecipe);
                Model.Add("ingredients", IngredientNames);
                Model.Add("instructions", Instructions);
                Model.Add("rate", thisRecipe.GetRate());
                Model.Add("time", thisRecipe.GetTime());
                return(View["recipe_update_form.cshtml", Model]);
            };
        }