Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions WordPressPCL.Tests.Selfhosted/CommentsThreaded_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,11 @@ public async Task CommentsThreaded_Sort_Extension_Desc()
{
// The following comment depth has to be the lower, equal or +1
int ni = i + 1;
System.DateTime idate = threaded[i].Date;
System.DateTime nidate = threaded[ni].Date;
System.DateTime idate = firstLvl[i].Date;
System.DateTime nidate = firstLvl[ni].Date;

// The following comment date has to be older
Assert.IsGreaterThan(threaded[ni].Id, threaded[i].Id);
Assert.IsLessThanOrEqualTo(nidate, idate);
Assert.IsTrue(nidate <= idate);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WordPressPCL.Models;
using WordPressPCL.Utility;

namespace WordPressPCL.Tests.Selfhosted.Utility;

[TestClass]
public class ThreadedCommentsHelper_Tests
{
[TestMethod]
public void ToThreaded_Descending_KeepsTopLevelCommentsInDescendingDateOrder()
{
DateTime olderRootDate = new(2026, 1, 1, 0, 0, 0, DateTimeKind.Utc);
DateTime newerRootDate = new(2026, 1, 2, 0, 0, 0, DateTimeKind.Utc);
DateTime newestChildDate = new(2026, 1, 3, 0, 0, 0, DateTimeKind.Utc);

List<Comment> comments =
[
new Comment { Id = 1, Date = newerRootDate },
new Comment { Id = 2, ParentId = 1, Date = newestChildDate },
new Comment { Id = 3, Date = olderRootDate }
];

List<CommentThreaded>? threaded = comments.ToThreaded(true);

Assert.IsNotNull(threaded);
CollectionAssert.AreEqual(new[] { 1, 2, 3 }, threaded.Select(comment => comment.Id).ToList());

List<CommentThreaded> firstLevel = threaded.Where(comment => comment.Depth == 0).ToList();
CollectionAssert.AreEqual(new[] { 1, 3 }, firstLevel.Select(comment => comment.Id).ToList());
Assert.IsTrue(firstLevel[0].Date >= firstLevel[1].Date);
}
}
Loading