コード例 #1
0
        public void GetWriteData_CanCovertDecimalToPercentage(string expectedResult, string inputDataString,
                                                              int numberOfDecimalPlaces)
        {
            // Arrange
            decimal inputData = decimal.Parse(inputDataString);

            var attribute = new CsvConverterNumberAttribute();

            attribute.NumberOfDecimalPlaces = numberOfDecimalPlaces;

            var classUnderTest = new CsvConverterPercentage();

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

            // Act
            string actual = classUnderTest.GetWriteData(typeof(decimal), inputData, ColumName, ColumnIndex, RowNumber);

            // Windows 7 and Windows 10 format strings differently so remove the space so that for the test it doesn't matter
            if (actual != null)
            {
                actual = actual.Replace(" ", "");
            }


            // Assert
            Assert.AreEqual(expectedResult, actual);
        }
コード例 #2
0
        public void GetReadData_CannotCovertJunkStrings()
        {
            // Arrange
            var classUnderTest = new CsvConverterPercentage();

            classUnderTest.Initialize(null, new DefaultTypeConverterFactory());
            // Act
            classUnderTest.GetReadData(typeof(decimal), "3d5%", ColumName, ColumnIndex, RowNumber);

            // Assert
            throw new Exception("Should have encountered exception above because the string is invalid!");
        }
コード例 #3
0
        public void GetReadData_CanCovertStringWithPercentageSign(string inputData, string expected,
                                                                  int numberOfDecimalPlaces)
        {
            // Arrange
            var attribute = new CsvConverterNumberAttribute();

            attribute.NumberOfDecimalPlaces = numberOfDecimalPlaces;

            var classUnderTest = new CsvConverterPercentage();

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

            decimal expectedResult = decimal.Parse(expected);

            // Act
            var actual = classUnderTest.GetReadData(typeof(decimal), inputData, ColumName, ColumnIndex, RowNumber);

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