예제 #1
0
        public void ConvUtils_ToShort()
        {
            Assert.AreEqual((short)55, ConvUtils.ToInt16Ex("55"), "Result differs");
            Assert.AreEqual((short)-55, ConvUtils.ToInt16Ex("-55"), "Result differs");
            Assert.AreEqual((short)0x55, ConvUtils.ToInt16Ex("0x55"), "Result differs");
            Assert.AreEqual((short)0x55, ConvUtils.ToInt16Ex("0X55"), "Result differs");
            Assert.AreEqual((short)3, ConvUtils.ToInt16Ex("0b11"), "Result differs");
            Assert.AreEqual((short)5, ConvUtils.ToInt16Ex("0B101"), "Result differs");
            Assert.AreEqual((short)0x7EDC, ConvUtils.ToInt16Ex("0x7EDC"), "Result differs");
            Assert.AreEqual((short)-0x7EDC, ConvUtils.ToInt16Ex("-0x7EDC"), "Result differs");

            short?nres;

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

            Assert.Throws <OverflowException>(() => ConvUtils.ToInt16Ex("0xFFFF"));
            Assert.Throws <OverflowException>(() => ConvUtils.ToInt16Ex("-0xFFFF"));
        }