public void DeleteInstruction() { //create a new cooking instruction var instruction = new CookingInstruction() { Name = "Prepare The Chicken", Instruction = "Cut the chicken into small cubes" }; //add the cooking instruction to the database cookingInstructionRepository.Add(instruction); //find the added instruction var foundInstruction = cookingInstructionRepository.GetAll().ToList(); //found it if (foundInstruction != null) { Assert.AreEqual(1, foundInstruction.Count()); } cookingInstructionRepository.Remove(foundInstruction[0]); //get the count after deletion foundInstruction = cookingInstructionRepository.GetAll().ToList(); //count should be zero Assert.AreEqual(0, foundInstruction.Count()); }
public static CookingInstruction AddCookInstr(CookingInstruction instr) { using (myContext db1 = new myContext()) { var newItem = db1.CookingInstructions.Add(instr); db1.SaveChanges(); return(newItem); } }
public static CookingInstruction UpdateCookingInstr(CookingInstruction UpdatedItem) { var item = db.CookingInstructions.FirstOrDefault(m => m.Id == UpdatedItem.Id); if (item != null) { item.Title = UpdatedItem.Title; item.BackgroundColor = UpdatedItem.BackgroundColor; item.TextColor = UpdatedItem.TextColor; item.IsBold = UpdatedItem.IsBold; item.IsItalic = UpdatedItem.IsItalic; item.FontSize = UpdatedItem.FontSize; item.TextStyle = UpdatedItem.TextStyle; db.Entry(item).State = EntityState.Modified; db.SaveChanges(); } return(item); }
public void AddInstruction() { //create a new cooking instruction var instruction = new CookingInstruction() { Name = "Prepare The Chicken", Instruction = "Cut the chicken into small cubes" }; //add the cooking instruction to the database cookingInstructionRepository.Add(instruction); var foundInstruction = cookingInstructionRepository.GetAll().ToList(); if (foundInstruction != null) { Assert.AreEqual(1, foundInstruction.Count()); Assert.AreEqual(foundInstruction[0].Name, instruction.Name); Assert.AreEqual(foundInstruction[0].Instruction, instruction.Instruction); } }
public JsonResult UpdateCookingInstr(CookingInstruction model) { if (model != null) { var item = DAC.UpdateCookingInstr(model); CookingInstrViewModel viewitem = new CookingInstrViewModel(); viewitem.BackgroundColor = item.BackgroundColor; viewitem.TextColor = item.TextColor; viewitem.TextStyle = item.TextStyle; viewitem.Id = item.Id; viewitem.Title = item.Title; viewitem.FontSize = item.FontSize; if (item.IsBold) { viewitem.fontWeight = "Bold"; } else { viewitem.fontWeight = "normal"; } if (item.IsItalic) { viewitem.fontStyle = "italic"; } else { viewitem.fontStyle = "normal"; } return(Json(viewitem, JsonRequestBehavior.AllowGet)); } else { return(Json("Please add Information", JsonRequestBehavior.AllowGet)); } }
public void AssignCookingInstructionsToRecipe_RecipeNotFoundInstructionFound_ReturnsFalse() { var instruction = new CookingInstruction() { Name = "Deep Fry Chicken", Instruction = "Deep fry the chicken in hot oil until golden brown" }; cookingInstructionRepository.Add(instruction); var foundInstuction = cookingInstructionRepository.GetAll().ToList(); //there should only be one added record in the database Assert.AreEqual(1, foundInstuction.Count()); //add a cooking instruction where cooking instruction is found and recipe is not if (foundInstuction != null) { var added = cookingInstructionRepository.AssignCookingInstructionsToRecipe(456456, foundInstuction[0].CookingInstructionId); //should return false Assert.IsFalse(added); } }
public void UpdateInstruction() { //create a new cooking instruction var instruction = new CookingInstruction() { Name = "Prepare The Chicken", Instruction = "Cut the chicken into small cubes" }; //add the cooking instruction to the database cookingInstructionRepository.Add(instruction); //find the added instruction var foundInstruction = cookingInstructionRepository.Find(instruction => instruction.Name == "Prepare The Chicken") .FirstOrDefault(); //found it if (foundInstruction != null) { //change the values foundInstruction.Name = "Cool Down"; foundInstruction.Instruction = "Let the chicken cool for 15 minutes before serving"; //update it cookingInstructionRepository.Update(foundInstruction); var updatedInstruction = cookingInstructionRepository.GetId(foundInstruction.CookingInstructionId); if (updatedInstruction != null) { Assert.AreEqual(updatedInstruction.CookingInstructionId, foundInstruction.CookingInstructionId); Assert.AreEqual(updatedInstruction.Name, foundInstruction.Name); Assert.AreEqual(updatedInstruction.Instruction, foundInstruction.Instruction); } } }