1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 19:58:49 +00:00

Rewrite TimeSpanParserTests

The tests previously worked on the assumption that TryParse would throw an exception on null argument. This was changed with 94a841b2fc but the tests were not updated to reflect that
This commit is contained in:
Oliver Booth 2023-02-26 00:46:01 +00:00
parent ba7329febd
commit d461c464df
No known key found for this signature in database
GPG Key ID: 20BEB9DC87961025

View File

@ -7,9 +7,26 @@ namespace X10D.Tests.Time;
public class TimeSpanParserTests
{
[TestMethod]
public void TryParse_ShouldThrow_GivenNullString()
public void TryParse_ShouldReturnTrue_GivenWellFormedTimeSpan()
{
string? value = null;
Assert.ThrowsException<ArgumentNullException>(() => TimeSpanParser.TryParse(value!, out _));
bool result = TimeSpanParser.TryParse("3d6h", out TimeSpan timeSpan);
Assert.IsTrue(result);
Assert.AreEqual(TimeSpan.FromDays(3) + TimeSpan.FromHours(6), timeSpan);
}
[TestMethod]
public void TryParse_ShouldReturnFalse_GivenMalformedTimeSpan()
{
bool result = TimeSpanParser.TryParse("asdf", out TimeSpan timeSpan);
Assert.IsFalse(result);
Assert.AreEqual(default, timeSpan);
}
[TestMethod]
public void TryParse_ShouldReturnFalse_GivenNull()
{
bool result = TimeSpanParser.TryParse(null, out TimeSpan timeSpan);
Assert.IsFalse(result);
Assert.AreEqual(default, timeSpan);
}
}