コード例 #1
0
        public void GetReadData_CannotHandleNonNumericStrings_ThrowsException(string inputData)
        {
            // Arrange
            var attribute = new CsvConverterNumberAttribute();
            var cut       = new CsvConverterDecimalToInt();

            cut.Initialize(attribute, new DefaultTypeConverterFactory());

            // Act
            decimal actual = (decimal)cut.GetReadData(typeof(decimal), inputData, "Column1", 1, 1);

            // Assert
            Assert.Fail("Exception should be thrown when invalid values are passed into the parser!");
        }
コード例 #2
0
        public void GetReadData_CanConvertNonNullableDecimalsWithoutAnAttribute_ValuesConverted(string inputData, int?expected)
        {
            // Arrange
            var attribute = new CsvConverterNumberAttribute();
            var cut       = new CsvConverterDecimalToInt();

            cut.Initialize(attribute, new DefaultTypeConverterFactory());

            // Act
            int actual = (int)cut.GetReadData(typeof(int), inputData, "Column1", 1, 1);

            // Assert
            Assert.AreEqual(expected, actual);
        }
コード例 #3
0
        [DataRow("58.88", 59, true, 2)] // decimal places are IGNORED during reading!
        public void GetReadData_CanRoundToGivenPrecision_NumberRoundedProperly(string inputData, int?expected,
                                                                               bool allowRounding, int numberOfDecimalPlaces)
        {
            // Arrange
            var attribute = new CsvConverterNumberAttribute()
            {
                AllowRounding = allowRounding, NumberOfDecimalPlaces = numberOfDecimalPlaces
            };
            var cut = new CsvConverterDecimalToInt();

            cut.Initialize(attribute, new DefaultTypeConverterFactory());

            // Act
            int actual = (int)cut.GetReadData(typeof(int), inputData, "Column1", 1, 1);

            // Assert
            Assert.AreEqual(expected, actual);
        }