private AzureADUser[] MakeUsers(int size, int startIdx) { var toreturn = new AzureADUser[size]; for (int i = 0; i < size; i++) { int thisIdx = startIdx + i; toreturn[i] = _help.UserNamed(thisIdx); } return(toreturn); }
private List <AzureADUser> MakeUsers(int size, int startIdx) { var helper = new TestObjectHelpers(); var users = new AzureADUser[size]; for (int i = 0; i < size; i++) { int thisIdx = startIdx + i; users[i] = helper.UserNamed(thisIdx); } return(users.ToList()); }
public async Task ProperlyGetsAndSendsMembershipWithMultipleSources() { const int userCount = 2500213; Guid[] sourceGroups = Enumerable.Range(0, 5).Select(_ => Guid.NewGuid()).ToArray(); Guid destinationGroup = Guid.NewGuid(); var mockGroups = new Dictionary <Guid, List <AzureADUser> >(); for (int i = 0; i < userCount; i++) { var currentGroup = sourceGroups[i % sourceGroups.Length]; var userToAdd = new AzureADUser { ObjectId = Guid.NewGuid() }; if (mockGroups.TryGetValue(currentGroup, out var users)) { users.Add(userToAdd); } else { mockGroups.Add(currentGroup, new List <AzureADUser> { userToAdd }); } } var graphRepo = new MockGraphGroupRepository() { GroupsToUsers = mockGroups }; var serviceBus = new MockMembershipServiceBusRepository(); var calc = new SGMembershipCalculator(graphRepo, serviceBus, new MockLogger()); await calc.SendMembership(new SyncJob { TargetOfficeGroupId = destinationGroup, Query = string.Join(';', sourceGroups) }); CollectionAssert.AreEquivalent(mockGroups.Values.SelectMany(x => x).ToArray(), serviceBus.Sent.SourceMembers); CollectionAssert.AreEqual(sourceGroups.Select(x => new AzureADGroup { ObjectId = x }).ToArray(), serviceBus.Sent.Sources); Assert.AreEqual(destinationGroup, serviceBus.Sent.Destination.ObjectId); }
public async Task ProperlyErrorsOnNonexistentGroups() { const int userCount = 2500213; var sourceGroups = Enumerable.Range(0, 5).Select(_ => Guid.NewGuid()).ToArray(); Guid destinationGroup = Guid.NewGuid(); var mockGroups = new Dictionary <Guid, List <AzureADUser> >(); for (int i = 0; i < userCount; i++) { var currentGroup = sourceGroups[i % sourceGroups.Length]; var userToAdd = new AzureADUser { ObjectId = Guid.NewGuid() }; if (mockGroups.TryGetValue(currentGroup, out var users)) { users.Add(userToAdd); } else { mockGroups.Add(currentGroup, new List <AzureADUser> { userToAdd }); } } var graphRepo = new MockGraphGroupRepository() { GroupsToUsers = mockGroups }; var serviceBus = new MockMembershipServiceBusRepository(); var calc = new SGMembershipCalculator(graphRepo, serviceBus, new MockLogger()); Guid nonexistentGroupId = Guid.NewGuid(); await calc.SendMembership(new SyncJob { TargetOfficeGroupId = destinationGroup, Query = string.Join(';', sourceGroups) + $";{nonexistentGroupId}" }); Assert.IsTrue(serviceBus.Sent.Errored); Assert.AreEqual(0, serviceBus.Sent.SourceMembers.Count); }
public async Task ProperlyGetsAndSendsMembershipWithMultipleSources(int getGroupExceptions, int getMembersExceptions) { const int userCount = 2500213; Guid[] sourceGroups = Enumerable.Range(0, 5).Select(_ => Guid.NewGuid()).ToArray(); Guid destinationGroup = Guid.NewGuid(); var allUsers = new List <AzureADUser> { }; var mockGroups = new Dictionary <Guid, List <AzureADUser> >(); for (int i = 0; i < userCount; i++) { var currentGroup = sourceGroups[i % sourceGroups.Length]; var userToAdd = new AzureADUser { ObjectId = Guid.NewGuid() }; if (mockGroups.TryGetValue(currentGroup, out var users)) { users.Add(userToAdd); } else { mockGroups.Add(currentGroup, new List <AzureADUser> { userToAdd }); } } var graphRepo = new MockGraphGroupRepository() { GroupsToUsers = mockGroups, ThrowSocketExceptionsFromGroupExistsBeforeSuccess = getGroupExceptions, ThrowSocketExceptionsFromGetUsersInGroupBeforeSuccess = getMembersExceptions }; var serviceBus = new MockMembershipServiceBusRepository(); var mail = new MockMailRepository(); var mailAddresses = new MockEmail <IEmailSenderRecipient>(); var syncJobs = new MockSyncJobRepository(); var dryRun = new MockDryRunValue() { DryRunEnabled = false }; var calc = new SGMembershipCalculator(graphRepo, serviceBus, mail, mailAddresses, syncJobs, new MockLoggingRepository(), dryRun); var testJob = new SyncJob { RowKey = "row", PartitionKey = "partition", TargetOfficeGroupId = destinationGroup, Query = string.Join(';', sourceGroups), Status = "InProgress" }; syncJobs.ExistingSyncJobs.Add((testJob.RowKey, testJob.PartitionKey), testJob); var groups = calc.ReadSourceGroups(testJob); await calc.SendMembershipAsync(testJob, Guid.NewGuid(), allUsers); foreach (var group in groups) { var groupExistsResult = await calc.GroupExistsAsync(group.ObjectId, Guid.NewGuid()); Assert.AreEqual(OutcomeType.Successful, groupExistsResult.Outcome); Assert.AreEqual(true, groupExistsResult.Result); } }
public async Task IgnoresNonGuidArguments(int getGroupExceptions, int getMembersExceptions) { const int userCount = 2500213; Guid[] sourceGroups = Enumerable.Range(0, 5).Select(_ => Guid.NewGuid()).ToArray(); Guid destinationGroup = Guid.NewGuid(); var mockGroups = new Dictionary <Guid, List <AzureADUser> >(); for (int i = 0; i < userCount; i++) { var currentGroup = sourceGroups[i % sourceGroups.Length]; var userToAdd = new AzureADUser { ObjectId = Guid.NewGuid() }; if (mockGroups.TryGetValue(currentGroup, out var users)) { users.Add(userToAdd); } else { mockGroups.Add(currentGroup, new List <AzureADUser> { userToAdd }); } } var graphRepo = new MockGraphGroupRepository() { GroupsToUsers = mockGroups, ThrowSocketExceptionsFromGroupExistsBeforeSuccess = getGroupExceptions, ThrowSocketExceptionsFromGetUsersInGroupBeforeSuccess = getMembersExceptions }; var serviceBus = new MockMembershipServiceBusRepository(); var mail = new MockMailRepository(); var mailAddresses = new MockEmail <IEmailSenderRecipient>(); var syncJobs = new MockSyncJobRepository(); var dryRun = new MockDryRunValue() { DryRunEnabled = false }; var calc = new SGMembershipCalculator(graphRepo, serviceBus, mail, mailAddresses, syncJobs, new MockLoggingRepository(), dryRun); var testJob = new SyncJob { RowKey = "row", PartitionKey = "partition", TargetOfficeGroupId = destinationGroup, Query = string.Join(';', sourceGroups) + ";nasdfasfd;;;", Status = "InProgress" }; syncJobs.ExistingSyncJobs.Add((testJob.RowKey, testJob.PartitionKey), testJob); var groups = calc.ReadSourceGroups(testJob); foreach (var group in groups) { await calc.SendEmailAsync(testJob, Guid.NewGuid(), "Content", null); } Assert.IsNull(serviceBus.Sent); }
public void FoundUser(AzureADUser user) => Users.Add(user);