Summary

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

Metrics

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

File(s)

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

#LineLine coverage
 1using System;
 2using System.ServiceModel;
 3using Microsoft.Crm.Sdk.Messages;
 4using Microsoft.Xrm.Sdk;
 5using Microsoft.Xrm.Sdk.Query;
 6
 7namespace FakeXrmEasy.FakeMessageExecutors
 8{
 9    public class BulkDeleteRequestExecutor : IFakeMessageExecutor
 10    {
 11        public bool CanExecute(OrganizationRequest request)
 1212        {
 1213            return request is BulkDeleteRequest;
 1214        }
 15
 16        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
 3017        {
 3018            var bulkDeleteRequest = (BulkDeleteRequest)request;
 19
 3020             if (string.IsNullOrEmpty(bulkDeleteRequest.JobName))
 621            {
 622                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not Bulk delete 
 23            }
 2424             if (bulkDeleteRequest.QuerySet == null)
 625            {
 626                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not Bulk delete 
 27            }
 1828             if (bulkDeleteRequest.CCRecipients == null)
 629            {
 630                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not Bulk delete 
 31            }
 1232             if (bulkDeleteRequest.ToRecipients == null)
 633            {
 634                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not Bulk delete 
 35            }
 36
 637            var service = ctx.GetOrganizationService();
 38
 39            // generate JobId
 640            var jobId = Guid.NewGuid();
 41
 42            // create related asyncOperation
 643            Entity asyncOpertation = new Entity("asyncoperation")
 644            {
 645                Id = jobId
 646            };
 47
 648            service.Create(asyncOpertation);
 49
 50            // delete all records from all queries
 3051            foreach (QueryExpression queryExpression in bulkDeleteRequest.QuerySet)
 652            {
 653                EntityCollection recordsToDelete = service.RetrieveMultiple(queryExpression);
 4254                foreach (Entity record in recordsToDelete.Entities)
 1255                {
 1256                    service.Delete(record.LogicalName, record.Id);
 1257                }
 658            }
 59
 60            // set ayncoperation to completed
 661            asyncOpertation["statecode"] = new OptionSetValue(3);
 662            service.Update(asyncOpertation);
 63
 64            // return result
 665            return new BulkDeleteResponse { ResponseName = "BulkDeleteResponse", ["JobId"] = jobId};
 666        }
 67
 68        public Type GetResponsibleRequestType()
 426469        {
 426470            return typeof(BulkDeleteRequest);
 426471        }
 72    }
 73}