diff --git a/BritishHorseRacingApi.Tests/DataConverterHelperTests.cs b/BritishHorseRacingApi.Tests/DataConverterHelperTests.cs index 3f4919b..71726a1 100644 --- a/BritishHorseRacingApi.Tests/DataConverterHelperTests.cs +++ b/BritishHorseRacingApi.Tests/DataConverterHelperTests.cs @@ -22,6 +22,19 @@ namespace BritishHorseRacingApi.Tests Assert.Equal(milliseconds, timeSpan.Milliseconds); } + [Theory()] + [InlineData("", null)] + [InlineData(null, null)] + [InlineData(" ", null)] + public void TestStopWatchStringConversionForEmpty(string time, double? expectedValue) + { + //Arrange + //Act + var totalMilliseconds = DataConverterHelper.StopWatchStringToMilliseconds(time); + //Assert + Assert.Equal(totalMilliseconds, expectedValue); + } + [Theory()] [InlineData("1m 1f 104y", 2084)] [InlineData("1f 104y", 324)] diff --git a/BritishHorseRacingApi/Helpers/DataConverterHelper.cs b/BritishHorseRacingApi/Helpers/DataConverterHelper.cs index b8b23a0..992089f 100644 --- a/BritishHorseRacingApi/Helpers/DataConverterHelper.cs +++ b/BritishHorseRacingApi/Helpers/DataConverterHelper.cs @@ -9,6 +9,8 @@ namespace BritishHorseRacingApi.Helpers private static Regex _stopwatchTimeRegex = new Regex(@"^(?'minutes'[0-9]*(?=m))?m? ?(?'seconds'[0-9\.]*)s ?(?:\(\+)?(?'lossDifference'[0-9\.]*)(?:s\))?", RegexOptions.Compiled); public static int? StopWatchStringToMilliseconds(string stopwatchValue) { + if (String.IsNullOrWhiteSpace(stopwatchValue)) + return null; var match = _stopwatchTimeRegex.Match(stopwatchValue); var minutes = GetComponent(match, "minutes", 0); var secondsAndMilliseconds = GetComponent(match, "seconds", "0").Split('.');