public void Should_Edit_ToDo_Item() { var editedToDo = new ToDo { Title = "Get A LOT MORE milk" }; var resirectToResult = (RedirectToRouteResult)new ToDoController().Edit("Get Milk", editedToDo); Assert.Contains(editedToDo, ToDo.ThingsToBeDone); Assert.AreEqual("Index", resirectToResult.RouteValues["action"]); }
public void Should_Add_ToDo_Item() { var todo = new ToDo { Title = "Learn MVC controller" }; var redirectToRouteResult = (RedirectToRouteResult)new ToDoController().Create(todo); Assert.Contains(todo, ToDo.ThingsToBeDone); Assert.AreEqual("Index", redirectToRouteResult.RouteValues["action"]); }
public ActionResult Create(ToDo toDo) { try { // TODO: Add insert logic here ToDo.ThingsToBeDone.Add(toDo); return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Edit(string oldTitle, ToDo item) { try { // TODO: Add update logic here ToDo.ThingsToBeDone.RemoveAll(aToDo => aToDo.Title == oldTitle); ToDo.ThingsToBeDone.Add(item); return RedirectToAction("Index"); } catch { return View(); } }