public async Task CommentsThreaded_MaxDepth() { var allComments = await _clientAuth.Comments.GetAllCommentsForPost(postid); var threaded = ThreadedCommentsHelper.GetThreadedComments(allComments, 1); Assert.IsNotNull(threaded); var ct0 = threaded.Find(x => x.Id == comment0id); Assert.AreEqual(ct0.Depth, 0); var ct1 = threaded.Find(x => x.Id == comment1id); Assert.AreEqual(ct1.Depth, 1); var ct2 = threaded.Find(x => x.Id == comment2id); Assert.AreEqual(ct2.Depth, 1); var ct3 = threaded.Find(x => x.Id == comment3id); Assert.AreEqual(ct3.Depth, 1); var ct4 = threaded.Find(x => x.Id == comment4id); Assert.AreEqual(ct4.Depth, 1); var ct00 = threaded.Find(x => x.Id == comment00id); Assert.AreEqual(ct00.Depth, 0); }
public async Task CommentsThreaded_MaxDepth() { var allComments = await client.Comments.GetAllCommentsForPost(postid); var threaded = ThreadedCommentsHelper.GetThreadedComments(allComments, 1); Debug.WriteLine($"threaded count: {threaded.Count}"); Assert.IsNotNull(threaded); var ct0 = threaded.Find(x => x.Id == comment0id); Assert.AreEqual(ct0.Depth, 0); Debug.WriteLine(threaded.IndexOf(ct0)); var ct1 = threaded.Find(x => x.Id == comment1id); Assert.AreEqual(ct1.Depth, 1); Debug.WriteLine(threaded.IndexOf(ct1)); var ct2 = threaded.Find(x => x.Id == comment2id); Assert.AreEqual(ct2.Depth, 1); Debug.WriteLine(threaded.IndexOf(ct2)); var ct3 = threaded.Find(x => x.Id == comment3id); Assert.AreEqual(ct3.Depth, 1); Debug.WriteLine(threaded.IndexOf(ct3)); var ct4 = threaded.Find(x => x.Id == comment4id); Assert.AreEqual(ct4.Depth, 1); Debug.WriteLine(threaded.IndexOf(ct4)); var ct00 = threaded.Find(x => x.Id == comment00id); Assert.AreEqual(ct00.Depth, 0); }
public async Task <List <CommentThreaded> > GetCommentsForPost(int postid) { var comments = await _client.Comments.GetAllCommentsForPost(postid); var isDesc = _settingsService.GetSetting("CommentsOrderDesc", () => true, SettingLocality.Roamed); return(ThreadedCommentsHelper.GetThreadedComments(comments, 2, isDesc)); }
public async Task CommentsThreaded_Sort_Extension() { var allComments = await _clientAuth.Comments.GetAllCommentsForPost(postid); Assert.IsTrue(allComments.Count() > 0); //ExtensionMethod var threaded = ThreadedCommentsHelper.ToThreaded(allComments); Debug.WriteLine($"threaded count: {threaded.Count}"); Assert.IsNotNull(threaded); var ct0 = threaded.Find(x => x.Id == comment0id); Assert.AreEqual(ct0.Depth, 0); Debug.WriteLine(threaded.IndexOf(ct0)); var ct1 = threaded.Find(x => x.Id == comment1id); Assert.AreEqual(ct1.Depth, 1); Debug.WriteLine(threaded.IndexOf(ct1)); var ct2 = threaded.Find(x => x.Id == comment2id); Assert.AreEqual(ct2.Depth, 2); Debug.WriteLine(threaded.IndexOf(ct2)); var ct3 = threaded.Find(x => x.Id == comment3id); Assert.AreEqual(ct3.Depth, 3); Debug.WriteLine(threaded.IndexOf(ct3)); var ct4 = threaded.Find(x => x.Id == comment4id); Assert.AreEqual(ct4.Depth, 2); Debug.WriteLine(threaded.IndexOf(ct4)); var ct00 = threaded.Find(x => x.Id == comment00id); Assert.AreEqual(ct00.Depth, 0); //Assert.AreEqual(threaded.Count, threaded.IndexOf(ct00) + 1); for (int i = 0; i < threaded.Count - 1; i++) { // The following comment depth has to be the lower, equal or +1 var ni = i + 1; var id = threaded[i].Depth; var nid = threaded[ni].Depth; var validDepth = (id >= nid || id + 1 == nid); Assert.IsTrue(validDepth); var idate = threaded[i].Date; var nidate = threaded[ni].Date; // The following comment date has to be var validDate = ( // newer idate <= nidate // or older and a child comment || (idate > nidate && id > nid)); Assert.IsTrue(validDate); } }
public async Task <List <CommentThreaded> > GetCommentsForPostAsync(int postid) { var comments = await _client.Comments.Query(new CommentsQueryBuilder { Posts = new[] { postid }, Page = 1, PerPage = 100 }); return(ThreadedCommentsHelper.GetThreadedComments(comments)); }
public async Task CommentsThreaded_Sort() { var client = await ClientHelper.GetAuthenticatedWordPressClient(); var IsValidToken = await client.IsValidJWToken(); Assert.IsTrue(IsValidToken); var post = await client.Posts.Create(new Post() { Title = new Title("Title 1"), Content = new Content("Content PostCreate") }); await Task.Delay(1000); var comment0 = await client.Comments.Create(new Comment() { PostId = post.Id, Content = new Content("orem ipsum dolor sit amet") }); var comment00 = await client.Comments.Create(new Comment() { PostId = post.Id, Content = new Content("r sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam non") }); var comment1 = await client.Comments.Create(new Comment() { PostId = post.Id, ParentId = comment0.Id, Content = new Content("onsetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna ali") }); var comment2 = await client.Comments.Create(new Comment() { PostId = post.Id, ParentId = comment1.Id, Content = new Content("ro eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem i") }); var comment3 = await client.Comments.Create(new Comment() { PostId = post.Id, ParentId = comment2.Id, Content = new Content("tetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam e") }); var comment4 = await client.Comments.Create(new Comment() { PostId = post.Id, ParentId = comment1.Id, Content = new Content("t ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum do") }); var allComments = await client.Comments.GetAllCommentsForPost(post.Id); var threaded = ThreadedCommentsHelper.GetThreadedComments(allComments); Debug.WriteLine($"threaded count: {threaded.Count}"); Assert.IsNotNull(threaded); var ct0 = threaded.Find(x => x.Id == comment0.Id); Assert.AreEqual(ct0.Depth, 0); Debug.WriteLine(threaded.IndexOf(ct0)); var ct1 = threaded.Find(x => x.Id == comment1.Id); Assert.AreEqual(ct1.Depth, 1); Debug.WriteLine(threaded.IndexOf(ct1)); var ct2 = threaded.Find(x => x.Id == comment2.Id); Assert.AreEqual(ct2.Depth, 2); Debug.WriteLine(threaded.IndexOf(ct2)); var ct3 = threaded.Find(x => x.Id == comment3.Id); Assert.AreEqual(ct3.Depth, 3); Debug.WriteLine(threaded.IndexOf(ct3)); var ct4 = threaded.Find(x => x.Id == comment4.Id); Assert.AreEqual(ct4.Depth, 2); Debug.WriteLine(threaded.IndexOf(ct4)); var ct00 = threaded.Find(x => x.Id == comment00.Id); Assert.AreEqual(ct00.Depth, 0); //Assert.AreEqual(threaded.Count, threaded.IndexOf(ct00) + 1); for (int i = 0; i < threaded.Count - 1; i++) { // The following comment depth has to be the lower, equal or +1 var ni = i + 1; var id = threaded[i].Depth; var nid = threaded[ni].Depth; var validDepth = (id >= nid || id + 1 == nid); Assert.IsTrue(validDepth); var idate = threaded[i].Date; var nidate = threaded[ni].Date; // The following comment date has to be newer or older with a lower depth var validDate = (idate <= nidate || (idate > nidate && id > nid)); Assert.IsTrue(validDate); } // cleanup await client.Posts.Delete(post.Id); }
public async Task CommentsThreaded_Sort_Extension_Desc() { var allComments = await _clientAuth.Comments.GetAllCommentsForPost(postid); Assert.IsTrue(allComments.Count() > 0); var threaded = ThreadedCommentsHelper.ToThreaded(allComments, true); // Depth should be the same regardless of desc or asc Assert.IsNotNull(threaded); var ct0 = threaded.Find(x => x.Id == comment0id); Assert.AreEqual(ct0.Depth, 0); var ct1 = threaded.Find(x => x.Id == comment1id); Assert.AreEqual(ct1.Depth, 1); var ct2 = threaded.Find(x => x.Id == comment2id); Assert.AreEqual(ct2.Depth, 2); var ct3 = threaded.Find(x => x.Id == comment3id); Assert.AreEqual(ct3.Depth, 3); var ct4 = threaded.Find(x => x.Id == comment4id); Assert.AreEqual(ct4.Depth, 2); var ct00 = threaded.Find(x => x.Id == comment00id); Assert.AreEqual(ct00.Depth, 0); for (int i = 0; i < threaded.Count - 1; i++) { // The following comment depth has to be the lower, equal or +1 at most var ni = i + 1; var idepth = threaded[i].Depth; var nidepth = threaded[ni].Depth; var niparent = threaded[ni].ParentId; var validDepth = (idepth >= nidepth || idepth + 1 == nidepth); Assert.IsTrue(validDepth); var idate = threaded[i].Date; var nidate = threaded[ni].Date; // The following comment date has to be var validDate = ( // older idate >= nidate // or newer, if it's a direct child comment || (idate < nidate && threaded[ni].ParentId == threaded[i].Id) // or newer, if the comments share the same parent || (idate < nidate && nidepth != 0 && idepth >= nidepth)); Assert.IsTrue(validDate); } // Comments with depth 0 must be ordered desc var firstLvl = threaded.FindAll(x => x.Depth == 0); for (int i = 0; i < firstLvl.Count - 1; i++) { // The following comment depth has to be the lower, equal or +1 var ni = i + 1; var idate = threaded[i].Date; var nidate = threaded[ni].Date; // The following comment date has to be older Assert.IsTrue(threaded[i].Id > threaded[ni].Id); Assert.IsTrue(idate <= nidate); } }