Esempio n. 1
0
        public void ConvUtils_ToUShort()
        {
            Assert.AreEqual((ushort)55, ConvUtils.ToUInt16Ex("55"), "Result differs");
            Assert.AreEqual((ushort)0x55, ConvUtils.ToUInt16Ex("0x55"), "Result differs");
            Assert.AreEqual((ushort)0x55, ConvUtils.ToUInt16Ex("0X55"), "Result differs");
            Assert.AreEqual((ushort)3, ConvUtils.ToUInt16Ex("0b11"), "Result differs");
            Assert.AreEqual((ushort)5, ConvUtils.ToUInt16Ex("0B101"), "Result differs");
            Assert.AreEqual((ushort)0xFEDC, ConvUtils.ToUInt16Ex("0XFEDC"), "Result differs");

            ushort?nres;

            nres = ConvUtils.ToNullableUInt16Ex(null);
            Assert.IsNull(nres, "Not null result");
            nres = ConvUtils.ToNullableUInt16Ex(String.Empty);
            Assert.IsNull(nres, "Not null result");
            nres = ConvUtils.ToNullableUInt16Ex("");
            Assert.IsNull(nres, "Not null result");
            nres = ConvUtils.ToNullableUInt16Ex("0xAA");
            Assert.AreEqual((ushort)0xAAU, nres, "Result differs");

            Assert.Throws <OverflowException>(() => ConvUtils.ToUInt16Ex("0xFFFFF"));
            Assert.Throws <OverflowException>(() => ConvUtils.ToUInt16Ex("-1"));
        }