Summary

Class:FakeXrmEasy.FakeMessageExecutors.AddMembersTeamRequestExecutor
Assembly:FakeXrmEasy
File(s):F:\Git\fake-xrm-easy\FakeXrmEasy.Shared\FakeMessageExecutors\AddMembersTeamRequestExecutor.cs
Covered lines:32
Uncovered lines:4
Coverable lines:36
Total lines:64
Line coverage:88.8%
Branch coverage:100%

Metrics

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

File(s)

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

#LineLine coverage
 1using Microsoft.Crm.Sdk.Messages;
 2using Microsoft.Xrm.Sdk;
 3using System;
 4using System.Linq;
 5
 6namespace FakeXrmEasy.FakeMessageExecutors
 7{
 8  public class AddMembersTeamRequestExecutor : IFakeMessageExecutor
 9  {
 10    public bool CanExecute(OrganizationRequest request)
 3611    {
 3612      return request is AddMembersTeamRequest;
 3613    }
 14
 15    public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx)
 3616    {
 3617      var req = (AddMembersTeamRequest)request;
 18
 3619       if (req.MemberIds == null)
 620      {
 621        FakeOrganizationServiceFault.Throw(ErrorCodes.InvalidArgument, "MemberIds parameter is required");
 022      }
 23
 3024       if (req.TeamId == Guid.Empty)
 625      {
 626        FakeOrganizationServiceFault.Throw(ErrorCodes.InvalidArgument, "TeamId parameter is required");
 027      }
 28
 2429      var service = ctx.GetOrganizationService();
 30
 31      // Find the list
 2432      var team = ctx.CreateQuery("team").FirstOrDefault(e => e.Id == req.TeamId);
 33
 2434       if (team == null)
 1235      {
 1236        FakeOrganizationServiceFault.Throw(ErrorCodes.ObjectDoesNotExist, string.Format("Team with Id {0} wasn't found",
 037      }
 38
 39      //ToDo:  FakeOrganizationServiceFault.Throw(ErrorCodes.CannotAddMembersToDefaultTeam, "Can't add members to the de
 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          FakeOrganizationServiceFault.Throw(ErrorCodes.ObjectDoesNotExist, string.Format("SystemUser with Id {0} wasn't
 047        }
 48
 49        // Create teammembership
 650        var teammembership = new Entity("teammembership");
 651        teammembership["teamid"] = team.Id;
 652        teammembership["systemuserid"] = memberId;
 653        service.Create(teammembership);
 654      }
 55
 656      return new AddMembersTeamResponse();
 657    }
 58
 59    public Type GetResponsibleRequestType()
 426460    {
 426461      return typeof(AddMembersTeamRequest);
 426462    }
 63  }
 64}