Esempio n. 1
0
        public async Task ProperlyGetsAndSendsMembership(int getGroupExceptions, int getMembersExceptions)
        {
            const int userCount   = 2500213;
            var       allUsers    = new List <AzureADUser> {
            };
            Guid sourceGroup      = Guid.NewGuid();
            Guid destinationGroup = Guid.NewGuid();
            var  initialUsers     = Enumerable.Range(0, userCount).Select(
                x => new AzureADUser {
                ObjectId = Guid.NewGuid()
            }).ToList();

            var graphRepo = new MockGraphGroupRepository()
            {
                GroupsToUsers = new Dictionary <Guid, List <AzureADUser> > {
                    { sourceGroup, initialUsers }
                },
                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  = sourceGroup.ToString(),
                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);
            }
        }
Esempio n. 2
0
        public async Task ProperlyErrorsOnAllNonexistentGroups(int getGroupExceptions, int getMembersExceptions)
        {
            Guid[] sourceGroups     = Enumerable.Range(0, 5).Select(_ => Guid.NewGuid()).ToArray();
            Guid   destinationGroup = Guid.NewGuid();
            var    graphRepo        = new MockGraphGroupRepository()
            {
                GroupsToUsers = new Dictionary <Guid, List <AzureADUser> >(),
                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) + $";{Guid.NewGuid()}",
                Status = "InProgress"
            };

            syncJobs.ExistingSyncJobs.Add((testJob.RowKey, testJob.PartitionKey), testJob);

            var groups = calc.ReadSourceGroups(testJob);

            foreach (var group in groups)
            {
                var groupExistsResult = await calc.GroupExistsAsync(group.ObjectId, Guid.NewGuid());

                Assert.AreEqual(false, groupExistsResult.Result);
            }
            Assert.IsNull(serviceBus.Sent);
        }
Esempio n. 3
0
        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);
            }
        }