Пример #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());
        }
Пример #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);
        }
Пример #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));
        }
Пример #4
0
 public void Test_Error_Is_Not_Convertible(Type targetType)
 {
     Assert.Throws <COMException>(() =>
     {
         var err = new ErrorWrapper(1);
         VariantConverter.ChangeType(err, targetType);
     });
 }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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));
        }
Пример #11
0
        public void Test_ObjectConversion_Null(object value)
        {
            var result = VariantConverter.ChangeType(value, VARENUM.VT_EMPTY);

            Assert.IsNull(result);
        }
Пример #12
0
        public void Test_ObjectConversion_DbNull(object value)
        {
            var result = VariantConverter.ChangeType(value, VARENUM.VT_NULL);

            Assert.IsInstanceOf <DBNull>(result);
        }
Пример #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));
        }
Пример #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)));
        }