84 lines
2.8 KiB
C#
84 lines
2.8 KiB
C#
using BritishHorseRacingApi.Helpers;
|
|
using System;
|
|
using Xunit;
|
|
|
|
namespace BritishHorseRacingApi.Tests
|
|
{
|
|
public class DataConverterHelperTests
|
|
{
|
|
[Theory()]
|
|
[InlineData("1m 24.73s", 1, 24, 73)]
|
|
[InlineData("5m 42s", 5, 42, 0)]
|
|
[InlineData("7m 2.9s", 7, 2, 9)]
|
|
public void TestStopWatchStringConversion(string time, int mins, int seconds, int milliseconds)
|
|
{
|
|
//Arrange
|
|
//Act
|
|
var totalMilliseconds = DataConverterHelper.StopWatchStringToMilliseconds(time);
|
|
//Assert
|
|
var timeSpan = TimeSpan.FromMilliseconds((double)totalMilliseconds);
|
|
Assert.Equal(mins, timeSpan.Minutes);
|
|
Assert.Equal(seconds, timeSpan.Seconds);
|
|
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 15.39s(+0.34s)", 340)]
|
|
[InlineData(null, null)]
|
|
[InlineData(" ", null)]
|
|
public void TestStopwatchStringDifferenceToMilliseconds(string time, double? expectedValue)
|
|
{
|
|
//Arrange
|
|
//Act
|
|
var totalMilliseconds = DataConverterHelper.StopwatchStringDifferenceToMilliseconds(time);
|
|
//Assert
|
|
Assert.Equal(totalMilliseconds, expectedValue);
|
|
}
|
|
|
|
[Theory()]
|
|
[InlineData("1m 1f 104y ", 2084)]
|
|
[InlineData("1f 104y", 324)]
|
|
[InlineData("104y", 104)]
|
|
[InlineData("", null)]
|
|
[InlineData(" ", null)]
|
|
[InlineData(null, null)]
|
|
public void TestDistanceStringToYardsConversion(string distance, int? expectedResult)
|
|
{
|
|
//Arrange
|
|
//Act
|
|
var result = DataConverterHelper.DistanceStringToYards(distance);
|
|
//Assert
|
|
Assert.Equal(expectedResult, result);
|
|
}
|
|
|
|
[Theory()]
|
|
[InlineData("3/5", 1.6)]
|
|
[InlineData("20/1",21)]
|
|
[InlineData("", null)]
|
|
[InlineData(" ", null)]
|
|
[InlineData(null, null)]
|
|
public void TestFractionOddsToDecimal(string value, double? expectedResult)
|
|
{
|
|
//Arrange
|
|
var decimalExpectedValue = (decimal?)expectedResult;
|
|
//Act
|
|
var result = DataConverterHelper.FractionOddsToDecimal(value);
|
|
//Assert
|
|
Assert.Equal(decimalExpectedValue, result);
|
|
}
|
|
}
|
|
}
|