public void Delete(BlogPost post) { var toDelete = GetById(post.Id); if (toDelete != null) { _blogPosts.Remove(toDelete); } }
public ActionResult Edit(BlogPost model) { if (ModelState.IsValid) { _repo.Edit(model); return RedirectToAction("Index"); } return View(model); }
public void Edit(BlogPost post) { var oldPost = GetById(post.Id); if (oldPost == null) { return; } oldPost.Title = post.Title; oldPost.Content = post.Content; }
public void Edit_Post_ReturnsViewWithModelWhenModelStateIsInvalid() { var repo = Mock.Create<IBlogPostRepository>(); var controller = new BlogController(repo); var post = new BlogPost { Id = 1, Title = "", Content = "", DateCreated = DateTime.Now }; controller.ViewData.ModelState.AddModelError("key", "error message"); var result = (ViewResult)controller.Edit(post); Assert.AreEqual(post, result.Model as BlogPost); }
public void Edit_Post_EditOnRepositoryIsCalled() { var repo = Mock.Create<IBlogPostRepository>(); var controller = new BlogController(repo); Mock.Arrange(() => repo.Edit(Arg.IsAny<BlogPost>())) .MustBeCalled(); var post = new BlogPost { Id = 1, Title = "", Content = "", DateCreated = DateTime.Now }; var result = controller.Edit(post); Mock.Assert(repo); Assert.IsTrue(result is RedirectToRouteResult); }