Summary

Class:FakeXrmEasy.XrmOrderByAttributeComparer
Assembly:FakeXrmEasy
File(s):C:\code\jordimontana82\fake-xrm-easy\FakeXrmEasy.Shared\XrmOrderByAttributeComparer.cs
Covered lines:58
Uncovered lines:4
Coverable lines:62
Total lines:95
Line coverage:93.5%
Branch coverage:87.5%

Metrics

MethodCyclomatic ComplexitySequence CoverageBranch Coverage
Compare(...)2693.3387.80

File(s)

C:\code\jordimontana82\fake-xrm-easy\FakeXrmEasy.Shared\XrmOrderByAttributeComparer.cs

#LineLine coverage
 1using Microsoft.Xrm.Sdk;
 2using System;
 3using System.Collections.Generic;
 4
 5namespace FakeXrmEasy
 6{
 7    public class XrmOrderByAttributeComparer : IComparer<object>
 8    {
 9        public int Compare(Object objectA, Object objectB)
 148010        {
 173611             if (objectA == null && objectB == null) return 0;  //Equal
 12
 122413             if (objectA == null)
 014                return -1;
 122415             if (objectB == null)
 616                return 1;
 17
 121818            Type attributeType = objectA.GetType();
 19
 121820             if (attributeType == typeof(OptionSetValue))
 1221            {
 22                // we'll want the text value
 1223                OptionSetValue attributeValueA = (OptionSetValue)(objectA);
 1224                OptionSetValue attributeValueB = (OptionSetValue)(objectB);
 1225                return attributeValueA.Value.CompareTo(attributeValueB.Value);
 26            }
 120627             else if (attributeType == typeof(EntityReference)
 120628#if FAKE_XRM_EASY
 120629                    || attributeType == typeof(Microsoft.Xrm.Client.CrmEntityReference)
 120630#endif
 120631                )
 8432            {
 33                // Name might well be Null in an entity reference?
 8434                EntityReference entityRefA = (EntityReference)objectA;
 8435                EntityReference entityRefB = (EntityReference)objectB;
 36
 9637                 if (entityRefA.Name == null && entityRefB.Name == null) return 0;  //Equal
 38
 7239                 if (entityRefA.Name == null)
 040                    return -1;
 7241                 if (entityRefB.Name == null)
 1242                    return 1;
 43
 6044                return entityRefA.Name.CompareTo(entityRefB.Name);
 45            }
 112246             else if (attributeType == typeof(Money))
 3047            {
 3048                Decimal valueA = ((Money)objectA).Value;
 3049                Decimal valueB = ((Money)objectB).Value;
 3050                var x = valueA.CompareTo(valueB);
 3051                return x;
 52            }
 109253             else if (attributeType == typeof(string))
 654            {
 655                return String.Compare(objectA.ToString(), objectB.ToString());
 56            }
 108657             else if (attributeType == typeof(int))
 88858            {
 88859                return ((int)objectA).CompareTo(((int)objectB));
 60            }
 19861             else if (attributeType == typeof(DateTime))
 3662            {
 3663                return ((DateTime)objectA).CompareTo((DateTime)objectB);
 64            }
 16265             else if (attributeType == typeof(Guid))
 1266            {
 1267                return ((Guid)objectA).CompareTo((Guid)objectB);
 68            }
 15069             else if (attributeType == typeof(decimal))
 1270            {
 1271                return ((decimal)objectA).CompareTo((decimal)objectB);
 72            }
 13873             else if (attributeType == typeof(double))
 1274            {
 1275                return ((double)objectA).CompareTo((double)objectB);
 76            }
 12677             else if (attributeType == typeof(float))
 1278            {
 1279                return ((float)objectA).CompareTo((float)objectB);
 80            }
 11481             else if (attributeType == typeof(bool))
 1282            {
 1283                return ((bool)objectA).CompareTo((bool)objectB);
 84            }
 10285             else if (attributeType == typeof(AliasedValue))
 10286            {
 10287                 return Compare((objectA as AliasedValue)?.Value, (objectB as AliasedValue)?.Value);
 88            }
 89            else
 090            {
 091                return 0;
 92            }
 148093        }
 94    }
 95}