public void MapTopicContainerMapsCommentsToQuestion() { var post1 = new Post(1) { ParentPostID = 0 }; var post2 = new Post(2) { IsFirstInTopic = true }; var post3 = new Post(3) { ParentPostID = 0 }; var post4 = new Post(4) { ParentPostID = 1 }; var post5 = new Post(5) { ParentPostID = 2 }; var post6 = new Post(6) { ParentPostID = 2 }; var post7 = new Post(7) { ParentPostID = 3 }; var posts = new List<Post> { post1, post2, post3, post4, post5, post6, post7 }; var topicContainer = new TopicContainer { Posts = posts, Topic = new Topic(1234)}; var service = GetService(); var result = service.MapTopicContainerForQA(topicContainer); Assert.IsTrue(result.QuestionPostWithComments.Children.Count == 2); Assert.IsTrue(result.QuestionPostWithComments.Children.Contains(post5)); Assert.IsTrue(result.QuestionPostWithComments.Children.Contains(post6)); }
public void MapTopicContainerOrdersAnswersByVoteThenDate() { var post1 = new Post(1) { IsFirstInTopic = true }; var post2 = new Post(2) { Votes = 7, PostTime = new DateTime(2000, 1, 1) }; var post3 = new Post(3) { Votes = 7, PostTime = new DateTime(2000, 2, 1) }; var post4 = new Post(4) { Votes = 2 }; var post5 = new Post(5) { Votes = 3 }; var post6 = new Post(6) { Votes = 8 }; var post7 = new Post(7) { Votes = 5 }; var posts = new List<Post> { post1, post2, post3, post4, post5, post6, post7 }; var topic = new Topic(123) { AnswerPostID = null }; var topicContainer = new TopicContainer { Posts = posts, Topic = topic }; var service = GetService(); var result = service.MapTopicContainerForQA(topicContainer); Assert.AreSame(post6, result.AnswersWithComments[0].Post); Assert.AreSame(post3, result.AnswersWithComments[1].Post); Assert.AreSame(post2, result.AnswersWithComments[2].Post); Assert.AreSame(post7, result.AnswersWithComments[3].Post); Assert.AreSame(post5, result.AnswersWithComments[4].Post); Assert.AreSame(post4, result.AnswersWithComments[5].Post); }
public void MapTopicContainerThrowsWithMoreThanOneFirstInTopicPost() { var posts = new List<Post> { new Post(1) {IsFirstInTopic = true}, new Post(2) {IsFirstInTopic = true} }; var topicContainer = new TopicContainer { Posts = posts, Topic = new Topic(123) }; var service = GetService(); Assert.Throws<InvalidOperationException>(() => service.MapTopicContainerForQA(topicContainer)); }
public void MapTopicContainerSetsQuestionsWithNoParentAsAnswers() { var post1 = new Post(1) {ParentPostID = 0}; var post2 = new Post(2) {IsFirstInTopic = true}; var post3 = new Post(3) {ParentPostID = 2}; var post4 = new Post(4) {ParentPostID = 1}; var post5 = new Post(5) {ParentPostID = 3}; var posts = new List<Post> {post1, post2, post3, post4, post5}; var topicContainer = new TopicContainer { Posts = posts, Topic = new Topic(1234)}; var service = GetService(); var result = service.MapTopicContainerForQA(topicContainer); Assert.AreEqual(1, result.AnswersWithComments.Count); Assert.AreSame(post1, result.AnswersWithComments[0].Post); }
public void MapTopicContainerGrabsFirstPostForQuestion() { var posts = new List<Post> { new Post(1), new Post(2) {IsFirstInTopic = true} }; var topicContainer = new TopicContainer {Posts = posts, Topic = new Topic(123)}; var service = GetService(); var result = service.MapTopicContainerForQA(topicContainer); Assert.AreEqual(2, result.QuestionPostWithComments.Post.PostID); }
public void MapTopicContainerForQAMapsBaseProperties() { var topicContainer = new TopicContainer { Forum = new Forum(1), Topic = new Topic(2), Posts = new List<Post> {new Post(123) { IsFirstInTopic = true }}, PagerContext = new PagerContext(), PermissionContext = new ForumPermissionContext(), IsSubscribed = true, IsFavorite = true, Signatures = new Dictionary<int, string>(), Avatars = new Dictionary<int, int>(), VotedPostIDs = new List<int>() }; var service = GetService(); var result = service.MapTopicContainerForQA(topicContainer); Assert.AreSame(topicContainer.Forum, result.Forum); Assert.AreSame(topicContainer.Topic, result.Topic); Assert.AreSame(topicContainer.Posts, result.Posts); Assert.AreSame(topicContainer.PagerContext, result.PagerContext); Assert.AreSame(topicContainer.PermissionContext, result.PermissionContext); Assert.IsTrue(topicContainer.IsSubscribed); Assert.IsTrue(topicContainer.IsFavorite); Assert.AreSame(topicContainer.Signatures, result.Signatures); Assert.AreSame(topicContainer.Avatars, result.Avatars); Assert.AreSame(topicContainer.VotedPostIDs, result.VotedPostIDs); }
public void MapTopicContainerMapsLastReadTimeToQuestionAndAnswerSets() { var post1 = new Post(1) { ParentPostID = 0 }; var post2 = new Post(2) { IsFirstInTopic = true }; var post3 = new Post(3) { ParentPostID = 0 }; var post4 = new Post(4) { ParentPostID = 1 }; var post5 = new Post(5) { ParentPostID = 2 }; var post6 = new Post(6) { ParentPostID = 3 }; var post7 = new Post(7) { ParentPostID = 3 }; var posts = new List<Post> { post1, post2, post3, post4, post5, post6, post7 }; var lastRead = new DateTime(2000, 1, 1); var topicContainer = new TopicContainer { Posts = posts, Topic = new Topic(1234), LastReadTime = lastRead }; var service = GetService(); var result = service.MapTopicContainerForQA(topicContainer); Assert.AreEqual(lastRead, result.AnswersWithComments[0].LastReadTime); Assert.AreEqual(lastRead, result.AnswersWithComments[1].LastReadTime); Assert.AreEqual(lastRead, result.QuestionPostWithComments.LastReadTime); }
public void MapTopicContainerDoesNotMapCommentsForTopQuestionAsReplies() { var post1 = new Post(1) { ParentPostID = 0 }; var post2 = new Post(2) { IsFirstInTopic = true }; var post3 = new Post(3) { ParentPostID = 0 }; var post4 = new Post(4) { ParentPostID = 1 }; var post5 = new Post(5) { ParentPostID = 2 }; var post6 = new Post(6) { ParentPostID = 3 }; var post7 = new Post(7) { ParentPostID = 3 }; var posts = new List<Post> { post1, post2, post3, post4, post5, post6, post7 }; var topicContainer = new TopicContainer { Posts = posts, Topic = new Topic(1234) }; var service = GetService(); var result = service.MapTopicContainerForQA(topicContainer); Assert.IsFalse(result.AnswersWithComments.Any(x => x.Post.PostID == post5.PostID)); }
public TopicContainerForQA MapTopicContainerForQA(TopicContainer topicContainer) { var result = new TopicContainerForQA { Forum = topicContainer.Forum, Topic = topicContainer.Topic, Posts = topicContainer.Posts, PagerContext = topicContainer.PagerContext, PermissionContext = topicContainer.PermissionContext, IsSubscribed = topicContainer.IsSubscribed, IsFavorite = topicContainer.IsFavorite, Signatures = topicContainer.Signatures, Avatars = topicContainer.Avatars, VotedPostIDs = topicContainer.VotedPostIDs }; try { var questionPost = result.Posts.Single(x => x.IsFirstInTopic); var questionComments = result.Posts.Where(x => x.ParentPostID == questionPost.PostID).ToList(); result.QuestionPostWithComments = new PostWithChildren { Post = questionPost, Children = questionComments, LastReadTime = topicContainer.LastReadTime }; } catch (InvalidOperationException) { throw new InvalidOperationException(String.Format("There is no post marked as FirstInTopic for TopicID {0}.", topicContainer.Topic.TopicID)); } var answers = result.Posts.Where(x => !x.IsFirstInTopic && (x.ParentPostID == 0)).OrderByDescending(x => x.Votes).ThenByDescending(x => x.PostTime).ToList(); if (topicContainer.Topic.AnswerPostID.HasValue) { var acceptedAnswer = answers.SingleOrDefault(x => x.PostID == topicContainer.Topic.AnswerPostID.Value); if (acceptedAnswer != null) { answers.Remove(acceptedAnswer); answers.Insert(0, acceptedAnswer); } } result.AnswersWithComments = new List<PostWithChildren>(); foreach (var item in answers) { var comments = result.Posts.Where(x => x.ParentPostID == item.PostID).ToList(); result.AnswersWithComments.Add(new PostWithChildren { Post = item, Children = comments, LastReadTime = topicContainer.LastReadTime }); } return result; }