1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-10-19 04:46:10 +00:00
X10D/X10D.Tests/src/Time/TimeSpanParserTests.cs

33 lines
926 B
C#
Raw Normal View History

using Microsoft.VisualStudio.TestTools.UnitTesting;
using X10D.Time;
namespace X10D.Tests.Time;
[TestClass]
public class TimeSpanParserTests
{
[TestMethod]
public void TryParse_ShouldReturnTrue_GivenWellFormedTimeSpan()
{
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);
}
}