Summary

Class:FakeXrmEasy.FakeMessageExecutors.RetrieveExchangeRateRequestExecutor
Assembly:FakeXrmEasy
File(s):C:\code\jordimontana82\fake-xrm-easy\FakeXrmEasy.Shared\FakeMessageExecutors\RetrieveExchangeRateRequest.cs
Covered lines:3
Uncovered lines:31
Coverable lines:34
Total lines:64
Line coverage:8.8%
Branch coverage:0%

Metrics

MethodCyclomatic ComplexitySequence CoverageBranch Coverage
CanExecute(...)100
Execute(...)200
GetResponsibleRequestType()1100100

File(s)

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

#LineLine coverage
 1using Microsoft.Crm.Sdk.Messages;
 2using Microsoft.Xrm.Sdk;
 3using System;
 4using System.Collections.Generic;
 5using System.Linq;
 6using System.ServiceModel;
 7using Microsoft.Xrm.Sdk.Query;
 8
 9namespace FakeXrmEasy.FakeMessageExecutors
 10{
 11    public class RetrieveExchangeRateRequestExecutor : IFakeMessageExecutor
 12    {
 13        public bool CanExecute(OrganizationRequest request)
 014        {
 015            return request is RetrieveExchangeRateRequest;
 016        }
 17
 18        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
 019        {
 020            var retrieveExchangeRateRequest = (RetrieveExchangeRateRequest)request;
 21
 022            var currencyId = retrieveExchangeRateRequest.TransactionCurrencyId;
 23
 024            if (currencyId == null)
 25            {
 26                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not retrieve Exc
 27            }
 28
 029            var service = ctx.GetOrganizationService();
 30
 031            var result = service.RetrieveMultiple(new QueryExpression("transactioncurrency")
 032            {
 033                ColumnSet = new ColumnSet("exchangerate"),
 034                Criteria = new FilterExpression
 035                {
 036                    Conditions =
 037                    {
 038                        new ConditionExpression("transactioncurrencyid", ConditionOperator.Equal, currencyId)
 039                    }
 040                }
 041            }).Entities;
 42
 043             if (!result.Any())
 044            {
 045                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Transaction Currency
 46            }
 47
 048            var exchangeRate = result.First().GetAttributeValue<decimal>("exchangerate");
 49
 050            return new RetrieveExchangeRateResponse
 051            {
 052                Results = new ParameterCollection
 053                {
 054                    {"ExchangeRate", exchangeRate}
 055                }
 056            };
 057        }
 58
 59        public Type GetResponsibleRequestType()
 427060        {
 427061            return typeof(RetrieveExchangeRateRequest);
 427062        }
 63    }
 64}