Summary

Class:FakeXrmEasy.FakeMessageExecutors.ReviseQuoteRequestExecutor
Assembly:FakeXrmEasy
File(s):F:\Git\fake-xrm-easy\FakeXrmEasy.Shared\FakeMessageExecutors\ReviseQuoteRequestExecutor.cs
Covered lines:67
Uncovered lines:4
Coverable lines:71
Total lines:114
Line coverage:94.3%
Branch coverage:71.4%

Metrics

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

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text;
 5using Microsoft.Crm.Sdk.Messages;
 6using Microsoft.Xrm.Sdk;
 7using Microsoft.Xrm.Sdk.Messages;
 8using Microsoft.Xrm.Sdk.Query;
 9
 10namespace FakeXrmEasy.FakeMessageExecutors
 11{
 12    public class ReviseQuoteRequestExecutor : IFakeMessageExecutor
 13    {
 14        public bool CanExecute(OrganizationRequest request)
 615        {
 616            return request is ReviseQuoteRequest;
 617        }
 18
 19        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
 620        {
 621            var service = ctx.GetOrganizationService();
 22
 623            var reviseQuoteRequest = request as ReviseQuoteRequest;
 24
 625             if (reviseQuoteRequest == null)
 026            {
 027                throw new Exception("You did not pass a ReviseQuoteRequest!");
 28            }
 29
 630            var oldQuoteId = reviseQuoteRequest.QuoteId;
 31
 632             if (oldQuoteId == Guid.Empty)
 033            {
 034                throw new Exception("QuoteId needs to be set!");
 35            }
 36
 637            var oldQuote = service.Retrieve("quote", oldQuoteId, new ColumnSet(true));
 38
 639            var revisedQuote = new Entity
 640            {
 641                LogicalName = "quote",
 642                Id = Guid.NewGuid()
 643            };
 44
 645            var columnSet = reviseQuoteRequest.ColumnSet;
 646            var quoteBlackList = new List<string> { "quoteid", "statuscode", "statecode", "createdon", "createdby" };
 47
 12648            foreach (var attribute in oldQuote.Attributes)
 5449            {
 5450                 if (quoteBlackList.Contains(attribute.Key))
 3051                {
 3052                    continue;
 53                }
 54
 2455                 if (columnSet.AllColumns || columnSet.Columns.Contains(attribute.Key))
 2456                {
 2457                     if(attribute.Key != "statecode")  //Skip statecode on create
 2458                        revisedQuote[attribute.Key] = attribute.Value;
 2459                }
 2460            }
 61
 662            service.Create(revisedQuote);
 63
 664            var quoteLines = service.RetrieveMultiple(new QueryExpression("quotedetail")
 665            {
 666                ColumnSet = new ColumnSet(true),
 667                Criteria = new FilterExpression(LogicalOperator.And)
 668                {
 669                    Conditions = { new ConditionExpression("quoteid", ConditionOperator.Equal, oldQuote.ToEntityReferenc
 670                }
 671            }).Entities.ToList();
 72
 3073            foreach (var quoteDetail in quoteLines)
 674            {
 675                var revisedDetail = new Entity
 676                {
 677                    LogicalName = "quotedetail",
 678                    Id = Guid.NewGuid(),
 679                    Attributes = new AttributeCollection
 680                    {
 681                        { "quoteid", revisedQuote.ToEntityReference() }
 682                    }
 683                };
 84
 685                var quoteDetailBlackList = new List<string> { "quoteid", "quotedetailid", "createdon", "createdby" };
 86
 12687                foreach (var attribute in quoteDetail.Attributes)
 5488                {
 5489                     if (quoteDetailBlackList.Contains(attribute.Key))
 2490                    {
 2491                        continue;
 92                    }
 3093                     if (attribute.Key != "statecode")  //Skip statecode on create
 2494                        revisedDetail[attribute.Key] = attribute.Value;
 3095                }
 96
 697                service.Create(revisedDetail);
 698            }
 99
 6100            var response = new ReviseQuoteResponse();
 101
 6102            revisedQuote = service.Retrieve(revisedQuote.LogicalName, revisedQuote.Id, new ColumnSet(true));
 103
 6104            response.Results["Entity"] = revisedQuote;
 105
 6106            return response;
 6107        }
 108
 109        public Type GetResponsibleRequestType()
 4264110        {
 4264111            return typeof(ReviseQuoteRequest);
 4264112        }
 113    }
 114}