Esempio n. 1
0
        public void Ingredient_Update_UpdateDatabaseAndLocalObject()
        {
            Ingredient testIngredient = new Ingredient("Pepper");

            testIngredient.Save();

            testIngredient.Update("Ketchup");
            Ingredient expectedIngredient = new Ingredient("Ketchup", testIngredient.GetId());

            Assert.Equal(expectedIngredient, Ingredient.Find(testIngredient.GetId()));
        }
Esempio n. 2
0
        public void Ingredient_Save_NoSaveOnDuplicateIngredient()
        {
            Ingredient testIngredient = new Ingredient("Pepper");

            testIngredient.Save();
            Ingredient secondIngredient = new Ingredient("Pepper");

            secondIngredient.Save();

            Assert.Equal(1, Ingredient.GetAll().Count);
        }
Esempio n. 3
0
        public void Find_OneIngredientId_ReturnIngredientFromDatabase()
        {
            //Arrange
            Ingredient testIngredient = new Ingredient("Pepper");

            testIngredient.Save();

            //Act
            Ingredient foundIngredient = Ingredient.Find(testIngredient.GetId());

            //Assert
            Assert.Equal(testIngredient, foundIngredient);
        }
Esempio n. 4
0
        public void Save_OneIngredient_IngredientSavedWithCorrectID()
        {
            //Arrange
            Ingredient testIngredient = new Ingredient("Pepper");

            testIngredient.Save();
            Ingredient savedIngredient = Ingredient.GetAll()[0];

            //Act
            int output = savedIngredient.GetId();
            int verify = testIngredient.GetId();

            //Assert
            Assert.Equal(verify, output);
        }
Esempio n. 5
0
        public void Save_OneIngredient_IngredientSavedToDatabase()
        {
            //Arrange
            Ingredient testIngredient = new Ingredient("Pepper");

            //Act
            testIngredient.Save();
            List <Ingredient> output = Ingredient.GetAll();
            List <Ingredient> verify = new List <Ingredient> {
                testIngredient
            };

            //Assert
            Assert.Equal(verify, output);
        }
Esempio n. 6
0
        public void SearchName_Name_ReturnIngredientFromDatabase()
        {
            //Arrange
            Ingredient testIngredient = new Ingredient("Pepper");

            testIngredient.Save();

            //Act
            List <Ingredient> output = Ingredient.SearchName("Pepper");
            List <Ingredient> verify = new List <Ingredient> {
                testIngredient
            };

            //Assert
            Assert.Equal(verify, output);
        }
Esempio n. 7
0
        public void Category_GetIngredientsByCategory_ReturnListOfIngredients()
        {
            //Arrange
            Ingredient testIngredient = new Ingredient("Chicken");

            testIngredient.Save();

            Category testCategory = new Category("Peasant");

            testCategory.Save();

            //Act
            testIngredient.AddCategory(testCategory);

            //Assert
            Assert.Equal(testIngredient, testCategory.GetIngredientsByCategory()[0]);
        }
Esempio n. 8
0
        public void SaveGetAll_ManyIngredients_ReturnListOfIngredients()
        {
            //Arrange
            Ingredient ingredientOne = new Ingredient("Pepper");

            ingredientOne.Save();
            Ingredient ingredientTwo = new Ingredient("Bacon");

            ingredientTwo.Save();

            //Act
            List <Ingredient> output = Ingredient.GetAll();
            List <Ingredient> verify = new List <Ingredient> {
                ingredientOne, ingredientTwo
            };

            //Assert
            Assert.Equal(verify, output);
        }
Esempio n. 9
0
        public void AddCategory_OneIngredient_CategoryAddedToJoinTable()
        {
            //Arrange
            Ingredient testIngredient = new Ingredient("Pepper");

            testIngredient.Save();
            Category testCategory = new Category("Spices");

            testCategory.Save();
            testIngredient.AddCategory(testCategory);

            //Act
            List <Category> output = testIngredient.GetCategory();
            List <Category> verify = new List <Category> {
                testCategory
            };

            //Assert
            Assert.Equal(verify, output);
        }
Esempio n. 10
0
        public void AddRecipe_OneIngredient_RecipeAssociatedWithIngredientAddedToJoinTable()
        {
            //Arrange
            Ingredient testIngredient = new Ingredient("Pepper");

            testIngredient.Save();
            Recipe testRecipe = new Recipe("Pot Pie", "Microwave it");

            testRecipe.Save();
            testIngredient.AddRecipe(testRecipe);

            //Act
            List <Recipe> output = testIngredient.GetRecipesByIngredient();
            List <Recipe> verify = new List <Recipe> {
                testRecipe
            };

            //Assert
            Assert.Equal(verify, output);
        }
Esempio n. 11
0
        public void Recipe_UpdateAmount_UpdateJoinTabaleAndLocalObject()
        {
            Recipe testRecipe = new Recipe("Pot Pie", "Microwave it");

            testRecipe.Save();
            Ingredient testIngredient = new Ingredient("Pepper");

            testIngredient.Save();
            testRecipe.AddIngredient(testIngredient, "1 dash ");

            testRecipe.UpdateAmount(testIngredient, "1 pound ");
            List <Ingredient> outputList = testRecipe.GetIngredient();
            List <Ingredient> verifyList = new List <Ingredient> {
                testIngredient
            };

            string output = outputList[0].GetAmount() + outputList[0].GetName();
            string verify = "1 pound Pepper";

            Assert.Equal(verify, output);
        }
Esempio n. 12
0
        public void AddIngredient_OneRecipe_IngredientAddedToJoinTable()
        {
            //Arrange
            Recipe testRecipe = new Recipe("Pot Pie", "Microwave it");

            testRecipe.Save();
            Ingredient testIngredient = new Ingredient("Pepper");

            testIngredient.Save();
            testRecipe.AddIngredient(testIngredient, "1 dash ");

            //Act
            List <Ingredient> outputList = testRecipe.GetIngredient();
            List <Ingredient> verifyList = new List <Ingredient> {
                testIngredient
            };

            string output = outputList[0].GetAmount() + outputList[0].GetName();
            string verify = "1 dash Pepper";

            //Assert
            Assert.Equal(verify, output);
        }
Esempio n. 13
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };

            Get["/recipes"] = _ => {
                return(View["recipes.cshtml", ModelMaker()]);
            };

            Post["/recipes"] = _ => {
                Recipe newRecipe = new Recipe(Request.Form["recipe-name"], Request.Form["instruction"], int.Parse(Request.Form["rating"]));
                newRecipe.Save();
                int ingredientCounter = int.Parse(Request.Form["ingredient-counter"]);
                for (int index = 1; index <= ingredientCounter; index++)
                {
                    Ingredient newIngredient = new Ingredient(Request.Form["ingredient-" + index.ToString()]);
                    newIngredient.Save();
                    string newAmount = Request.Form["ingredient-amount-" + index.ToString()];
                    newRecipe.AddIngredient(newIngredient, newAmount);
                }
                return(View["recipes.cshtml", ModelMaker()]);
            };

            Delete["/recipes"] = _ => {
                Recipe.DeleteAll();
                return(View["recipes.cshtml", ModelMaker()]);
            };

            Get["/recipes/{id}"] = parameters => {
                Dictionary <string, object> model = ModelMaker();
                model.Add("recipe", Recipe.Find(parameters.id));
                return(View["recipe.cshtml", model]);
            };

            Delete["/recipes/{id}"] = parameters => {
                Recipe.Find(parameters.id).Delete();
                return(View["recipes.cshtml", ModelMaker()]);
            };

            Patch["/recipes/{id}"] = parameters => {
                Recipe newRecipe = Recipe.Find(parameters.id);
                newRecipe.Update(Request.Form["update-recipe-name"], Request.Form["instruction"], Request.Form["rating"]);
                newRecipe.DeleteIngredients();
                int ingredientCounter = int.Parse(Request.Form["ingredient-counter"]);
                for (int index = 1; index <= ingredientCounter; index++)
                {
                    Ingredient newIngredient = new Ingredient(Request.Form["ingredient-" + index.ToString()]);
                    newIngredient.Save();
                    string newAmount = Request.Form["ingredient-amount-" + index.ToString()];
                    newRecipe.AddIngredient(newIngredient, newAmount);
                }
                Dictionary <string, object> model = ModelMaker();
                model.Add("recipe", newRecipe);
                return(View["recipe.cshtml", model]);
            };


            Post["/recipes/{id}/add-category"] = parameters => {
                Recipe   foundRecipe   = Recipe.Find(parameters.id);
                Category foundCategory = Category.Find(Request.Form["new-category"]);
                foundRecipe.AddCategory(foundCategory);
                Dictionary <string, object> model = ModelMaker();
                model.Add("recipe", Recipe.Find(parameters.id));
                return(View["recipe.cshtml", model]);
            };

            Get["/categories"] = _ => {
                return(View["categories.cshtml", ModelMaker()]);
            };

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

            Delete["/categories"] = _ => {
                Category.DeleteAll();
                return(View["recipes.cshtml", ModelMaker()]);
            };

            Get["/categories/{id}"] = parameters => {
                Category foundCategory = Category.Find(parameters.id);
                return(View["category.cshtml", foundCategory]);
            };

            Patch["/categories/{id}"] = parameters => {
                Category foundCategory = Category.Find(parameters.id);
                foundCategory.Update(Request.Form["update-category-name"]);
                return(View["categories.cshtml", ModelMaker()]);
            };

            Delete["/categories/{id}"] = parameters => {
                Category foundCategory = Category.Find(parameters.id);
                foundCategory.Delete();
                return(View["categories.cshtml", ModelMaker()]);
            };

            Get["/ingredients"] = _ => {
                return(View["ingredients.cshtml", ModelMaker()]);
            };

            Post["/ingredients"] = _ => {
                Ingredient newIngredient = new Ingredient(Request.Form["ingredient-name"]);
                newIngredient.Save();
                return(View["ingredients.cshtml", ModelMaker()]);
            };

            Delete["/ingredients"] = _ => {
                Ingredient.DeleteAll();
                return(View["ingredients.cshtml", ModelMaker()]);
            };

            Get["/ingredients/{id}"] = parameters => {
                Ingredient foundIngredient = Ingredient.Find(parameters.id);
                return(View["ingredient.cshtml", foundIngredient]);
            };

            Patch["/ingredients/{id}"] = parameters => {
                Ingredient foundIngredient = Ingredient.Find(parameters.id);
                foundIngredient.Update(Request.Form["update-ingredient-name"]);
                return(View["ingredients.cshtml", ModelMaker()]);
            };

            Delete["/ingredients/{id}"] = parameters => {
                Ingredient foundIngredient = Ingredient.Find(parameters.id);
                foundIngredient.Delete();
                return(View["ingredients.cshtml", ModelMaker()]);
            };
        }