Summary

Class:FakeXrmEasy.FakeMessageExecutors.RetrieveEntityRequestExecutor
Assembly:FakeXrmEasy
File(s):C:\code\jordimontana82\fake-xrm-easy\FakeXrmEasy.Shared\FakeMessageExecutors\RetrieveEntityRequestExecutor.cs
Covered lines:36
Uncovered lines:4
Coverable lines:40
Total lines:74
Line coverage:90%
Branch coverage:75%

Metrics

MethodCyclomatic ComplexitySequence CoverageBranch Coverage
CanExecute(...)1100100
GetEntityProxyType(...)47566.67
Execute(...)586.6785.71
GetResponsibleRequestType()1100100

File(s)

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

#LineLine coverage
 1using Microsoft.Xrm.Sdk;
 2using Microsoft.Xrm.Sdk.Messages;
 3using Microsoft.Xrm.Sdk.Metadata;
 4using System;
 5using System.Collections.Generic;
 6using System.Text;
 7using System.Linq;
 8using Microsoft.Xrm.Sdk.Client;
 9
 10namespace FakeXrmEasy.FakeMessageExecutors
 11{
 12    public class RetrieveEntityRequestExecutor : IFakeMessageExecutor
 13    {
 14
 15        public bool CanExecute(OrganizationRequest request)
 3016        {
 3017            return request is RetrieveEntityRequest;
 3018        }
 19        public static Type GetEntityProxyType(string entityName, XrmFakedContext ctx)
 2420        {
 21            //Find the reflected type in the proxy types assembly
 2422            var assembly = ctx.ProxyTypesAssembly;
 2423            var subClassType = assembly.GetTypes()
 311424                    .Where(t => typeof(Entity).IsAssignableFrom(t))
 190825                    .Where(t => t.GetCustomAttributes(typeof(EntityLogicalNameAttribute), true).Length > 0)
 190826                    .Where(t => ((EntityLogicalNameAttribute)t.GetCustomAttributes(typeof(EntityLogicalNameAttribute), t
 2427                    .FirstOrDefault();
 28
 2429             if (subClassType == null)
 030            {
 031                throw new Exception(string.Format("Entity {0} was not found in the proxy types", entityName));
 32            }
 2433            return subClassType;
 2434        }
 35        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
 3036        {
 3037            var req = request as RetrieveEntityRequest;
 38
 3039             if (string.IsNullOrWhiteSpace(req.LogicalName))
 640            {
 641                throw new Exception("A logical name property must be specified in the request");
 42            }
 43
 44            // HasFlag -> used to verify flag matches --> to verify EntityFilters.Entity | EntityFilters.Attributes
 2445             if (req.EntityFilters.HasFlag(Microsoft.Xrm.Sdk.Metadata.EntityFilters.Entity) ||
 2446                req.EntityFilters.HasFlag(Microsoft.Xrm.Sdk.Metadata.EntityFilters.Attributes))
 1247            {
 1248                 if(!ctx.EntityMetadata.ContainsKey(req.LogicalName))
 049                {
 050                    throw new Exception($"Entity '{req.LogicalName}' is not found in the metadata cache");
 51                }
 52
 1253                var entityMetadata = ctx.GetEntityMetadataByName(req.LogicalName);
 54
 1255                var response = new RetrieveEntityResponse()
 1256                {
 1257                    Results = new ParameterCollection
 1258                        {
 1259                            { "EntityMetadata", entityMetadata }
 1260                        }
 1261                };
 62
 1263                return response;
 64            }
 65
 1266            throw new Exception("At least EntityFilters.Entity or EntityFilters.Attributes must be present on EntityFilt
 1267        }
 68
 69        public Type GetResponsibleRequestType()
 427070        {
 427071            return typeof(RetrieveEntityRequest);
 427072        }
 73    }
 74}