mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-23 01:28:48 +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:
parent
ba7329febd
commit
d461c464df
@ -7,9 +7,26 @@ namespace X10D.Tests.Time;
|
|||||||
public class TimeSpanParserTests
|
public class TimeSpanParserTests
|
||||||
{
|
{
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TryParse_ShouldThrow_GivenNullString()
|
public void TryParse_ShouldReturnTrue_GivenWellFormedTimeSpan()
|
||||||
{
|
{
|
||||||
string? value = null;
|
bool result = TimeSpanParser.TryParse("3d6h", out TimeSpan timeSpan);
|
||||||
Assert.ThrowsException<ArgumentNullException>(() => TimeSpanParser.TryParse(value!, out _));
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user