예제 #1
0
        private static object GetConvertedValue(CrmTestingContext context, AttributeMetadata metadata, string value, ConvertedObjectType objectType)
        {
            switch (metadata.AttributeType)
            {
            case AttributeTypeCode.Boolean:
                return(GetTwoOptionValue(metadata, value, context));

            case AttributeTypeCode.Double: return(double.Parse(value, NumberFormatInfo.InvariantInfo));

            case AttributeTypeCode.Decimal: return(decimal.Parse(value, NumberFormatInfo.InvariantInfo));

            case AttributeTypeCode.Integer: return(int.Parse(value, NumberFormatInfo.InvariantInfo));

            case AttributeTypeCode.DateTime:
                return(ParseDateTime(metadata, value));

            case AttributeTypeCode.Memo:
            case AttributeTypeCode.String: return(value);

            case AttributeTypeCode.Money:
                if (objectType == ConvertedObjectType.Primitive)
                {
                    return(decimal.Parse(value, NumberFormatInfo.InvariantInfo));
                }
                else
                {
                    return(new Money(decimal.Parse(value, NumberFormatInfo.InvariantInfo)));
                }

            case AttributeTypeCode.Picklist:
            case AttributeTypeCode.State:
            case AttributeTypeCode.Status:
                var optionSet = GetOptionSetValue(metadata, value, context);
                if (objectType == ConvertedObjectType.Primitive)
                {
                    return(optionSet.Value);
                }
                else
                {
                    return(optionSet);
                }

            case AttributeTypeCode.Customer:
            case AttributeTypeCode.Lookup:
            case AttributeTypeCode.Owner:
                var lookup = GetLookupValue(context, metadata, value);
                if (objectType == ConvertedObjectType.Primitive)
                {
                    return(lookup.Id);
                }
                else
                {
                    return(lookup);
                }

            case AttributeTypeCode.Uniqueidentifier:
                return(GetLookupValue(context, metadata, value).Id);

            case AttributeTypeCode.Virtual:
                return(ParseVirtualType(context, metadata, value));

            default: throw new NotImplementedException(string.Format("Type {0} not implemented", metadata.AttributeType));
            }
        }
예제 #2
0
        public static object ToCrmObject(string entityName, string attributeName, string value, CrmTestingContext context, ConvertedObjectType objectType = ConvertedObjectType.Default)
        {
            Logger.WriteLine($"Converting CRM Object. Entity: {entityName}, Attribute: {attributeName}, Value: {value}, ObjectType: {objectType}");
            if (string.IsNullOrWhiteSpace(value))
            {
                return(null);
            }

            var    metadata       = GlobalTestingContext.Metadata.GetAttributeMetadata(entityName, attributeName);
            object convertedValue = GetConvertedValue(context, metadata, value, objectType);

            Logger.WriteLine($"ConvertedValue: {HelperMethods.CrmObjectToPrimitive(convertedValue)}");

            return(convertedValue);
        }