Summary

Class:FakeXrmEasy.FakeMessageExecutors.RemoveUserFromRecordTeamRequestExecutor
Assembly:FakeXrmEasy
File(s):F:\Git\fake-xrm-easy\FakeXrmEasy.Shared\FakeMessageExecutors\RemoveUserFromRecordTeamRequestExecutor.cs
Covered lines:32
Uncovered lines:15
Coverable lines:47
Total lines:82
Line coverage:68%
Branch coverage:50%

Metrics

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

File(s)

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

#LineLine coverage
 1#if FAKE_XRM_EASY_2013 || FAKE_XRM_EASY_2015 || FAKE_XRM_EASY_2016 || FAKE_XRM_EASY_365 || FAKE_XRM_EASY_9
 2using System;
 3using System.Linq;
 4using Microsoft.Xrm.Sdk;
 5using System.ServiceModel;
 6using Microsoft.Crm.Sdk.Messages;
 7
 8namespace FakeXrmEasy.FakeMessageExecutors
 9{
 10    public class RemoveUserFromRecordTeamRequestExecutor : IFakeMessageExecutor
 11    {
 12        public bool CanExecute(OrganizationRequest request)
 513        {
 514            return request is RemoveUserFromRecordTeamRequest;
 515        }
 16
 17        public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
 518        {
 519            RemoveUserFromRecordTeamRequest remReq = (RemoveUserFromRecordTeamRequest)request;
 20
 521            EntityReference target = remReq.Record;
 522            Guid systemuserId = remReq.SystemUserId;
 523            Guid teamTemplateId = remReq.TeamTemplateId;
 24
 525             if (target == null)
 026            {
 027                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not remove from 
 28            }
 29
 530             if (systemuserId == Guid.Empty)
 031            {
 032                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not remove from 
 33            }
 34
 535             if (teamTemplateId == Guid.Empty)
 036            {
 037                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Can not remove from 
 38            }
 39
 540            Entity teamTemplate = ctx.CreateQuery("teamtemplate").FirstOrDefault(p => p.Id == teamTemplateId);
 541             if (teamTemplate == null)
 042            {
 043                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "Team template with i
 44            }
 45
 546            Entity user = ctx.CreateQuery("systemuser").FirstOrDefault(p => p.Id == systemuserId);
 547             if (user == null)
 048            {
 049                throw new FaultException<OrganizationServiceFault>(new OrganizationServiceFault(), "User with id=" + tea
 50            }
 51
 552            IOrganizationService service = ctx.GetOrganizationService();
 53
 554            ctx.AccessRightsRepository.RevokeAccessTo(target, user.ToEntityReference());
 555            Entity team = ctx.CreateQuery("team").FirstOrDefault(p => ((EntityReference)p["teamtemplateid"]).Id == teamT
 556             if (team == null)
 057            {
 058                return new RemoveUserFromRecordTeamResponse
 059                {
 060                    ResponseName = "RemoveUserFromRecordTeam"
 061                };
 62            }
 63
 564            Entity tm = ctx.CreateQuery("teammembership").FirstOrDefault(p => (Guid)p["teamid"] == team.Id);
 565             if (tm != null)
 566            {
 567                service.Delete(tm.LogicalName, tm.Id);
 568            }
 69
 570            return new RemoveUserFromRecordTeamResponse
 571            {
 572                ResponseName = "RemoveUserFromRecordTeam"
 573            };
 574        }
 75
 76        public Type GetResponsibleRequestType()
 359277        {
 359278            return typeof(RemoveUserFromRecordTeamRequestExecutor);
 359279        }
 80    }
 81}
 82#endif