public void Add_New_Comment_Test() { ICollection <Comment> commentList = new List <Comment>() { new Comment() { ApplicationUserID = "1", CommentContent = "Comment Content", CommentID = 1, TopicID = 2 } }; Mock <ITopicRepository> topicRepo = new Mock <ITopicRepository>(); Mock <IIntermediateCategoryRepository> interRepo = new Mock <IIntermediateCategoryRepository>(); topicRepo.Setup(t => t.Get(3)).Returns(new Topic { TopicId = 3, TopicData = "Data 3", TopicName = "Topic 3", IntermediateCategoryId = 1, Comment = commentList }); TopicController controller = new TopicController(topicRepo.Object, interRepo.Object); AddingCommentViewModel result = (AddingCommentViewModel)((controller.Add_New_Comment(3) as ViewResult).Model); AddingCommentViewModel check = new AddingCommentViewModel(); check.topic = new Topic { TopicId = 3, TopicData = "Data 3", TopicName = "Topic 3", IntermediateCategoryId = 1, Comment = commentList }; Assert.AreEqual(result.topic.TopicId, check.topic.TopicId); }
public ActionResult AddComment(int?itemId, string type) { AddingCommentViewModel viewModel = new AddingCommentViewModel { itemId = (int)itemId, itemType = type, commentCount = questionHelper.commentCount }; questionHelper.commentCount++; return(View(viewModel)); }
public ActionResult Add_New_Comment(int id) { //Topic topic = repository.Get_Topic_By_Id(id); Topic topic = repository.Get(id); AddingCommentViewModel adding = new AddingCommentViewModel(); adding.topic = topic; return(View(adding)); }
public ActionResult Add_New_Comment(Comment comment) { if (!ModelState.IsValid) { Topic topic = repository.Get(comment.TopicID); AddingCommentViewModel adding = new AddingCommentViewModel(); adding.topic = topic; return(View("Add_New_Comment", adding)); } //string UserId = User.Identity.GetUserId(); string UserId = GetUserId(); repository.Add_Comment(comment, UserId); return(RedirectToAction("Go_To_Topic", new { controller = "Topic", action = "Go_To_Topic", id = comment.TopicID })); }