Skip to content

Commit

Permalink
Added a UniqueIdRange.SortOrder property
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Aug 12, 2024
1 parent 6f1b96e commit 4c75b69
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions MailKit/UniqueIdRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
using System.Globalization;
using System.Collections.Generic;

using MailKit.Search;

namespace MailKit {
/// <summary>
/// A range of <see cref="UniqueId"/> items.
Expand Down Expand Up @@ -113,6 +115,17 @@ public UniqueIdRange (UniqueId start, UniqueId end)
this.end = end.Id;
}

/// <summary>
/// Gets the sort order of the unique identifiers.
/// </summary>
/// <remarks>
/// Gets the sort order of the unique identifiers.
/// </remarks>
/// <value>The sort order.</value>
public SortOrder SortOrder {
get { return start <= end ? SortOrder.Ascending : SortOrder.Descending; }
}

/// <summary>
/// Gets the validity, if non-zero.
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions UnitTests/UniqueIdRangeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
//

using MailKit;
using MailKit.Search;

namespace UnitTests {
public class UniqueIdRangeTests
Expand Down Expand Up @@ -55,6 +56,7 @@ public void TestAscending ()
UniqueIdRange uids;

Assert.That (UniqueIdRange.TryParse (example, 20160117, out uids), Is.True, "Failed to parse uids.");
Assert.That (uids.SortOrder, Is.EqualTo (SortOrder.Ascending), "SortOrder");
Assert.That (uids.Validity, Is.EqualTo (20160117), "Validity");
Assert.That (uids.IsReadOnly, Is.True, "IsReadOnly");
Assert.That (uids.Start.Id, Is.EqualTo (1), "Start");
Expand Down Expand Up @@ -98,6 +100,7 @@ public void TestDescending ()
UniqueIdRange uids;

Assert.That (UniqueIdRange.TryParse (example, 20160117, out uids), Is.True, "Failed to parse uids.");
Assert.That (uids.SortOrder, Is.EqualTo (SortOrder.Descending), "SortOrder");
Assert.That (uids.Validity, Is.EqualTo (20160117), "Validity");
Assert.That (uids.IsReadOnly, Is.True, "IsReadOnly");
Assert.That (uids.Start.Id, Is.EqualTo (20), "Start");
Expand Down Expand Up @@ -155,6 +158,7 @@ public void TestParser ()
Assert.That (UniqueIdRange.TryParse ("1:1x", out _), Is.False);

Assert.That (UniqueIdRange.TryParse ("1:*", out var range), Is.True);
Assert.That (range.SortOrder, Is.EqualTo (SortOrder.Ascending), "SortOrder");
Assert.That (range.Min, Is.EqualTo (UniqueId.MinValue));
Assert.That (range.Max, Is.EqualTo (UniqueId.MaxValue));
}
Expand Down

0 comments on commit 4c75b69

Please sign in to comment.