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