From 2c81398877c63afaad765ea068b539011903293b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 7 Apr 2026 10:27:23 +0000 Subject: [PATCH 1/2] Initial plan From 5e30ff77e67e5fe7180c0e3316537f00c4fda51d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 7 Apr 2026 10:39:01 +0000 Subject: [PATCH 2/2] test: stabilize threaded comments ordering checks Agent-Logs-Url: https://github.com/wp-net/WordPressPCL/sessions/a71830fa-e874-4fe6-ab7c-1ecb616d4c79 Co-authored-by: ThomasPe <4225039+ThomasPe@users.noreply.github.com> --- .../CommentsThreaded_Tests.cs | 7 ++-- .../Utility/ThreadedCommentsHelper_Tests.cs | 36 +++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 WordPressPCL.Tests.Selfhosted/Utility/ThreadedCommentsHelper_Tests.cs diff --git a/WordPressPCL.Tests.Selfhosted/CommentsThreaded_Tests.cs b/WordPressPCL.Tests.Selfhosted/CommentsThreaded_Tests.cs index b0c60498..a920a6e4 100644 --- a/WordPressPCL.Tests.Selfhosted/CommentsThreaded_Tests.cs +++ b/WordPressPCL.Tests.Selfhosted/CommentsThreaded_Tests.cs @@ -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); } } diff --git a/WordPressPCL.Tests.Selfhosted/Utility/ThreadedCommentsHelper_Tests.cs b/WordPressPCL.Tests.Selfhosted/Utility/ThreadedCommentsHelper_Tests.cs new file mode 100644 index 00000000..b851722f --- /dev/null +++ b/WordPressPCL.Tests.Selfhosted/Utility/ThreadedCommentsHelper_Tests.cs @@ -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 comments = + [ + new Comment { Id = 1, Date = newerRootDate }, + new Comment { Id = 2, ParentId = 1, Date = newestChildDate }, + new Comment { Id = 3, Date = olderRootDate } + ]; + + List? threaded = comments.ToThreaded(true); + + Assert.IsNotNull(threaded); + CollectionAssert.AreEqual(new[] { 1, 2, 3 }, threaded.Select(comment => comment.Id).ToList()); + + List 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); + } +}