Summary

Class:Xrm.Oss.XTL.Interpreter.PropertyStringifier
Assembly:Xrm.Oss.XTL.Templating
File(s):D:\Entwicklung\Xrm-Templating-Language\src\lib\Xrm.Oss.XTL.Interpreter\PropertyStringifier.cs
Covered lines:49
Uncovered lines:1
Coverable lines:50
Total lines:94
Line coverage:98% (49 of 50)
Covered branches:20
Total branches:24
Branch coverage:83.3% (20 of 24)

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage Crap Score
StringifyProperty(...)12102497.37%85.71%156
Stringify(...)22100%100%6

File(s)

D:\Entwicklung\Xrm-Templating-Language\src\lib\Xrm.Oss.XTL.Interpreter\PropertyStringifier.cs

#LineLine coverage
 1using Microsoft.Xrm.Sdk;
 2using System;
 3using System.Collections.Generic;
 4using System.Text;
 5using System.Globalization;
 6using Microsoft.Xrm.Sdk.Messages;
 7using System.Linq;
 8using Microsoft.Xrm.Sdk.Metadata;
 9
 10namespace Xrm.Oss.XTL.Interpreter
 11{
 12    public static class PropertyStringifier
 13    {
 14        private static string StringifyProperty(string field, object value, Entity record, IOrganizationService service,
 14815        {
 14816            var entityReference = value as EntityReference;
 14817            var optionSet = value as OptionSetValue;
 14818            var money = value as Money;
 14819            var aliasedValue = value as AliasedValue;
 20
 14821            if (optionSet != null)
 622            {
 623                var textValue = optionSet.Value.ToString(CultureInfo.InvariantCulture);
 24
 625                if (config == null)
 126                {
 127                    return textValue;
 28                }
 29
 530                var configLanguage = config.GetValue<int>("optionSetLcid", "optionSetLcid must be an int!");
 31
 532                if (configLanguage == 0)
 233                {
 234                    return textValue;
 35                }
 36
 337                var request = new RetrieveAttributeRequest
 338                {
 339                    EntityLogicalName = record.LogicalName,
 340                    RetrieveAsIfPublished = true,
 341                    LogicalName = field
 342                };
 43
 344                var response = service.Execute(request) as RetrieveAttributeResponse;
 345                var metadata = (EnumAttributeMetadata)response.AttributeMetadata;
 46
 647                var fieldMetadata = metadata.OptionSet.Options.First(f => f.Value == optionSet.Value);
 48
 649                var label = fieldMetadata.Label.LocalizedLabels.FirstOrDefault(l => l.LanguageCode == configLanguage)?.L
 50
 351                if (label != null)
 352                {
 353                    return label;
 54                }
 55
 056                return fieldMetadata.Label.UserLocalizedLabel.Label;
 57            }
 58
 14259            if (record.FormattedValues.ContainsKey(field))
 260            {
 261                return record.FormattedValues[field];
 62            }
 63
 14064            if (entityReference != null)
 1265            {
 1266                return entityReference.Name ?? entityReference.Id.ToString();
 67            }
 68
 12869            if (money != null)
 270            {
 271                return money.Value.ToString(CultureInfo.InvariantCulture);
 72            }
 73
 12674            if (aliasedValue != null)
 175            {
 176                return StringifyProperty(field, aliasedValue.Value, record, service, config);
 77            }
 78
 12579            return value.ToString();
 14880        }
 81
 82        public static string Stringify(string field, Entity record, IOrganizationService service, ConfigHandler config =
 14883        {
 14884            var value = record.GetAttributeValue<object>(field);
 85
 14886            if (value == null)
 187            {
 188                return null;
 89            }
 90
 14791            return StringifyProperty(field, value, record, service, config);
 14892        }
 93    }
 94}