public void IngredientDatabaseEmpty() { //Arrange, act int result = Ingredient.GetAllIngredients().Count; //Assert Assert.Equal(0, result); }
public void Test_SaveAssignsIdToObject() { //Arrange firstIngredient.Save(); //Act Ingredient testIngredient = Ingredient.GetAllIngredients()[0]; int result = firstIngredient.GetIngredientId(); int testId = testIngredient.GetIngredientId(); //Assert Assert.Equal(testId, result); }
public void Test_SaveToDatabase() { // Arrange firstIngredient.Save(); // Act List <Ingredient> result = Ingredient.GetAllIngredients(); List <Ingredient> testList = new List <Ingredient> { firstIngredient }; // Assert Assert.Equal(testList, result); }
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]); }; }