Summary

Class:FakeXrmEasy.FakeMessageExecutors.CloseIncidentRequestExecutor
Assembly:FakeXrmEasy
File(s):C:\code\jordimontana82\fake-xrm-easy\FakeXrmEasy.Shared\FakeMessageExecutors\CloseIncidentRequestExecutor.cs
Covered lines:43
Uncovered lines:0
Coverable lines:43
Total lines:76
Line coverage:100%
Branch coverage:100%

Metrics

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

File(s)

C:\code\jordimontana82\fake-xrm-easy\FakeXrmEasy.Shared\FakeMessageExecutors\CloseIncidentRequestExecutor.cs

#LineLine coverage
 1using Microsoft.Crm.Sdk.Messages;
 2using Microsoft.Xrm.Sdk;
 3using System;
 4using System.Linq;
 5using System.ServiceModel;
 6
 7namespace FakeXrmEasy.FakeMessageExecutors
 8{
 9    public class CloseIncidentRequestExecutor : IFakeMessageExecutor
 10    {
 11        private const string AttributeIncidentId = "incidentid";
 12        private const string AttributeSubject = "subject";
 13        private const string IncidentLogicalName = "incident";
 14        private const string IncidentResolutionLogicalName = "incidentresolution";
 15        private const int StateResolved = 1;
 16
 17        public bool CanExecute(OrganizationRequest request)
 618        {
 619            return request is CloseIncidentRequest;
 620        }
 21
 22        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
 2423        {
 2424            var service = ctx.GetOrganizationService();
 2425            var closeIncidentRequest = (CloseIncidentRequest)request;
 26
 2427            var incidentResolution = closeIncidentRequest.IncidentResolution;
 2428             if (incidentResolution == null)
 629            {
 630                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Cannot close inciden
 31            }
 32
 1833            var status = closeIncidentRequest.Status;
 1834             if (status == null)
 635            {
 636                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Cannot close inciden
 37            }
 38
 1239            var incidentId = (EntityReference)incidentResolution[AttributeIncidentId];
 1240             if (ctx.Data.ContainsKey(IncidentLogicalName) &&
 2441                ctx.Data[IncidentLogicalName].Values.SingleOrDefault(p => p.Id == incidentId.Id) == null)
 642            {
 643                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(),
 644                    string.Format("Incident with id {0} not found.", incidentId.Id));
 45            }
 46
 647            var newIncidentResolution = new Entity
 648            {
 649                LogicalName = IncidentResolutionLogicalName,
 650                Attributes = new AttributeCollection
 651                {
 652                    { "description", incidentResolution[AttributeSubject] },
 653                    { AttributeSubject, incidentResolution[AttributeSubject] },
 654                    { AttributeIncidentId, incidentId }
 655                }
 656            };
 657            service.Create(newIncidentResolution);
 58
 659            var setState = new SetStateRequest
 660            {
 661                EntityMoniker = incidentId,
 662                Status = status,
 663                State = new OptionSetValue(StateResolved)
 664            };
 65
 666            service.Execute(setState);
 67
 668            return new CloseIncidentResponse();
 669        }
 70
 71        public Type GetResponsibleRequestType()
 427072        {
 427073            return typeof(CloseIncidentResponse);
 427074        }
 75    }
 76}