public void Recipe_Delete_RemoveObjectFromDatabase() { Recipe testRecipe = new Recipe("Pot Pie", "Microwave it"); testRecipe.Save(); testRecipe.Delete(); Assert.Equal(0, Recipe.GetAll().Count); }
public void Recipe_Save_NoSaveOnDuplicateRecipe() { Recipe testRecipe = new Recipe("Pot Pie", "Microwave it"); testRecipe.Save(); Recipe secondRecipe = new Recipe("Pot Pie", "Microwave it"); secondRecipe.Save(); Assert.Equal(1, Recipe.GetAll().Count); }
public void Recipe_Update_UpdateDatabaseAndLocalObject() { Recipe testRecipe = new Recipe("Pot Pie", "Microwave it"); testRecipe.Save(); testRecipe.Update("Chicken Pot Pie", "Boil it", 4); Recipe expectedRecipe = new Recipe("Chicken Pot Pie", "Boil it", 4, testRecipe.GetId()); Assert.Equal(expectedRecipe, Recipe.Find(testRecipe.GetId())); }
public void Find_OneRecipeId_ReturnRecipeFromDatabase() { //Arrange Recipe testRecipe = new Recipe("Pot Pie", "Microwave it"); testRecipe.Save(); //Act Recipe foundRecipe = Recipe.Find(testRecipe.GetId()); //Assert Assert.Equal(testRecipe, foundRecipe); }
public void Save_OneRecipe_RecipeSavedWithCorrectID() { //Arrange Recipe testRecipe = new Recipe("Pot Pie", "Microwave it"); testRecipe.Save(); Recipe savedRecipe = Recipe.GetAll()[0]; //Act int output = savedRecipe.GetId(); int verify = testRecipe.GetId(); //Assert Assert.Equal(verify, output); }
public void Save_OneRecipe_RecipeSavedToDatabase() { //Arrange Recipe testRecipe = new Recipe("Pot Pie", "Microwave it"); //Act testRecipe.Save(); List <Recipe> output = Recipe.GetAll(); List <Recipe> verify = new List <Recipe> { testRecipe }; //Assert Assert.Equal(verify, output); }
public void SearchName_Name_ReturnRecipeFromDatabase() { //Arrange Recipe testRecipe = new Recipe("Pot Pie", "Microwave it"); testRecipe.Save(); //Act List <Recipe> output = Recipe.SearchName("Pot Pie"); List <Recipe> verify = new List <Recipe> { testRecipe }; //Assert Assert.Equal(verify, output); }
public void Category_GetRecipesByCategory_ReturnListOfRecipes() { //Arrange Recipe testRecipe = new Recipe("Pot Pie", "Microwave it"); testRecipe.Save(); Category testCategory = new Category("Peasant"); testCategory.Save(); //Act testRecipe.AddCategory(testCategory); //Assert Assert.Equal(testRecipe, testCategory.GetRecipesByCategory()[0]); }
public void SaveGetAll_ManyRecipes_ReturnListOfRecipes() { //Arrange Recipe recipeOne = new Recipe("Pot Pie", "Microwave it"); recipeOne.Save(); Recipe recipeTwo = new Recipe("Instant Ramen", "Boil it"); recipeTwo.Save(); //Act List <Recipe> output = Recipe.GetAll(); List <Recipe> verify = new List <Recipe> { recipeOne, recipeTwo }; //Assert Assert.Equal(verify, output); }
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); }
public void AddCategory_OneRecipe_CategoryAddedToJoinTable() { //Arrange Recipe testRecipe = new Recipe("Pot Pie", "Microwave it"); testRecipe.Save(); Category testCategory = new Category("Peasant"); testCategory.Save(); testRecipe.AddCategory(testCategory); //Act List <Category> output = testRecipe.GetCategory(); List <Category> verify = new List <Category> { testCategory }; //Assert Assert.Equal(verify, output); }
public void AddRecipe_OneCategory_RecipeAddedToJoinTable() { //Arrange Category testCategory = new Category("Peasant"); testCategory.Save(); Recipe testRecipe = new Recipe("Pot Pie", "Microwave it"); testRecipe.Save(); testCategory.AddRecipe(testRecipe); //Act List <Recipe> output = testCategory.GetRecipesByCategory(); List <Recipe> verify = new List <Recipe> { testRecipe }; //Assert Assert.Equal(verify, output); }
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); }
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); }
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()]); }; }