Skip to content

Commit

Permalink
add HybridDateTimeTests.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-kev committed Sep 2, 2024
1 parent af44a4e commit de6236b
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions src/SIL.Harmony.Tests/Core/HybridDateTimeTests.cs
Original file line number Diff line number Diff line change
@@ -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<ArgumentOutOfRangeException>();
}

[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);
}
}

0 comments on commit de6236b

Please sign in to comment.