ThisToThat/ThisToThatTests/ToDecimalTests.cs
/// <summary>
/// Makes multiple Single to Decimal or default conversions and asserts that the results are correct.
/// </summary>
Makes multiple Single to Decimal or default conversions and asserts that the results are correct.
Makes multiple Single to Decimal or default conversions and asserts that the results are correct .
[TestMethod, TestCategory("ToDecimal tests")]
        public void TestSingleToDecimalOrDefault()
        {
            Single source = Single.MinValue;
            Assert.IsInstanceOfType(source, typeof(Single));
            Decimal? result = source.ToDecimalOrDefault(86m);
            Assert.AreEqual(86m, result);
            Assert.IsInstanceOfType(result, typeof(Decimal));
            source = 42f;
            Assert.IsInstanceOfType(source, typeof(Single));
            result = source.ToDecimalOrDefault(86m);
            Assert.AreEqual(42m, result);
            Assert.IsInstanceOfType(result, typeof(Decimal));
            source = Single.MaxValue;
            Assert.IsInstanceOfType(source, typeof(Single));
            result = source.ToDecimalOrDefault(86m);
            Assert.AreEqual(86m, result);
            Assert.IsInstanceOfType(result, typeof(Decimal));
        }
[ TestMethod , TestCategory ( " " ) ] public void TestSingleToDecimalOrDefault ( ) { Single source = Single . MinValue ; Assert . IsInstanceOfType ( source , typeof ( Single ) ) ; Decimal ? result = source . ToDecimalOrDefault ( 86m ) ; Assert . AreEqual ( 86m , result ) ; Assert . IsInstanceOfType ( result , typeof ( Decimal ) ) ; source = 42f ; Assert . IsInstanceOfType ( source , typeof ( Single ) ) ; result = source . ToDecimalOrDefault ( 86m ) ; Assert . AreEqual ( 42m , result ) ; Assert . IsInstanceOfType ( result , typeof ( Decimal ) ) ; source = Single . MaxValue ; Assert . IsInstanceOfType ( source , typeof ( Single ) ) ; result = source . ToDecimalOrDefault ( 86m ) ; Assert . AreEqual ( 86m , result ) ; Assert . IsInstanceOfType ( result , typeof ( Decimal ) ) ; }
Makes multiple Single to Decimal or default conversions and asserts that the results are correct.
Makes multiple Single to Decimal or default 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 the default value of 86m),  // since the source type's minimum value (-3.40282347E+38) 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 the default value of 86m),  // since the source type's maximum value (3.40282347E+38) is greater than the target type's maximum value (79228162514264337593543950335).