This commit is contained in:
@@ -22,6 +22,19 @@ namespace BritishHorseRacingApi.Tests
|
|||||||
Assert.Equal(milliseconds, timeSpan.Milliseconds);
|
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()]
|
[Theory()]
|
||||||
[InlineData("1m 1f 104y", 2084)]
|
[InlineData("1m 1f 104y", 2084)]
|
||||||
[InlineData("1f 104y", 324)]
|
[InlineData("1f 104y", 324)]
|
||||||
|
|||||||
@@ -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);
|
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)
|
public static int? StopWatchStringToMilliseconds(string stopwatchValue)
|
||||||
{
|
{
|
||||||
|
if (String.IsNullOrWhiteSpace(stopwatchValue))
|
||||||
|
return null;
|
||||||
var match = _stopwatchTimeRegex.Match(stopwatchValue);
|
var match = _stopwatchTimeRegex.Match(stopwatchValue);
|
||||||
var minutes = GetComponent(match, "minutes", 0);
|
var minutes = GetComponent(match, "minutes", 0);
|
||||||
var secondsAndMilliseconds = GetComponent(match, "seconds", "0").Split('.');
|
var secondsAndMilliseconds = GetComponent(match, "seconds", "0").Split('.');
|
||||||
|
|||||||
Reference in New Issue
Block a user