Summary

Class:FakeXrmEasy.FakeMessageExecutors.PickFromQueueRequestExecutor
Assembly:FakeXrmEasy
File(s):F:\Git\fake-xrm-easy\FakeXrmEasy.Shared\FakeMessageExecutors\PickFromQueueRequestExecutor.cs
Covered lines:45
Uncovered lines:2
Coverable lines:47
Total lines:83
Line coverage:95.7%
Branch coverage:87.5%

Metrics

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

File(s)

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

#LineLine coverage
 1#if FAKE_XRM_EASY_2013 || FAKE_XRM_EASY_2015 || FAKE_XRM_EASY_2016 || FAKE_XRM_EASY_365 || FAKE_XRM_EASY_9
 2
 3using Microsoft.Crm.Sdk.Messages;
 4using Microsoft.Xrm.Sdk;
 5using Microsoft.Xrm.Sdk.Query;
 6using System;
 7using System.Linq;
 8using System.ServiceModel;
 9
 10namespace FakeXrmEasy.FakeMessageExecutors
 11{
 12    public class PickFromQueueRequestExecutor : IFakeMessageExecutor
 13    {
 14        public bool CanExecute(OrganizationRequest request)
 515        {
 516            return request is PickFromQueueRequest;
 517        }
 18
 19        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
 2020        {
 2021            var pickFromQueueRequest = (PickFromQueueRequest)request;
 22
 2023            var queueItemId = pickFromQueueRequest.QueueItemId;
 2024            var workerid = pickFromQueueRequest.WorkerId;
 25
 2026             if ((queueItemId == Guid.Empty) || (workerid == Guid.Empty))
 027            {
 028                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Expected non-empty G
 29            }
 30
 2031            var service = ctx.GetOrganizationService();
 32
 2033            var query = new QueryByAttribute("systemuser");
 2034            query.Attributes.Add("systemuserid");
 2035            query.Values.Add(workerid);
 36
 2037            var worker = service.RetrieveMultiple(query).Entities.FirstOrDefault();
 2038             if (worker == null)
 539            {
 540                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), string.Format("Invali
 41            }
 42
 1543            query = new QueryByAttribute("queueitem");
 1544            query.Attributes.Add("queueitemid");
 1545            query.Values.Add(queueItemId);
 46
 1547            var queueItem = service.RetrieveMultiple(query).Entities.FirstOrDefault();
 1548             if (queueItem == null)
 549            {
 550                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), string.Format("queuei
 51            }
 52
 1053             if (pickFromQueueRequest.RemoveQueueItem)
 554            {
 555                service.Delete("queueitem", queueItemId);
 556            }
 57            else
 558            {
 559                var pickUpdateEntity = new Entity
 560                {
 561                    LogicalName = "queueitem",
 562                    Id = queueItem.Id,
 563                    Attributes = new AttributeCollection
 564                    {
 565                        { "workerid", worker.ToEntityReference() },
 566                        { "workeridmodifiedon", DateTime.Now },
 567                    }
 568                };
 69
 570                service.Update(pickUpdateEntity);
 571            }
 72
 1073            return new PickFromQueueResponse();
 1074        }
 75
 76        public Type GetResponsibleRequestType()
 359277        {
 359278            return typeof(PickFromQueueRequest);
 359279        }
 80    }
 81}
 82
 83#endif