示例#1
0
        public void ConvUtils_ToUInt32()
        {
            Assert.AreEqual(0U, ConvUtils.ToUInt32Ex(""), "Result differs");
            Assert.AreEqual(55U, ConvUtils.ToUInt32Ex("55"), "Result differs");
            Assert.AreEqual(0x55U, ConvUtils.ToUInt32Ex("0x55"), "Result differs");
            Assert.AreEqual(0x55U, ConvUtils.ToUInt32Ex("0X55"), "Result differs");
            Assert.AreEqual(3U, ConvUtils.ToUInt32Ex("0b11"), "Result differs");
            Assert.AreEqual(5U, ConvUtils.ToUInt32Ex("0B101"), "Result differs");
            Assert.AreEqual(0xFEDCBAU, ConvUtils.ToUInt32Ex("0XFEDCBA"), "Result differs");

            uint?nres;

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

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