예제 #1
0
        public void TestTypeOverriding()
        {
            CustomVariable customVariable = new CustomVariable();
            customVariable.Name = "Whatever";
            customVariable.Type = "int";
            customVariable.DefaultValue = 4;

            object value = ElementRuntime.ConvertIfOverriding(
                customVariable, customVariable.DefaultValue);

            if (value is int == false || ((int)value) != 4)
            {
                throw new Exception("Converting variables without overrides ");
            }
            ////////////////////////////////////////////////////////////////////
            customVariable.Type = "string";
            customVariable.OverridingPropertyType = "int";

            value = ElementRuntime.ConvertIfOverriding(
                customVariable, customVariable.DefaultValue);

            if (value is string == false || ((string)value) != "4")
            {
                throw new Exception("Converting variables without overrides ");
            }
            ////////////////////////////////////////////////////////////////////
            customVariable.Type = "string";
            customVariable.OverridingPropertyType = "int";
            customVariable.TypeConverter = "Minutes:Seconds";

            value = ElementRuntime.ConvertIfOverriding(
                customVariable, customVariable.DefaultValue);

            if (value is string == false || ((string)value) != "0:04")
            {
                throw new Exception("Converting int to time is wrong");
            }
            ///////////////////////////////////////////////////////////////////
            customVariable.DefaultValue = 1234;
            customVariable.TypeConverter = "Comma Separating";

            value = ElementRuntime.ConvertIfOverriding(
                customVariable, customVariable.DefaultValue);

            if (value is string == false || ((string)value) != "1,234")
            {
                throw new Exception("Converting variables without overrides ");
            }
            //////////////////////////////////////////////////////////////////
            customVariable.DefaultValue = 1234.0f;
            customVariable.TypeConverter = "Comma Separating";
            customVariable.OverridingPropertyType = "float";

            value = ElementRuntime.ConvertIfOverriding(
                customVariable, customVariable.DefaultValue);

            if (value is string == false || ((string)value) != "1,234.00")
            {
                throw new Exception("Converting variables without overrides ");
            }





            ///////////////////////////////////////////////////////////////////
            customVariable.DefaultValue = 1234.5f;
            customVariable.TypeConverter = "Minutes:Seconds.Hundredths";
            customVariable.OverridingPropertyType = "float";

            value = ElementRuntime.ConvertIfOverriding(
                customVariable, customVariable.DefaultValue);

            if (value is string == false || ((string)value) != "20:34.50")
            {
                throw new Exception("Converting variables without overrides ");
            }


        }