-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: DateTimePeriod persists DateTime.Kind of original DateTime (#135)
- Loading branch information
Showing
3 changed files
with
98 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
TournamentManager/TournamentManager.Tests/Importers/ExcludeDateRecordTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using NUnit.Framework; | ||
using TournamentManager.Importers.ExcludeDates; | ||
|
||
namespace TournamentManager.Tests.Importers; | ||
|
||
[TestFixture] | ||
internal class ExcludeDateRecordTests | ||
{ | ||
[Test] | ||
public void Create_Should_Succeed() | ||
{ | ||
var dateTime = DateTime.UtcNow; | ||
// DateTimePeriod truncates milliseconds | ||
var expected = new DateTime( | ||
dateTime.Ticks - (dateTime.Ticks % TimeSpan.TicksPerSecond), | ||
dateTime.Kind | ||
); | ||
|
||
var record = new ExcludeDateRecord { | ||
Period = new DateTimePeriod(dateTime, dateTime.AddDays(1)), | ||
Reason = "Any reason" | ||
}; | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.That(record.Period.Start, Is.EqualTo(expected)); | ||
Assert.That(record.Period.End, Is.EqualTo(expected.AddDays(1))); | ||
Assert.That(record.Reason, Is.EqualTo("Any reason")); | ||
Assert.That(record.ToString(), Is.EqualTo($"{expected:yyyy-MM-dd HH:mm:ss} - {expected.AddDays(1):yyyy-MM-dd HH:mm:ss}: Any reason")); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void Conversion_To_ExcludeMatchDate_Should_Succeed() | ||
{ | ||
var dateTime = new DateTime(2024, 1, 31, 12, 58, 59); | ||
|
||
var record = new ExcludeDateRecord | ||
{ | ||
Period = new DateTimePeriod(dateTime, dateTime.AddDays(1)), | ||
Reason = "Any reason" | ||
}; | ||
|
||
var excludeMatchDate = record.ToExcludeMatchDateEntity(); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.That(excludeMatchDate.DateFrom, Is.EqualTo(dateTime)); | ||
Assert.That(excludeMatchDate.DateTo, Is.EqualTo(dateTime.AddDays(1))); | ||
Assert.That(excludeMatchDate.Reason, Is.EqualTo("Any reason")); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void Conversion_With_Invalid_Data_Should_Fail() | ||
{ | ||
var dateTime = DateTime.MinValue; | ||
|
||
var record = new ExcludeDateRecord | ||
{ | ||
Period = new DateTimePeriod(dateTime, dateTime), | ||
Reason = "" | ||
}; | ||
|
||
Assert.That(() => record.ToExcludeMatchDateEntity(), Throws.TypeOf<ArgumentException>()); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters