ThisToThat/ThisToThatTests/ToUInt16Tests.cs
/// <summary>
/// Makes multiple Int32 to UInt16 or default conversions and asserts that the results are correct.
/// </summary>
Makes multiple Int32 to UInt16 or default conversions and asserts that the results are correct.
Makes multiple Int32 to UInt16 or default conversions and asserts that the results are correct .
[TestMethod, TestCategory("ToUInt16 tests")]
        public void TestInt32ToUInt16OrDefault()
        {
            Int32 source = Int32.MinValue;
            Assert.IsInstanceOfType(source, typeof(Int32));
            UInt16? result = source.ToUInt16OrDefault((ushort)86);
            Assert.AreEqual((ushort)86, result);
            Assert.IsInstanceOfType(result, typeof(UInt16));
            source = 42;
            Assert.IsInstanceOfType(source, typeof(Int32));
            result = source.ToUInt16OrDefault((ushort)86);
            Assert.AreEqual((ushort)42, result);
            Assert.IsInstanceOfType(result, typeof(UInt16));
            source = Int32.MaxValue;
            Assert.IsInstanceOfType(source, typeof(Int32));
            result = source.ToUInt16OrDefault((ushort)86);
            Assert.AreEqual((ushort)86, result);
            Assert.IsInstanceOfType(result, typeof(UInt16));
        }
[ TestMethod , TestCategory ( " " ) ] public void TestInt32ToUInt16OrDefault ( ) { Int32 source = Int32 . MinValue ; Assert . IsInstanceOfType ( source , typeof ( Int32 ) ) ; UInt16 ? result = source . ToUInt16OrDefault ( ( ushort ) 86 ) ; Assert . AreEqual ( ( ushort ) 86 , result ) ; Assert . IsInstanceOfType ( result , typeof ( UInt16 ) ) ; source = 42 ; Assert . IsInstanceOfType ( source , typeof ( Int32 ) ) ; result = source . ToUInt16OrDefault ( ( ushort ) 86 ) ; Assert . AreEqual ( ( ushort ) 42 , result ) ; Assert . IsInstanceOfType ( result , typeof ( UInt16 ) ) ; source = Int32 . MaxValue ; Assert . IsInstanceOfType ( source , typeof ( Int32 ) ) ; result = source . ToUInt16OrDefault ( ( ushort ) 86 ) ; Assert . AreEqual ( ( ushort ) 86 , result ) ; Assert . IsInstanceOfType ( result , typeof ( UInt16 ) ) ; }
Makes multiple Int32 to UInt16 or default conversions and asserts that the results are correct.
Makes multiple Int32 to UInt16 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 (ushort)86),  // since the source type's minimum value (-2147483648) is less than the target type's minimum value (0). // 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 (ushort)86),  // since the source type's maximum value (2147483647) is greater than the target type's maximum value (65535).