Summary

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

Metrics

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

File(s)

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

#LineLine coverage
 1using Microsoft.Crm.Sdk.Messages;
 2using Microsoft.Xrm.Sdk;
 3using System;
 4using System.Linq;
 5using System.ServiceModel;
 6using Microsoft.Xrm.Sdk.Query;
 7
 8namespace FakeXrmEasy.FakeMessageExecutors
 9{
 10    public class RemoveMembersTeamRequestExecutor : IFakeMessageExecutor
 11    {
 12        public bool CanExecute(OrganizationRequest request)
 3613        {
 3614            return request is RemoveMembersTeamRequest;
 3615        }
 16
 17        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
 3618        {
 3619            var req = (RemoveMembersTeamRequest)request;
 20
 3621             if (req.TeamId == null || req.TeamId == Guid.Empty)
 622            {
 623                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "TeamId parameter is 
 24            }
 25
 3026             if (req.MemberIds == null)
 627            {
 628                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "MemberIds parameter 
 29            }
 30
 2431            var service = ctx.GetOrganizationService();
 32
 33            // Find the list
 2434            var team = ctx.CreateQuery("team").FirstOrDefault(e => e.Id == req.TeamId);
 35
 2436             if (team == null)
 1237            {
 1238                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), string.Format("Team w
 39            }
 40
 5441            foreach (var memberId in req.MemberIds)
 1242            {
 1243                var user = ctx.CreateQuery("systemuser").FirstOrDefault(e => e.Id == memberId);
 1244                 if (user == null)
 645                {
 646                    throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), string.Format("Sy
 47                }
 48
 649                var queryTeamMember = new QueryExpression("teammembership")
 650                {
 651                    TopCount = 1,
 652                    ColumnSet = new ColumnSet("teammembershipid"),
 653                    Criteria =
 654                    {
 655                        Conditions =
 656                        {
 657                            new ConditionExpression("teamid", ConditionOperator.Equal, req.TeamId),
 658                            new ConditionExpression("systemuserid", ConditionOperator.Equal, user.Id)
 659                        }
 660                    }
 661                };
 62
 663                var teamMember = ctx.Service.RetrieveMultiple(queryTeamMember).Entities.FirstOrDefault();
 64
 665                 if (teamMember != null)
 666                {
 667                    service.Delete("teammembership", teamMember.Id);
 668                }
 669            }
 70
 671            return new RemoveMembersTeamResponse();
 672        }
 73
 74        public Type GetResponsibleRequestType()
 426475        {
 426476            return typeof(RemoveMembersTeamRequest);
 426477        }
 78    }
 79}