From d461c464df6eedcc9b173a80f0ee4361976a791e Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sun, 26 Feb 2023 00:46:01 +0000 Subject: [PATCH] Rewrite TimeSpanParserTests The tests previously worked on the assumption that TryParse would throw an exception on null argument. This was changed with 94a841b2fc37c76d8f3f39bca4f735961b4beb9c but the tests were not updated to reflect that --- X10D.Tests/src/Time/TimeSpanParserTests.cs | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/X10D.Tests/src/Time/TimeSpanParserTests.cs b/X10D.Tests/src/Time/TimeSpanParserTests.cs index b671070..04149c5 100644 --- a/X10D.Tests/src/Time/TimeSpanParserTests.cs +++ b/X10D.Tests/src/Time/TimeSpanParserTests.cs @@ -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(() => 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); } }