예제 #1
0
        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"]);
        }
예제 #2
0
        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"]);
        }
예제 #3
0
 public ActionResult Create(ToDo toDo)
 {
     try
     {
         // TODO: Add insert logic here
         ToDo.ThingsToBeDone.Add(toDo);
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
예제 #4
0
        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();
            }
        }