private async Task <CommentSegment> GetCommentSegment(int submissionID, int?parentID, int startingIndex, CommentSortAlgorithm sort) { var q = new QueryCommentSegment(submissionID, parentID, startingIndex, sort).SetUserContext(User); var results = await q.ExecuteAsync(); return(results); }
public void CommentSegment_Anon() { var user = TestHelper.SetPrincipal("TestUser01"); var q = new QueryCommentSegment(_submissionID, null, 0, CommentSortAlgorithm.New); var r = q.Execute(); Assert.IsNotNull(r, "Query returned null"); VerifyCommentSegmentIsAnonProtected(r); }
public void EnsureParentIDNulledCorrectly() { var q = new QueryCommentSegment(100, 0, 101, CommentSortAlgorithm.New); Assert.AreEqual(q.ParentID, null, "Expecting 0 parentID to store as null"); q = new QueryCommentSegment(100, -1, 101, CommentSortAlgorithm.New); Assert.AreEqual(q.ParentID, null, "Expecting -1 parentID to store as null"); q = new QueryCommentSegment(100, 1, 101, CommentSortAlgorithm.New); Assert.AreEqual(q.ParentID, 1, "Expecting 1 parentID to store as 1"); }
private async Task <CommentSegment> GetCommentSegment(int submissionID, int?parentID, int startingIndex, string sort) { //attempt to parse sort var sortAlg = CommentSortAlgorithm.Top; if (!Enum.TryParse(sort, true, out sortAlg)) { sortAlg = CommentSortAlgorithm.Top; } var q = new QueryCommentSegment(submissionID, parentID, startingIndex, sortAlg); var results = await q.ExecuteAsync(); return(results); }
public async Task Test_CommentTreeLoading() { var user = TestHelper.SetPrincipal("TestUser01"); var q = new QueryCommentSegment(_unitSubmissionID, null, null, CommentSortAlgorithm.New); var r = q.Execute(); Assert.IsNotNull(r, "Segment returned null"); Assert.AreEqual(_rootCount, r.Comments.Count, "expected root count off"); foreach (var c in r.Comments) { Assert.IsNull(c.ParentID, "expecting only root comments"); Assert.AreEqual(_nestedCount, c.ChildCount, "Child Count on Root is off"); Assert.AreEqual(_unitSubmissionID, c.SubmissionID); //Test for embedded objects Assert.IsNotNull(c.Children, "Children object is null"); Assert.IsNotNull(c.Children.Comments, "Children Comments object is null"); Assert.AreEqual(_nestedCount, c.Children.TotalCount, "Child comment count off in embedded object"); Action <CommentSegment, int> testSegment = null; testSegment = new Action <CommentSegment, int>((segment, expectedCount) => { Assert.IsNotNull(segment); Assert.AreEqual(expectedCount, segment.TotalCount); foreach (var child in segment.Comments) { Assert.IsNotNull(child, "Comment Null"); Assert.AreEqual(_unitSubmissionID, c.SubmissionID, "Submission of Comment doesn't match tree"); if (child.Children != null && child.Children.TotalCount > 0) { testSegment(child.Children, expectedCount); } } if (segment.Comments.Count > 0) { //Test individual segment and ensure it matches current segment var q2 = new QueryCommentSegment(_unitSubmissionID, segment.Comments.First().ParentID, null, CommentSortAlgorithm.New); //all children should have same parent var segment2 = q2.Execute(); CompareSegments(segment, segment2); } }); testSegment(c.Children, _nestedCount); } }
private void VerifyComment(int commentID, string expectedContent, bool isDeleted) { var queryCommentDirect = new QueryComment(commentID, Caching.CachePolicy.None); var comment = queryCommentDirect.Execute(); Assert.IsNotNull(comment); Assert.IsTrue(comment.Content.Contains(expectedContent)); Assert.AreEqual(isDeleted, comment.IsDeleted); //purge cache to ensure fresh pull Caching.CacheHandler.Instance.Remove(Caching.CachingKey.CommentTree(comment.SubmissionID.Value)); var queryCommentTree = new QueryCommentSegment(comment.SubmissionID.Value); var tree = queryCommentTree.Execute(); var treeComment = tree.Comments.FirstOrDefault(x => x.ID == commentID); Assert.IsNotNull(treeComment); Assert.IsTrue(treeComment.Content.Contains(expectedContent)); Assert.AreEqual(isDeleted, treeComment.IsDeleted); }