Summary

Class:FakeXrmEasy.FakeMessageExecutors.AddToQueueRequestExecutor
Assembly:FakeXrmEasy
File(s):F:\Git\fake-xrm-easy\FakeXrmEasy.Shared\FakeMessageExecutors\AddToQueueRequestExecutor.cs
Covered lines:41
Uncovered lines:2
Coverable lines:43
Total lines:75
Line coverage:95.3%
Branch coverage:75%

Metrics

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

File(s)

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

#LineLine coverage
 1using Microsoft.Crm.Sdk.Messages;
 2using Microsoft.Xrm.Sdk;
 3using Microsoft.Xrm.Sdk.Query;
 4using System;
 5using System.Linq;
 6using System.ServiceModel;
 7
 8namespace FakeXrmEasy.FakeMessageExecutors
 9{
 10    public class AddToQueueRequestExecutor : IFakeMessageExecutor
 11    {
 12        public bool CanExecute(OrganizationRequest request)
 613        {
 614            return request is AddToQueueRequest;
 615        }
 16
 17        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
 1818        {
 1819            var addToQueueRequest = (AddToQueueRequest)request;
 20
 1821            var target = addToQueueRequest.Target;
 1822            var destinationQueueId = addToQueueRequest.DestinationQueueId;
 1823            var queueItemProperties = addToQueueRequest.QueueItemProperties;
 24
 1825             if (target == null)
 026            {
 027                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not add to queue
 28            }
 29
 1830            if (destinationQueueId == null)
 31            {
 32                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not add to queue
 33            }
 34
 1835            var service = ctx.GetOrganizationService();
 36
 37            // CRM updates existing queue item if one already exists for a given objectid
 1838            var existingQueueItem = service.RetrieveMultiple(new QueryExpression
 1839            {
 1840                EntityName = "queueitem",
 1841                ColumnSet = new ColumnSet(true),
 1842                Criteria = new FilterExpression
 1843                {
 1844                    Conditions =
 1845                        {
 1846                            new ConditionExpression("objectid", ConditionOperator.Equal, target.Id)
 1847                        }
 1848                }
 1849            }).Entities.FirstOrDefault();
 50
 1851             var createQueueItem = existingQueueItem ?? new Entity
 1852            {
 1853                LogicalName = "queueitem",
 1854                // QueueItemProperties are used for initializing new queueitems
 1855                Attributes = queueItemProperties?.Attributes
 1856            };
 57
 1858            createQueueItem["queueid"] = new EntityReference("queue", destinationQueueId);
 1859            createQueueItem["objectid"] = target;
 60
 1861            var guid = service.Create(createQueueItem);
 62
 1863            return new AddToQueueResponse()
 1864            {
 1865                ResponseName = "AddToQueue",
 1866                Results = new ParameterCollection { { "QueueItemId", guid } }
 1867            };
 1868        }
 69
 70        public Type GetResponsibleRequestType()
 426471        {
 426472            return typeof(AddToQueueRequest);
 426473        }
 74    }
 75}