コード例 #1
0
        public void CannotCovertJunkStrings_ResultsInAnException()
        {
            // Arrange
            PropertyInfo stringProperty = ReflectionHelper.FindPropertyInfoByName <PercentConverterTest>("SomeStringProperty");

            Assert.IsNotNull(stringProperty, "Cannot find property");

            var data = new PercentConverterTest()
            {
                SomeStringProperty = "3d5%"
            };

            // Act
            var     classUnderTest = new PercentCtodTypeConverter();
            decimal?somePercentage = classUnderTest.Convert(stringProperty, data) as decimal?;

            // Assert
            Assert.Fail("Should have encountered exception above because the string is invalid!");
        }
コード例 #2
0
        public void CannotHandleNonStringFields_ResultsInAnException()
        {
            // Arrange
            PropertyInfo decimalProperty = ReflectionHelper.FindPropertyInfoByName <PercentConverterTest>("SomeDecimalProperty");

            Assert.IsNotNull(decimalProperty, "Cannot find property");

            var data = new PercentConverterTest()
            {
                SomeDecimalProperty = .35m
            };

            // Act
            var     classUnderTest = new PercentCtodTypeConverter();
            decimal?somePercentage = classUnderTest.Convert(decimalProperty, data) as decimal?;

            // Assert
            Assert.Fail("Should have encountered exception above because it cannot handle anything other than a string!");
        }
コード例 #3
0
        public void CanCovertStringWithoutPercentageSign_StringConvertedToDecimal()
        {
            // Arrange
            PropertyInfo stringProperty = ReflectionHelper.FindPropertyInfoByName <PercentConverterTest>("SomeStringProperty");

            Assert.IsNotNull(stringProperty, "Cannot find property");

            var data = new PercentConverterTest()
            {
                SomeStringProperty = "35"
            };

            // Act
            var     classUnderTest = new PercentCtodTypeConverter();
            decimal?somePercentage = classUnderTest.Convert(stringProperty, data) as decimal?;

            // Assert
            Assert.IsNotNull(somePercentage);
            Assert.AreEqual(.35m, somePercentage.Value);
        }