ThisToThat/ThisToThatTests/ToInt16Tests.cs
/// <summary>
/// Makes multiple UInt32 to Int16 or default conversions and asserts that the results are correct.
/// </summary>
Makes multiple UInt32 to Int16 or default conversions and asserts that the results are correct.
Makes multiple UInt32 to Int16 or default conversions and asserts that the results are correct .
[TestMethod, TestCategory("ToInt16 tests")]
        public void TestUInt32ToInt16OrDefault()
        {
            UInt32 source = UInt32.MinValue;
            Assert.IsInstanceOfType(source, typeof(UInt32));
            Int16? result = source.ToInt16OrDefault((short)86);
            Assert.AreEqual((short)0, result);
            Assert.IsInstanceOfType(result, typeof(Int16));
            source = 42u;
            Assert.IsInstanceOfType(source, typeof(UInt32));
            result = source.ToInt16OrDefault((short)86);
            Assert.AreEqual((short)42, result);
            Assert.IsInstanceOfType(result, typeof(Int16));
            source = UInt32.MaxValue;
            Assert.IsInstanceOfType(source, typeof(UInt32));
            result = source.ToInt16OrDefault((short)86);
            Assert.AreEqual((short)86, result);
            Assert.IsInstanceOfType(result, typeof(Int16));
        }
[ TestMethod , TestCategory ( " " ) ] public void TestUInt32ToInt16OrDefault ( ) { UInt32 source = UInt32 . MinValue ; Assert . IsInstanceOfType ( source , typeof ( UInt32 ) ) ; Int16 ? result = source . ToInt16OrDefault ( ( short ) 86 ) ; Assert . AreEqual ( ( short ) 0 , result ) ; Assert . IsInstanceOfType ( result , typeof ( Int16 ) ) ; source = 42u ; Assert . IsInstanceOfType ( source , typeof ( UInt32 ) ) ; result = source . ToInt16OrDefault ( ( short ) 86 ) ; Assert . AreEqual ( ( short ) 42 , result ) ; Assert . IsInstanceOfType ( result , typeof ( Int16 ) ) ; source = UInt32 . MaxValue ; Assert . IsInstanceOfType ( source , typeof ( UInt32 ) ) ; result = source . ToInt16OrDefault ( ( short ) 86 ) ; Assert . AreEqual ( ( short ) 86 , result ) ; Assert . IsInstanceOfType ( result , typeof ( Int16 ) ) ; }
Makes multiple UInt32 to Int16 or default conversions and asserts that the results are correct.
Makes multiple UInt32 to Int16 or default conversions and asserts that the results are correct .
// Test conversion of source type minimum value // 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 (short)86),  // since the source type's maximum value (4294967295) is greater than the target type's maximum value (32767).