From de6236b9ea322f6f961e99b7555c087e51986aca Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Mon, 2 Sep 2024 16:28:49 +0700 Subject: [PATCH] add HybridDateTimeTests.cs --- .../Core/HybridDateTimeTests.cs | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/SIL.Harmony.Tests/Core/HybridDateTimeTests.cs diff --git a/src/SIL.Harmony.Tests/Core/HybridDateTimeTests.cs b/src/SIL.Harmony.Tests/Core/HybridDateTimeTests.cs new file mode 100644 index 0000000..9c5a16a --- /dev/null +++ b/src/SIL.Harmony.Tests/Core/HybridDateTimeTests.cs @@ -0,0 +1,77 @@ +using SIL.Harmony.Core; + +namespace SIL.Harmony.Tests.Core; + +public class HybridDateTimeTests +{ + [Fact] + public void Equals_TrueWhenTheSame() + { + var dateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); + var otherDateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); + + (dateTime == otherDateTime).Should().BeTrue(); + } + + [Fact] + public void Equals_FalseWhenDifferentDateTime() + { + var dateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); + var otherDateTime = new HybridDateTime(new DateTimeOffset(2001, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); + + (dateTime != otherDateTime).Should().BeTrue(); + } + + [Fact] + public void Equals_FalseWhenDifferentCounter() + { + var dateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); + var otherDateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 1); + + dateTime.Should().NotBe(otherDateTime); + } + + [Fact] + public void Constructor_ThrowsArgumentOutOfRangeExceptionWhenCounterIsNegative() + { + Action action = () => new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), -1); + action.Should().Throw(); + } + + [Fact] + public void CompareTo_ReturnsOneWhenOtherIsNull() + { + var dateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); + dateTime.CompareTo(null).Should().Be(1); + } + + [Fact] + public void CompareTo_ReturnsNegativeOneWhenThisIsLessThanOther() + { + var dateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); + var otherDateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 2, 0, 0, 0, TimeSpan.Zero), 0); + + var result = dateTime.CompareTo(otherDateTime); + result.Should().BeLessThan(0); + } + + [Fact] + public void CompareTo_ReturnsZeroWhenThisIsEqualToOther() + { + var dateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); + var otherDateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); + + var result = dateTime.CompareTo(otherDateTime); + result.Should().Be(0); + } + + [Fact] + public void CompareTo_ReturnsOneWhenThisIsGreaterThanOther() + { + var dateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 2, 0, 0, 0, TimeSpan.Zero), 0); + var otherDateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); + + var result = dateTime.CompareTo(otherDateTime); + result.Should().Be(1); + } +} \ No newline at end of file