Summary

Class:FakeXrmEasy.FakeMessageExecutors.RetrieveRelationshipRequestExecutor
Assembly:FakeXrmEasy
File(s):C:\code\jordimontana82\fake-xrm-easy\FakeXrmEasy.Shared\FakeMessageExecutors\RetrieveRelationshipRequestExecutor.cs
Covered lines:39
Uncovered lines:4
Coverable lines:43
Total lines:71
Line coverage:90.6%
Branch coverage:66.6%

Metrics

MethodCyclomatic ComplexitySequence CoverageBranch Coverage
CanExecute(...)1100100
Execute(...)37560
GetRelationshipMetadata(...)2100100
GetResponsibleRequestType()1100100

File(s)

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

#LineLine coverage
 1using Microsoft.Xrm.Sdk;
 2using Microsoft.Xrm.Sdk.Messages;
 3using System;
 4using System.Linq;
 5
 6namespace FakeXrmEasy.FakeMessageExecutors
 7{
 8    public class RetrieveRelationshipRequestExecutor : IFakeMessageExecutor
 9    {
 10        public bool CanExecute(OrganizationRequest request)
 1811        {
 1812            return request is RetrieveRelationshipRequest;
 1813        }
 14
 15        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
 1816        {
 1817            var retrieveRequest = request as RetrieveRelationshipRequest;
 1818             if (retrieveRequest == null)
 019            {
 020                throw new Exception("Only RetrieveRelationshipRequest can be processed!");
 21            }
 22
 1823            var service = ctx.GetFakedOrganizationService();
 1824            var fakeRelationShip = ctx.GetRelationship(retrieveRequest.Name);
 1825             if (fakeRelationShip == null)
 026            {
 027                throw new Exception(string.Format("Relationship {0} does not exist in the metadata cache", retrieveReque
 28            }
 29
 30
 1831            var response = new RetrieveRelationshipResponse();
 1832            response.Results = new ParameterCollection();
 1833            response.Results.Add("RelationshipMetadata", GetRelationshipMetadata(fakeRelationShip));
 1834            response.ResponseName = "RetrieveRelationship";
 35
 1836            return response;
 1837        }
 38
 39        private static object GetRelationshipMetadata(XrmFakedRelationship fakeRelationShip)
 1840        {
 1841             if (fakeRelationShip.RelationshipType == XrmFakedRelationship.enmFakeRelationshipType.ManyToMany)
 642            {
 643                var mtm = new Microsoft.Xrm.Sdk.Metadata.ManyToManyRelationshipMetadata();
 644                mtm.Entity1LogicalName = fakeRelationShip.Entity1LogicalName;
 645                mtm.Entity1IntersectAttribute = fakeRelationShip.Entity1Attribute;
 646                mtm.Entity2LogicalName = fakeRelationShip.Entity2LogicalName;
 647                mtm.Entity2IntersectAttribute = fakeRelationShip.Entity2Attribute;
 648                mtm.SchemaName = fakeRelationShip.IntersectEntity;
 649                mtm.IntersectEntityName = fakeRelationShip.IntersectEntity.ToLower();
 650                return mtm;
 1251            } else {
 52
 1253                var otm = new Microsoft.Xrm.Sdk.Metadata.OneToManyRelationshipMetadata();
 54#if FAKE_XRM_EASY_2016 || FAKE_XRM_EASY_365 || FAKE_XRM_EASY_9
 655                otm.ReferencedEntityNavigationPropertyName = fakeRelationShip.IntersectEntity;
 56#endif
 1257                otm.ReferencingAttribute = fakeRelationShip.Entity1Attribute;
 1258                otm.ReferencingEntity = fakeRelationShip.Entity1LogicalName;
 1259                otm.ReferencedAttribute = fakeRelationShip.Entity2Attribute;
 1260                otm.ReferencedEntity = fakeRelationShip.Entity2LogicalName;
 1261                otm.SchemaName = fakeRelationShip.IntersectEntity;
 1262                return otm;
 63            }
 1864        }
 65
 66        public Type GetResponsibleRequestType()
 427067        {
 427068            return typeof(RetrieveRelationshipRequest);
 427069        }
 70    }
 71}