public async Task <GroupMemberDiff> GetMemberDiffAsync(GrouperDocument document, bool includeUnchanged = false) { if (document is null) { throw new ArgumentNullException(nameof(document)); } var currentMembers = await GetCurrentMembersAsync(document); var targetMembers = await GetTargetMembersAsync(document); IGroupOwnerSource ownerSource = GetOwnerSource(document); if (ownerSource != null) { if (document.Owner != GroupOwnerActions.MatchSource) { var owners = new GroupMemberCollection(); await ownerSource.GetGroupOwnersAsync(owners, document.GroupId); if (document.Owner == GroupOwnerActions.KeepExisting) { owners.IntersectWith(currentMembers); } targetMembers.Add(owners); } } if (!currentMembers.ContainsMatchingMemberType(targetMembers)) { throw new InvalidOperationException("Member types does not match"); } GroupMemberCollection unchangedMembers = new GroupMemberCollection(); if (includeUnchanged) { unchangedMembers = currentMembers.Clone(); unchangedMembers.IntersectWith(targetMembers); } int currentCount = currentMembers.Count; currentMembers.FilterUniqueMember(targetMembers); double changeRatio; if (currentCount == 0) { changeRatio = targetMembers.Count == 0 ? 1.0 : targetMembers.Count; } else { changeRatio = (currentCount - currentMembers.Count + targetMembers.Count) / (double)currentCount; } return(new GroupMemberDiff(document, targetMembers, currentMembers, unchangedMembers, changeRatio)); }
public void TestIntersectWith() { GroupMemberCollection collection1 = new GroupMemberCollection(); GroupMemberCollection collection2 = new GroupMemberCollection(); collection1.Add(azureMember1); collection1.Add(azureMember2); collection2.Add(azureMember2); collection2.Add(azureMember3); collection1.IntersectWith(collection2); Assert.Equal(1, collection1.Count); Exception exception = Record.Exception(() => collection1.AsEnumerable().First(m => m.Id == azureMember2.Id)); Assert.Null(exception); }