Summary

Class:FakeXrmEasy.FakeMessageExecutors.UpsertRequestExecutor
Assembly:FakeXrmEasy
File(s):F:\Git\fake-xrm-easy\FakeXrmEasy.Shared\FakeMessageExecutors\UpsertRequestExecutor.cs
Covered lines:26
Uncovered lines:0
Coverable lines:26
Total lines:51
Line coverage:100%
Branch coverage:100%

Metrics

MethodCyclomatic ComplexitySequence CoverageBranch Coverage
CanExecute(...)1100100
Execute(...)3100100
GetResponsibleRequestType()1100100

File(s)

F:\Git\fake-xrm-easy\FakeXrmEasy.Shared\FakeMessageExecutors\UpsertRequestExecutor.cs

#LineLine coverage
 1using FakeXrmEasy.Extensions;
 2using Microsoft.Xrm.Sdk;
 3using Microsoft.Xrm.Sdk.Messages;
 4using System;
 5
 6#if !FAKE_XRM_EASY && !FAKE_XRM_EASY_2013 && !FAKE_XRM_EASY_2015
 7
 8namespace FakeXrmEasy.FakeMessageExecutors
 9{
 10    public class UpsertRequestExecutor : IFakeMessageExecutor
 11    {
 12        public bool CanExecute(OrganizationRequest request)
 1213        {
 1214            return request is UpsertRequest;
 1215        }
 16
 17        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
 1218        {
 1219            var upsertRequest = (UpsertRequest)request;
 20            bool recordCreated;
 21
 1222            var service = ctx.GetOrganizationService();
 23
 1224            var entityLogicalName = upsertRequest.Target.LogicalName;
 1225            var entityId = ctx.GetRecordUniqueId(upsertRequest.Target.ToEntityReferenceWithKeyAttributes(), validate: fa
 26
 1227             if (ctx.Data.ContainsKey(entityLogicalName) &&
 1228                ctx.Data[entityLogicalName].ContainsKey(entityId))
 629            {
 630                recordCreated = false;
 631                service.Update(upsertRequest.Target);
 632            }
 33            else
 634            {
 635                recordCreated = true;
 636                entityId = service.Create(upsertRequest.Target);
 637            }
 38
 1239            var result = new UpsertResponse();
 1240            result.Results.Add("RecordCreated", recordCreated);
 1241            result.Results.Add("Target", new EntityReference(entityLogicalName, entityId));
 1242            return result;
 1243        }
 44
 45        public Type GetResponsibleRequestType()
 219846        {
 219847            return typeof(UpsertRequest);
 219848        }
 49    }
 50}
 51#endif