ThisToThat/ThisToThatTests/ToUInt16Tests.cs
/// <summary>
/// Makes multiple UInt32 to nullable UInt16 conversions and asserts that the results are correct.
/// </summary>
Makes multiple UInt32 to nullable UInt16 conversions and asserts that the results are correct.
Makes multiple UInt32 to nullable UInt16 conversions and asserts that the results are correct .
[TestMethod, TestCategory("ToUInt16 tests")]
        public void TestUInt32ToUInt16Nullable()
        {
            UInt32 source = UInt32.MinValue;
            Assert.IsInstanceOfType(source, typeof(UInt32));
            UInt16? result = source.ToUInt16Nullable();
            Assert.AreEqual((ushort)0, result);
            Assert.IsInstanceOfType(result, typeof(UInt16));
            source = 42u;
            Assert.IsInstanceOfType(source, typeof(UInt32));
            result = source.ToUInt16Nullable();
            Assert.AreEqual((ushort)42, result);
            Assert.IsInstanceOfType(result, typeof(UInt16));
            source = UInt32.MaxValue;
            Assert.IsInstanceOfType(source, typeof(UInt32));
            result = source.ToUInt16Nullable();
            Assert.IsNull(result);
        }
[ TestMethod , TestCategory ( " " ) ] public void TestUInt32ToUInt16Nullable ( ) { UInt32 source = UInt32 . MinValue ; Assert . IsInstanceOfType ( source , typeof ( UInt32 ) ) ; UInt16 ? result = source . ToUInt16Nullable ( ) ; Assert . AreEqual ( ( ushort ) 0 , result ) ; Assert . IsInstanceOfType ( result , typeof ( UInt16 ) ) ; source = 42u ; Assert . IsInstanceOfType ( source , typeof ( UInt32 ) ) ; result = source . ToUInt16Nullable ( ) ; Assert . AreEqual ( ( ushort ) 42 , result ) ; Assert . IsInstanceOfType ( result , typeof ( UInt16 ) ) ; source = UInt32 . MaxValue ; Assert . IsInstanceOfType ( source , typeof ( UInt32 ) ) ; result = source . ToUInt16Nullable ( ) ; Assert . IsNull ( result ) ; }
Makes multiple UInt32 to nullable UInt16 conversions and asserts that the results are correct.
Makes multiple UInt32 to nullable UInt16 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 null),  // since the source type's maximum value (4294967295) is greater than the target type's maximum value (65535).