Esempio n. 1
0
        public Type Test_ObjectConversion_IConvertible(VARENUM vt, TypeCode code)
        {
            var convertible = new ConvertibleTest(code);
            var result      = VariantConverter.ChangeType(convertible, vt);

            return(result.GetType());
        }
Esempio n. 2
0
        public void Test_ObjectConversion_IConvertible_Null()
        {
            var convertible = new ConvertibleTest(TypeCode.Empty);
            var result      = VariantConverter.ChangeType(convertible, VARENUM.VT_EMPTY);

            Assert.IsNull(result);
        }
Esempio n. 3
0
        public object Test_ObjectConversion_Date_Localized(string value, Type targetType, string locale)
        {
            var culture = new CultureInfo(locale);
            var date    = DateTime.ParseExact(value, TheOneTrueDateFormat, culture);

            return(VariantConverter.ChangeType(date, targetType, culture));
        }
Esempio n. 4
0
 public void Test_Error_Is_Not_Convertible(Type targetType)
 {
     Assert.Throws <COMException>(() =>
     {
         var err = new ErrorWrapper(1);
         VariantConverter.ChangeType(err, targetType);
     });
 }
Esempio n. 5
0
        public object Test_ObjectConversion_SimpleValues(object value, Type targetType)
        {
            var result = VariantConverter.ChangeType(value, targetType);

            if (result is DateTime dt)
            {
                return(dt.ToString(TheOneTrueDateFormat));
            }

            return(result);
        }
Esempio n. 6
0
        public void Test_ObjectConversion_Object()
        {
            var obj    = new object();
            var unk    = new UnknownWrapper(obj);
            var result = VariantConverter.ChangeType(unk, typeof(DispatchWrapper));

            Assert.AreSame(obj, result);

            var result2 = VariantConverter.ChangeType(result, typeof(UnknownWrapper));

            Assert.AreSame(unk.WrappedObject, result2);
        }
Esempio n. 7
0
        public object Test_ObjectConversion_Currency(decimal value, Type targetType)
        {
            var cy     = new CurrencyWrapper(value);
            var result = VariantConverter.ChangeType(cy, targetType);

            if (result is DateTime dt)
            {
                return(dt.ToString(TheOneTrueDateFormat));
            }

            return(result);
        }
Esempio n. 8
0
        public string Test_US_format_String_To_Date_Localized(string locale, object value, Type targetType)
        {
            var culture = new CultureInfo(locale);
            var result  = VariantConverter.ChangeType(value, targetType, culture);

            if (result is DateTime dt)
            {
                return(dt.ToString(TheOneTrueDateFormat));
            }

            // Invalid result
            return(string.Empty);
        }
Esempio n. 9
0
        public string Test_ObjectConversion_SimpleValues_To_Date(object value, Type targetType)
        {
            var culture = new CultureInfo("en-US");
            var result  = VariantConverter.ChangeType(value, targetType, culture);

            if (result is DateTime dt)
            {
                return(dt.ToString(TheOneTrueDateFormat));
            }

            // Invalid result
            return(string.Empty);
        }
        /// <summary>
        /// Tests equity between 2 objects using VBA's type promotion rules.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns>VBA equity</returns>
        public new bool Equals(object x, object y)
        {
            if (x == null)
            {
                return(y == null);
            }

            if (y == null)
            {
                return(false);
            }

            var converted = VariantConverter.ChangeType(y, x.GetType());

            return(x.Equals(converted));
        }
Esempio n. 11
0
        public void Test_ObjectConversion_Null(object value)
        {
            var result = VariantConverter.ChangeType(value, VARENUM.VT_EMPTY);

            Assert.IsNull(result);
        }
Esempio n. 12
0
        public void Test_ObjectConversion_DbNull(object value)
        {
            var result = VariantConverter.ChangeType(value, VARENUM.VT_NULL);

            Assert.IsInstanceOf <DBNull>(result);
        }
Esempio n. 13
0
        [TestCase("9999-12-31 23:59:59", typeof(double), ExpectedResult = 2958465.999988426d)]      // Note: VBA returns 2958465.99998843d but accepts the other values as equal
        public object Test_ObjectConversion_Date(string value, Type targetType)
        {
            var date = DateTime.ParseExact(value, TheOneTrueDateFormat, CultureInfo.InvariantCulture);

            return(VariantConverter.ChangeType(date, targetType));
        }
Esempio n. 14
0
        public object Test_ObjectConversion_Currency_Localized(decimal value, Type targetType, string locale)
        {
            var cy = new CurrencyWrapper(value);

            return(VariantConverter.ChangeType(cy, targetType, new CultureInfo(locale)));
        }