Provides conversion between strings and Encoding.
Inheritance: System.ComponentModel.TypeConverter
Ejemplo n.º 1
0
        public void ConvertToInteger()
        {
            var converter = new EncodingConverter();
            Assert.IsTrue(converter.CanConvertTo(typeof(int)), "Cannot convert to an integer.");

            var value = (int)converter.ConvertTo(Encoding.UTF8, typeof(int));
            Assert.AreEqual<int>(65001, value, "Could not convert to an integer.");
        }
Ejemplo n.º 2
0
        public void ConvertFromStringPropertyName()
        {
            var converter = new EncodingConverter();
            Assert.IsTrue(converter.CanConvertFrom(typeof(string)), "Cannot convert from a string.");

            var value = (Encoding)converter.ConvertFrom("UTF8");
            Assert.AreEqual<Encoding>(Encoding.UTF8, value, "Could not convert from a string.");
        }
Ejemplo n.º 3
0
        public void ConvertFromNull()
        {
            var converter = new EncodingConverter();
            Assert.IsTrue(converter.CanConvertFrom(typeof(string)), "Cannot convert from a string.");

            var value = (Encoding)converter.ConvertFrom(null);
            Assert.AreEqual<Encoding>(Encoding.Default, value, "Could not convert from a null string.");
        }
Ejemplo n.º 4
0
        public void ConvertFromIntegerCodePage()
        {
            var converter = new EncodingConverter();
            Assert.IsTrue(converter.CanConvertFrom(typeof(int)), "Cannot convert from an integer.");

            var value = (Encoding)converter.ConvertFrom(65001);
            Assert.AreEqual<Encoding>(Encoding.UTF8, value, "Could not convert from an integer.");
        }
Ejemplo n.º 5
0
        public void ConvertToInteger()
        {
            var converter = new EncodingConverter();

            Assert.IsTrue(converter.CanConvertTo(typeof(int)), "Cannot convert to an integer.");

            var value = (int)converter.ConvertTo(Encoding.UTF8, typeof(int));

            Assert.AreEqual <int>(65001, value, "Could not convert to an integer.");
        }
Ejemplo n.º 6
0
        public void ConvertToString()
        {
            var converter = new EncodingConverter();

            Assert.IsTrue(converter.CanConvertTo(typeof(string)), "Cannot convert to a string");

            var value = (string)converter.ConvertTo(Encoding.UTF8, typeof(string));

            Assert.AreEqual("utf-8", value, true, "Could not convert to a string.");
        }
Ejemplo n.º 7
0
        public void ConvertFromIntegerCodePage()
        {
            var converter = new EncodingConverter();

            Assert.IsTrue(converter.CanConvertFrom(typeof(int)), "Cannot convert from an integer.");

            var value = (Encoding)converter.ConvertFrom(65001);

            Assert.AreEqual <Encoding>(Encoding.UTF8, value, "Could not convert from an integer.");
        }
Ejemplo n.º 8
0
        public void ConvertFromNull()
        {
            var converter = new EncodingConverter();

            Assert.IsTrue(converter.CanConvertFrom(typeof(string)), "Cannot convert from a string.");

            var value = (Encoding)converter.ConvertFrom(null);

            Assert.AreEqual <Encoding>(Encoding.Default, value, "Could not convert from a null string.");
        }
Ejemplo n.º 9
0
        public void ConvertFromStringEncodingName()
        {
            var converter = new EncodingConverter();

            Assert.IsTrue(converter.CanConvertFrom(typeof(string)), "Cannot convert from a string.");

            var value = (Encoding)converter.ConvertFrom("utf-8");

            Assert.AreEqual <Encoding>(Encoding.UTF8, value, "Could not convert from a string.");
        }
Ejemplo n.º 10
0
 public void IsNumeric()
 {
     Assert.IsTrue(EncodingConverter.IsNumeric(typeof(short)));
     Assert.IsTrue(EncodingConverter.IsNumeric(typeof(int)));
     Assert.IsTrue(EncodingConverter.IsNumeric(typeof(long)));
     Assert.IsTrue(EncodingConverter.IsNumeric(typeof(ushort)));
     Assert.IsTrue(EncodingConverter.IsNumeric(typeof(uint)));
     Assert.IsTrue(EncodingConverter.IsNumeric(typeof(ulong)));
     Assert.IsFalse(EncodingConverter.IsNumeric(typeof(byte)));
     Assert.IsFalse(EncodingConverter.IsNumeric(typeof(float)));
     Assert.IsFalse(EncodingConverter.IsNumeric(typeof(double)));
 }
Ejemplo n.º 11
0
        public void ConvertToString()
        {
            var converter = new EncodingConverter();
            Assert.IsTrue(converter.CanConvertTo(typeof(string)), "Cannot convert to a string");

            var value = (string)converter.ConvertTo(Encoding.UTF8, typeof(string));
            Assert.AreEqual("utf-8", value, true, "Could not convert to a string.");
        }