public void CanSerializeAndDeserialize()
        {
            uint value = uint.MaxValue;
            UIntConverter converter = new UIntConverter();
            byte[] bytes = converter.Serialize(value);

            uint valueFromBytes = converter.Deserialize(bytes);

            Assert.Equal(valueFromBytes, value);
        }
示例#2
0
        public void ValidateconvertToTypeUInt32()
        {
            var value = new UIntConverter("3000000000").ConvertToObject("", CultureInfo.GetCultureInfo("en-IE"));

            Assert.AreEqual(0xB2D05E00, value);
        }
示例#3
0
        public void ValidateReadTypeUInt32()
        {
            var value = new UIntConverter(0xB2D05E00).GetString("", CultureInfo.CurrentCulture);

            Assert.AreEqual("3000000000", value);
        }
        public void UIntConverter_ConvertBack()
        {
            IValueConverter converter;
            object actualValue;
            Type expectedType;

            converter = new UIntConverter();
            expectedType = typeof(uint);

            //
            // Test with null.
            //

            try
            {
                converter.ConvertBack(null);
                Assert.Fail("Expected ArgumentNullException to be thrown.");
            }
            catch (ArgumentNullException)
            {
            }

            //
            // Test with incorrect value.
            //

            try
            {
                converter.ConvertBack("true");
                Assert.Fail("Expected FormatException to be thrown.");
            }
            catch (FormatException)
            {
            }

            try
            {
                converter.ConvertBack("999999999999999");
                Assert.Fail("Expected OverflowException to be thrown.");
            }
            catch (OverflowException)
            {
            }

            //
            // Test with 0.
            //

            actualValue = converter.ConvertBack("0");
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual(0u, actualValue, "Converted value is incorrect.");

            //
            // Test with positive value.
            //

            actualValue = converter.ConvertBack("1024");
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual(1024u, actualValue, "Converted value is incorrect.");

            //
            // Test with negative value.
            //

            try
            {
                actualValue = converter.ConvertBack("-1024");
                Assert.Fail("Expected OverflowException to be thrown.");
            }
            catch (OverflowException)
            {
            }
        }
        public void UIntConverter_Convert()
        {
            IValueConverter converter;
            object actualValue;
            Type expectedType;

            converter = new UIntConverter();
            expectedType = typeof(string);

            //
            // Test with null.
            //

            try
            {
                converter.Convert(null);
                Assert.Fail("Expected ArgumentNullException to be thrown.");
            }
            catch (ArgumentNullException)
            {
            }

            //
            // Test with incorrect type.
            //

            try
            {
                converter.Convert("true");
                Assert.Fail("Expected ArgumentException to be thrown.");
            }
            catch (ArgumentException)
            {
            }

            //
            // Test with 0.
            //

            actualValue = converter.Convert(0u);
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual("0", actualValue, "Converted value is incorrect.");

            //
            // Test with negative value.
            //

            try
            {
                actualValue = converter.Convert(-1);
                Assert.Fail("Expected ArgumentException to be thrown.");
            }
            catch (ArgumentException)
            {
            }

            //
            // Test with positive value.
            //

            actualValue = converter.Convert(1024u);
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual("1024", actualValue, "Converted value is incorrect.");
        }
        public void UIntConverter_ConvertBack()
        {
            IValueConverter converter;
            object          actualValue;
            Type            expectedType;

            converter    = new UIntConverter();
            expectedType = typeof(uint);

            //
            // Test with null.
            //

            try
            {
                converter.ConvertBack(null);
                Assert.Fail("Expected ArgumentNullException to be thrown.");
            }
            catch (ArgumentNullException)
            {
            }

            //
            // Test with incorrect value.
            //

            try
            {
                converter.ConvertBack("true");
                Assert.Fail("Expected FormatException to be thrown.");
            }
            catch (FormatException)
            {
            }

            try
            {
                converter.ConvertBack("999999999999999");
                Assert.Fail("Expected OverflowException to be thrown.");
            }
            catch (OverflowException)
            {
            }

            //
            // Test with 0.
            //

            actualValue = converter.ConvertBack("0");
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual(0u, actualValue, "Converted value is incorrect.");

            //
            // Test with positive value.
            //

            actualValue = converter.ConvertBack("1024");
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual(1024u, actualValue, "Converted value is incorrect.");

            //
            // Test with negative value.
            //

            try
            {
                actualValue = converter.ConvertBack("-1024");
                Assert.Fail("Expected OverflowException to be thrown.");
            }
            catch (OverflowException)
            {
            }
        }
        public void UIntConverter_Convert()
        {
            IValueConverter converter;
            object          actualValue;
            Type            expectedType;

            converter    = new UIntConverter();
            expectedType = typeof(string);

            //
            // Test with null.
            //

            try
            {
                converter.Convert(null);
                Assert.Fail("Expected ArgumentNullException to be thrown.");
            }
            catch (ArgumentNullException)
            {
            }

            //
            // Test with incorrect type.
            //

            try
            {
                converter.Convert("true");
                Assert.Fail("Expected ArgumentException to be thrown.");
            }
            catch (ArgumentException)
            {
            }

            //
            // Test with 0.
            //

            actualValue = converter.Convert(0u);
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual("0", actualValue, "Converted value is incorrect.");

            //
            // Test with negative value.
            //

            try
            {
                actualValue = converter.Convert(-1);
                Assert.Fail("Expected ArgumentException to be thrown.");
            }
            catch (ArgumentException)
            {
            }

            //
            // Test with positive value.
            //

            actualValue = converter.Convert(1024u);
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual("1024", actualValue, "Converted value is incorrect.");
        }