public void CreateActionShouldCallTheInsertPostMethodOnTheServiceSuccessfully() { Mock<IPostService> postService = new Mock<IPostService>(); var controller = new BlogController(postService.Object); var post = new PostForm { Title = "Title from a test", Content = "Test Content" }; var result = controller.Create(post) as ViewResult; postService.Verify(x => x.InsertPost(It.IsAny<Post>()), Times.Exactly(1)); }
public ActionResult Create(PostForm post) { var newPost = new Post { Title = post.Title, Content = post.Content }; try { //TODO: Remove the hardcoded author name, Get it from the AppHelper newPost.Author = "Khaja Minhajuddin"; newPost.Timestamp = DateTime.Now; _blogService.InsertPost(newPost); } catch { return View(); } return RedirectToAction("Index"); }