Ejemplo n.º 1
0
        public void CategoryDatabaseEmpty()
        {
            //Arrange, act
            int result = Category.GetAllCategories().Count;

            //Assert
            Assert.Equal(0, result);
        }
Ejemplo n.º 2
0
        public void Test_SaveAssignsIdToObject()
        {
            //Arrange
            firstCategory.Save();

            //Act
            Category testCategory = Category.GetAllCategories()[0];

            int result = firstCategory.GetCategoryId();
            int testId = testCategory.GetCategoryId();

            //Assert
            Assert.Equal(testId, result);
        }
Ejemplo n.º 3
0
        public void Test_SaveToDatabase()
        {
            // Arrange
            firstCategory.Save();

            // Act
            List <Category> result   = Category.GetAllCategories();
            List <Category> testList = new List <Category> {
                firstCategory
            };

            // Assert
            Assert.Equal(testList, result);
        }
Ejemplo n.º 4
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };
            Get["/categories"] = _ => {
                return(View["categories.cshtml"]);
            };

            Get["/recipes"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                List <Recipe>   allRecipes        = Recipe.GetAllRecipes();
                List <Category> allCategories     = Category.GetAllCategories();
                model.Add("recipe", allRecipes);
                model.Add("categories", allCategories);
                return(View["recipes.cshtml", model]);
            };
            Post["/recipes"] = _ => {
                Console.WriteLine("Ckeck returns: " + Request.Form["boxtest"]);

                Dictionary <string, object> model = new Dictionary <string, object>();
                Recipe   newRecipe   = new Recipe(Request.Form["recipe-name"], Request.Form["recipe-description"], Request.Form["recipe-instructions"]);
                Category newCategory = Category.Find(Request.Form["assign-category"]);
                newRecipe.Save();
                newRecipe.AddCategory(newCategory);
                List <Category> allCategories = Category.GetAllCategories();
                List <Recipe>   allRecipes    = Recipe.GetAllRecipes();

                model.Add("recipe", allRecipes);
                model.Add("categories", allCategories);
                return(View["recipes.cshtml", model]);
            };

            Get["/categories"] = _ => {
                List <Category> allCategories = Category.GetAllCategories();
                return(View["categories.cshtml", allCategories]);
            };
            Post["/categories"] = _ => {
                Category newCategory = new Category(Request.Form["category-name"]);
                newCategory.Save();
                List <Category> allCategories = Category.GetAllCategories();
                return(View["categories.cshtml", allCategories]);
            };
            Get["/category/{id}/{name}"] = parameters => {
                Category      selectedCategory = Category.Find(parameters.id);
                List <Recipe> allRecipes       = selectedCategory.GetRecipes();

                Dictionary <string, object> model = new Dictionary <string, object>();
                model.Add("category", selectedCategory);
                model.Add("recipes", allRecipes);

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

            Get["/recipe/{id}/{name}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Recipe            selectedRecipe  = Recipe.Find(parameters.id);
                List <Ingredient> ingredientList  = Ingredient.GetAllIngredients();
                model.Add("recipe", selectedRecipe);
                model.Add("instructions", selectedRecipe.SplitInstructions());
                model.Add("ingredients", ingredientList);
                return(View["recipe.cshtml", model]);
            };

            Post["/recipe/{id}/{name}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                // Ingredient newIngredient = new Ingredient();
                Recipe            selectedRecipe    = Recipe.Find(parameters.id);
                List <Ingredient> recipeIngredients = new List <Ingredient> {
                };
                if (Request.Form["ingredient"] != "")
                {
                    var newIngredient = Request.Form["ingredient"];
                    foreach (var ingredient in Ingredient.Find(newIngredient))
                    {
                        selectedRecipe.AddIngredient(ingredient);
                    }
                }
                model.Add("recipe", selectedRecipe);
                model.Add("instructions", selectedRecipe.SplitInstructions());
                model.Add("ingredients", recipeIngredients);
                return(View["recipe.cshtml", model]);
            };
        }