Example #1
0
        public void CanConvertBoolWithComma()
        {
            var convertible = new DefaultConvertible("true,false");

            Assert.That(convertible.ToType(typeof(bool), CultureInfo.CurrentCulture), Is.EqualTo(true));
            Assert.That(convertible.ToBoolean(CultureInfo.CurrentCulture), Is.True);
        }
Example #2
0
        public void FallsBackToTypeConverter()
        {
            var convertible = new DefaultConvertible("1.02:03:04.005");
            var value       = (TimeSpan)convertible.ToType(typeof(TimeSpan), CultureInfo.InvariantCulture);
            var actual      = new TimeSpan(1, 2, 3, 4, 5);

            Assert.AreEqual(actual, value);
        }
        public void CanConvertByte()
        {
            var convertible = new DefaultConvertible(byte.MaxValue.ToString());
            byte value = convertible.ToByte(CultureInfo.InvariantCulture);

            Assert.AreEqual(byte.MaxValue, value);

            object oValue = convertible.ToType(typeof(byte), CultureInfo.InvariantCulture);
            Assert.AreEqual(byte.MaxValue, oValue);
        }
        public void CanConvertBool()
        {
            var convertible = new DefaultConvertible("true");
            bool value = convertible.ToBoolean(CultureInfo.InvariantCulture);

            Assert.IsTrue(value);

            object oValue = convertible.ToType(typeof(bool), CultureInfo.InvariantCulture);
            Assert.AreEqual(true, oValue);
        }
        public void CanConvertChar()
        {
            var convertible = new DefaultConvertible("t");
            char value = convertible.ToChar(CultureInfo.InvariantCulture);

            Assert.AreEqual('t', value);

            object oValue = convertible.ToType(typeof(char), CultureInfo.InvariantCulture);
            Assert.AreEqual('t', oValue);
        }
		public void CanConvertShort()
		{
			var convertible = new DefaultConvertible(short.MaxValue.ToString());
			short value = convertible.ToInt16(CultureInfo.InvariantCulture);

			Assert.AreEqual(short.MaxValue, value);

			object oValue = convertible.ToType(typeof(short), CultureInfo.InvariantCulture);
			Assert.AreEqual(short.MaxValue, oValue);
		}
Example #7
0
        public void CanConvertBool()
        {
            var  convertible = new DefaultConvertible("true");
            bool value       = convertible.ToBoolean(CultureInfo.InvariantCulture);

            Assert.IsTrue(value);

            object oValue = convertible.ToType(typeof(bool), CultureInfo.InvariantCulture);

            Assert.AreEqual(true, oValue);
        }
Example #8
0
        public void CanConvertUShort()
        {
            var    convertible = new DefaultConvertible(ushort.MaxValue.ToString());
            ushort value       = convertible.ToUInt16(CultureInfo.InvariantCulture);

            Assert.AreEqual(ushort.MaxValue, value);

            object oValue = convertible.ToType(typeof(ushort), CultureInfo.InvariantCulture);

            Assert.AreEqual(ushort.MaxValue, oValue);
        }
Example #9
0
        public void CanConvertByte()
        {
            var  convertible = new DefaultConvertible(byte.MaxValue.ToString());
            byte value       = convertible.ToByte(CultureInfo.InvariantCulture);

            Assert.AreEqual(byte.MaxValue, value);

            object oValue = convertible.ToType(typeof(byte), CultureInfo.InvariantCulture);

            Assert.AreEqual(byte.MaxValue, oValue);
        }
Example #10
0
        public void CanConvertChar()
        {
            var  convertible = new DefaultConvertible("t");
            char value       = convertible.ToChar(CultureInfo.InvariantCulture);

            Assert.AreEqual('t', value);

            object oValue = convertible.ToType(typeof(char), CultureInfo.InvariantCulture);

            Assert.AreEqual('t', oValue);
        }
Example #11
0
        public void CanConvertEnum()
        {
            var convertible = new DefaultConvertible("Minute");
            var value       = (WeAre)convertible.ToEnum(typeof(WeAre));

            Assert.AreEqual(WeAre.Minute, value);

            object oValue = convertible.ToType(typeof(WeAre), CultureInfo.InvariantCulture);

            Assert.AreEqual(WeAre.Minute, oValue);
        }
Example #12
0
        public void CanConvertDecimal()
        {
            var     convertible = new DefaultConvertible("1.3");
            decimal value       = convertible.ToDecimal(CultureInfo.InvariantCulture);

            Assert.AreEqual(1.3M, value);

            object oValue = convertible.ToType(typeof(decimal), CultureInfo.InvariantCulture);

            Assert.AreEqual(1.3M, oValue);
        }
Example #13
0
        public void CanConvertDouble()
        {
            var    convertible = new DefaultConvertible("1.2");
            double value       = convertible.ToDouble(CultureInfo.InvariantCulture);

            Assert.AreEqual(1.2, value);

            object oValue = convertible.ToType(typeof(double), CultureInfo.InvariantCulture);

            Assert.AreEqual(1.2, oValue);
        }
Example #14
0
        public void CanConvertFloat()
        {
            var   convertible = new DefaultConvertible("1.1");
            float value       = convertible.ToSingle(CultureInfo.InvariantCulture);

            Assert.AreEqual(1.1F, value);

            object oValue = convertible.ToType(typeof(float), CultureInfo.InvariantCulture);

            Assert.AreEqual(1.1F, oValue);
        }
Example #15
0
        public void CanConvertULong()
        {
            var   convertible = new DefaultConvertible(ulong.MaxValue.ToString());
            ulong value       = convertible.ToUInt64(CultureInfo.InvariantCulture);

            Assert.AreEqual(ulong.MaxValue, value);

            object oValue = convertible.ToType(typeof(ulong), CultureInfo.InvariantCulture);

            Assert.AreEqual(ulong.MaxValue, oValue);
        }
Example #16
0
        public void CanConvertInt()
        {
            var convertible = new DefaultConvertible(int.MaxValue.ToString());
            int value       = convertible.ToInt32(CultureInfo.InvariantCulture);

            Assert.AreEqual(int.MaxValue, value);

            object oValue = convertible.ToType(typeof(int), CultureInfo.InvariantCulture);

            Assert.AreEqual(int.MaxValue, oValue);
        }
        public void CanConvertDateTime()
        {
            var convertible = new DefaultConvertible("11/05/1605");
            DateTime value = convertible.ToDateTime(CultureInfo.InvariantCulture);
            var actual = new DateTime(1605, 11, 5);

            Assert.AreEqual(actual, value);

            object oValue = convertible.ToType(typeof(DateTime), CultureInfo.InvariantCulture);
            Assert.AreEqual(actual, oValue);
        }
Example #18
0
        public void CanConvertGuid()
        {
            Guid actual      = Guid.NewGuid();
            var  convertible = new DefaultConvertible(actual.ToString());
            Guid value       = convertible.ToGuid();

            Assert.AreEqual(actual, value);

            object oValue = convertible.ToType(typeof(Guid), CultureInfo.InvariantCulture);

            Assert.AreEqual(actual, oValue);
        }
Example #19
0
        public void CanConvertDateTime()
        {
            var      convertible = new DefaultConvertible("11/05/1605");
            DateTime value       = convertible.ToDateTime(CultureInfo.InvariantCulture);
            var      actual      = new DateTime(1605, 11, 5);

            Assert.AreEqual(actual, value);

            object oValue = convertible.ToType(typeof(DateTime), CultureInfo.InvariantCulture);

            Assert.AreEqual(actual, oValue);
        }
        public void CanConvertDouble()
        {
            var convertible = new DefaultConvertible("1.2");
            double value = convertible.ToDouble(CultureInfo.InvariantCulture);

            Assert.AreEqual(1.2, value);

            object oValue = convertible.ToType(typeof(double), CultureInfo.InvariantCulture);
            Assert.AreEqual(1.2, oValue);
        }
        public void CanConvertDecimal()
        {
            var convertible = new DefaultConvertible("1.3");
            decimal value = convertible.ToDecimal(CultureInfo.InvariantCulture);

            Assert.AreEqual(1.3M, value);

            object oValue = convertible.ToType(typeof(decimal), CultureInfo.InvariantCulture);
            Assert.AreEqual(1.3M, oValue);
        }
        public void CanConvertEnum()
        {
            var convertible = new DefaultConvertible("Minute");
            var value = (WeAre)convertible.ToEnum(typeof(WeAre));

            Assert.AreEqual(WeAre.Minute, value);

            object oValue = convertible.ToType(typeof(WeAre), CultureInfo.InvariantCulture);
            Assert.AreEqual(WeAre.Minute, oValue);
        }
 public void CanConvertBoolWithComma()
 {
     var convertible = new DefaultConvertible("true,false");
     Assert.That(convertible.ToType(typeof(bool), CultureInfo.CurrentCulture), Is.EqualTo(true));
     Assert.That(convertible.ToBoolean(CultureInfo.CurrentCulture), Is.True);
 }
        public void FallsBackToTypeConverter()
        {
            var convertible = new DefaultConvertible("1.02:03:04.005");
            var value = (TimeSpan)convertible.ToType(typeof(TimeSpan), CultureInfo.InvariantCulture);
            var actual = new TimeSpan(1, 2, 3, 4, 5);

            Assert.AreEqual(actual, value);
        }
        public void CanConvertULong()
        {
            var convertible = new DefaultConvertible(ulong.MaxValue.ToString());
            ulong value = convertible.ToUInt64(CultureInfo.InvariantCulture);

            Assert.AreEqual(ulong.MaxValue, value);

            object oValue = convertible.ToType(typeof(ulong), CultureInfo.InvariantCulture);
            Assert.AreEqual(ulong.MaxValue, oValue);
        }
        public void CanConvertInt()
        {
            var convertible = new DefaultConvertible(int.MaxValue.ToString());
            int value = convertible.ToInt32(CultureInfo.InvariantCulture);

            Assert.AreEqual(int.MaxValue, value);

            object oValue = convertible.ToType(typeof(int), CultureInfo.InvariantCulture);
            Assert.AreEqual(int.MaxValue, oValue);
        }
        public void CanConvertGuid()
        {
            Guid actual = Guid.NewGuid();
            var convertible = new DefaultConvertible(actual.ToString());
            Guid value = convertible.ToGuid();

            Assert.AreEqual(actual, value);

            object oValue = convertible.ToType(typeof(Guid), CultureInfo.InvariantCulture);
            Assert.AreEqual(actual, oValue);
        }
        public void CanConvertFloat()
        {
            var convertible = new DefaultConvertible("1.1");
            float value = convertible.ToSingle(CultureInfo.InvariantCulture);

            Assert.AreEqual(1.1F, value);

            object oValue = convertible.ToType(typeof(float), CultureInfo.InvariantCulture);
            Assert.AreEqual(1.1F, oValue);
        }