public void GetReadData_CannotHandleNonNumericStrings_ThrowsException(string inputData) { // Arrange var cut = new CsvConverterDefaultDouble(); cut.Initialize(null, new DefaultTypeConverterFactory()); // Act double actual = (double)cut.GetReadData(typeof(double), inputData, "Column1", 1, 1); // Assert Assert.Fail("Exception should be thrown when invalid values are passed into the parser!"); }
public void GetReadData_CanConvertNullableDoublesWithoutAnAttribute_ValuesConverted(string inputData, string expectedAsString) { // Arrange double?expected = string.IsNullOrWhiteSpace(expectedAsString) ? (double?)null : double.Parse(expectedAsString); var cut = new CsvConverterDefaultDouble(); cut.Initialize(null, new DefaultTypeConverterFactory()); // Act double?actual = (double?)cut.GetReadData(typeof(double?), inputData, "Column1", 1, 1); // Assert Assert.AreEqual(expected, actual); }
public void GetReadData_CanRoundToGivenPrecision_NumberRoundedProperly( string inputData, string expectedAsString, int numberOfDecimalPlaces, bool allowRounding) { // Arrange double expected = double.Parse(expectedAsString); var cut = new CsvConverterDefaultDouble(); cut.AllowRounding = allowRounding; cut.Initialize(null, new DefaultTypeConverterFactory()); cut.NumberOfDecimalPlaces = numberOfDecimalPlaces; // Act double actual = (double)cut.GetReadData(typeof(double), inputData, "Column1", 1, 1); // Assert Assert.AreEqual(expected, actual); }
[DataRow(.20, "20%", "P0")] // Differs between windows 10 (20%) & windows 7 (20 %) public void GetWriteData_CanConvertNullableDouble_DoubleConverted(double?inputData, string expectedData, string formatData) { // Arrange // Arrange var cut = new CsvConverterDefaultDouble(); cut.StringFormat = formatData; // Act string actualData = cut.GetWriteData(typeof(double?), inputData, "Column1", 1, 1); // Windows 10 (2,000%) & Windows 7 (2,000 %) format percentages slightly differently // So remove spaces before comparing if (formatData != null && formatData.StartsWith("P")) { actualData = actualData.Replace(" ", ""); } // Assert Assert.AreEqual(expectedData, actualData); }