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 void Add_New_Comment_Dont_Save_InValid_Changes() { Mock <ITopicRepository> repositoryTopic = new Mock <ITopicRepository>(); Mock <IIntermediateCategoryRepository> repositoryInter = new Mock <IIntermediateCategoryRepository>(); TopicController controller = new TopicController(repositoryTopic.Object, repositoryInter.Object, () => "ewa2323"); Comment comment = new Comment() { CommentContent = null }; controller.ModelState.AddModelError("CommentContent", "Pole nie może pozostawać puste"); ActionResult result = controller.Add_New_Comment(comment); ViewResult resultView = (ViewResult)result; repositoryTopic.Verify(x => x.Add_Comment(It.IsAny <Comment>(), It.IsAny <string>()), Times.Never); Assert.AreEqual(resultView.ViewName, "Add_New_Comment"); }
public void Add_New_Comment_Test2() { Mock <ITopicRepository> topicRepo = new Mock <ITopicRepository>(); Mock <IIntermediateCategoryRepository> interRepo = new Mock <IIntermediateCategoryRepository>(); TopicController controller = new TopicController(topicRepo.Object, interRepo.Object, () => "koral2323"); RedirectToRouteResult result = controller.Add_New_Comment(new Comment() { CommentContent = "None", CommentID = 1, TopicID = 1 }) as RedirectToRouteResult; Assert.AreEqual(result.RouteValues["action"], "Go_To_Topic"); Assert.AreEqual(result.RouteValues["controller"], "Topic"); Assert.AreEqual(result.RouteValues["id"], 1); Assert.AreNotEqual(result.RouteValues["id"], 3); }