ThisToThat/ThisToThatTests/ToDecimalTests.cs
/// <summary>
/// Makes multiple Double to nullable Decimal conversions and asserts that the results are correct.
/// </summary>
Makes multiple Double to nullable Decimal conversions and asserts that the results are correct.
Makes multiple Double to nullable Decimal conversions and asserts that the results are correct .
[TestMethod, TestCategory("ToDecimal tests")]
        public void TestDoubleToDecimalNullable()
        {
            Double source = Double.MinValue;
            Assert.IsInstanceOfType(source, typeof(Double));
            Decimal? result = source.ToDecimalNullable();
            Assert.IsNull(result);
            source = 42d;
            Assert.IsInstanceOfType(source, typeof(Double));
            result = source.ToDecimalNullable();
            Assert.AreEqual(42m, result);
            Assert.IsInstanceOfType(result, typeof(Decimal));
            source = Double.MaxValue;
            Assert.IsInstanceOfType(source, typeof(Double));
            result = source.ToDecimalNullable();
            Assert.IsNull(result);
        }
[ TestMethod , TestCategory ( " " ) ] public void TestDoubleToDecimalNullable ( ) { Double source = Double . MinValue ; Assert . IsInstanceOfType ( source , typeof ( Double ) ) ; Decimal ? result = source . ToDecimalNullable ( ) ; Assert . IsNull ( result ) ; source = 42d ; Assert . IsInstanceOfType ( source , typeof ( Double ) ) ; result = source . ToDecimalNullable ( ) ; Assert . AreEqual ( 42m , result ) ; Assert . IsInstanceOfType ( result , typeof ( Decimal ) ) ; source = Double . MaxValue ; Assert . IsInstanceOfType ( source , typeof ( Double ) ) ; result = source . ToDecimalNullable ( ) ; Assert . IsNull ( result ) ; }
Makes multiple Double to nullable Decimal conversions and asserts that the results are correct.
Makes multiple Double to nullable Decimal conversions and asserts that the results are correct .
// Test conversion of source type minimum value // Here we would expect this conversion to fail (and return null),  // since the source type's minimum value (-1.7976931348623157E+308) is less than the target type's minimum value (-79228162514264337593543950335). // Test conversion of source type value 42 to target type // Test conversion of source type maximum value // Here we would expect this conversion to fail (and return null),  // since the source type's maximum value (1.7976931348623157E+308) is greater than the target type's maximum value (79228162514264337593543950335).