public void IfWrongValue_ReturnValue()
        {
            var converter = new ApprovalStateToDisplayNameConverter();

            var obj = new object();

            var result = converter.Convert(obj, typeof(ApprovalStates), null, CultureInfo.InvariantCulture);
            Assert.AreSame(obj, result);
        }
        public void ConvertTest()
        {
            var converter = new ApprovalStateToDisplayNameConverter();

            //Convert by using field name
            var result = converter.Convert("ReadyForApproval", typeof(ApprovalStates), null, CultureInfo.InvariantCulture);
            Assert.IsTrue(result is string);
            Assert.IsTrue(((string)result).Equals("In process", StringComparison.InvariantCultureIgnoreCase));

            //Convert by using field's description
            converter = new ApprovalStateToDisplayNameConverter();

            result = converter.Convert("In process", typeof(ApprovalStates), null, CultureInfo.InvariantCulture);
            Assert.IsTrue(((string)result).Equals("In process", StringComparison.InvariantCultureIgnoreCase));
        }
        private static ConverterInfo GetConverterInfo(IColumnItem column)
        {
            var localProperty = column.Property;
            IValueConverter converterObject = null;
            object converterParameter = null;
            var converterString = string.Empty;
            PropertyInfo sourceProperty = null;

            if (ReferenceFieldsHelper.IsReferenceProperty(localProperty))
            {
                // Field type specific attributes should be taken from source.
                var refInfo = ReferenceFieldsHelper.GetCrossRefInfo(localProperty);
                sourceProperty = new ReferenceFieldsHelper().GetSourcePropertyInfo(refInfo.Item1, refInfo.Item2);
            }

            var prop = sourceProperty ?? localProperty;

            if (PropertyIsDateTime(localProperty, column))
            {
                var datetimeFormat = ReferenceFieldsHelper.GetDateTimeFormat(prop);

                if (!string.IsNullOrEmpty(datetimeFormat))
                {
                    converterObject = new DateTimeFormatConverter();
                    converterString = string.Format(CultureInfo.InvariantCulture, "Converter={{StaticResource DateTimeFormatConverter}}, ConverterParameter={0}", datetimeFormat);
                }
            }
            else if (localProperty.PropertyType == typeof(string))
            {
                var approvalAttribute = (ApprovalDefinitionAttribute)(sourceProperty ?? prop).GetCustomAttributes(typeof(ApprovalDefinitionAttribute), false).FirstOrDefault();

                if (approvalAttribute != null)
                {
                    converterObject = new ApprovalStateToDisplayNameConverter();
                    converterString = string.Format(CultureInfo.InvariantCulture, "Converter={{StaticResource ApprovalStateToDisplayNameConverter}}");
                }
            }
            else if (prop.PropertyType == typeof(bool?))
            {
                var checkboxSettings = ReferenceFieldsHelper.GetCheckboxSettings(prop);

                if (checkboxSettings != null && checkboxSettings.IsSwitchToggle)
                {
                    var param = new[]
                                            {
                                                checkboxSettings.UndefinedLabel,
                                                checkboxSettings.FalseLabel,
                                                checkboxSettings.TrueLabel
                                            };

                    converterObject = new CheckboxToCustomValueConverter();
                    converterParameter = string.Join("~", param).Replace(' ', '_').Replace('\'', '^');
                    converterString = string.Format(CultureInfo.InvariantCulture, "Converter={{StaticResource checkboxToCustomValueConverter}}, ConverterParameter={0}", converterParameter);
                }
            }

            var numericAttribute = (NumericAttribute)prop.GetCustomAttributes(typeof(NumericAttribute), false).FirstOrDefault();

            if (numericAttribute != null)
            {
                switch (numericAttribute.NumericType)
                {
                    case NumericTypes.Percentage:
                        converterObject = new NumberToPercentConverter();
                        converterString = string.Format(CultureInfo.InvariantCulture, "Converter={{StaticResource NumberToPercentConverter}}");
                        break;
                }
            }

            return new ConverterInfo(converterObject, converterParameter, converterString);
        }