Summary

Class:FakeXrmEasy.FakeMessageExecutors.ExecuteMultipleRequestExecutor
Assembly:FakeXrmEasy
File(s):F:\Git\fake-xrm-easy\FakeXrmEasy.Shared\FakeMessageExecutors\ExecuteMultipleRequestExecutor.cs
Covered lines:55
Uncovered lines:4
Coverable lines:59
Total lines:94
Line coverage:93.2%
Branch coverage:81.2%

Metrics

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

File(s)

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

#LineLine coverage
 1using Microsoft.Xrm.Sdk;
 2using Microsoft.Xrm.Sdk.Messages;
 3using System;
 4using System.Linq;
 5using System.ServiceModel;
 6
 7namespace FakeXrmEasy.FakeMessageExecutors
 8{
 9    public class ExecuteMultipleRequestExecutor : IFakeMessageExecutor
 10    {
 11        public bool CanExecute(OrganizationRequest request)
 4212        {
 4213            return request is ExecuteMultipleRequest;
 4214        }
 15
 16        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
 4217        {
 4218            var executeMultipleRequest = (ExecuteMultipleRequest)request;
 19
 4220             if (executeMultipleRequest.Settings == null)
 021            {
 022                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "You need to pass a v
 23            }
 24
 4225             if (executeMultipleRequest.Requests == null)
 026            {
 027                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "You need to pass a v
 28            }
 29
 4230            var service = ctx.GetFakedOrganizationService();
 31
 4232            var response = new ExecuteMultipleResponse();
 4233            response.Results["Responses"] = new ExecuteMultipleResponseItemCollection();
 34
 26435             for (var i = 0; i < executeMultipleRequest.Requests.Count; i++)
 10236            {
 10237                var executeRequest = executeMultipleRequest.Requests[i];
 38
 39                try
 10240                {
 10241                    OrganizationResponse resp = service.Execute(executeRequest);
 42
 8443                     if (executeMultipleRequest.Settings.ReturnResponses)
 6644                    {
 6645                        response.Responses.Add(new ExecuteMultipleResponseItem
 6646                        {
 6647                            RequestIndex = i,
 6648                            Response = resp
 6649                        });
 6650                    }
 8451                }
 1852                catch (Exception ex)
 1853                {
 1854                     if (!response.IsFaulted)
 1855                    {
 1856                        response.Results["IsFaulted"] = true;
 1857                    }
 58
 1859                    response.Responses.Add(new ExecuteMultipleResponseItem
 1860                    {
 1861                        Fault = new OrganizationServiceFault { Message = ex.Message },
 1862                        RequestIndex = i
 1863                    });
 64
 1865                     if (!executeMultipleRequest.Settings.ContinueOnError)
 1266                    {
 1267                        break;
 68                    }
 669                }
 9070            }
 71
 72            // Implement response behaviour as in https://msdn.microsoft.com/en-us/library/jj863631.aspx
 4273             if (executeMultipleRequest.Settings.ReturnResponses)
 3074            {
 3075                response.Results["response.Responses"] = response.Responses;
 3076            }
 1877             else if (response.Responses.Any(resp => resp.Fault != null))
 678            {
 679                var failures = new ExecuteMultipleResponseItemCollection();
 80
 1281                failures.AddRange(response.Responses.Where(resp => resp.Fault != null));
 82
 683                response.Results["response.Responses"] = failures;
 684            }
 85
 4286            return response;
 4287        }
 88
 89        public Type GetResponsibleRequestType()
 426490        {
 426491            return typeof(ExecuteMultipleRequest);
 426492        }
 93    }
 94}