public async Task SendNotificationToSupportAsFallBack() { var calculator = new MembershipDifferenceCalculator <AzureADUser>(); var senderRecipients = new EmailSenderRecipient { SupportEmailAddresses = "*****@*****.**" }; var syncjobRepository = new MockSyncJobRepository(); var loggingRepository = new MockLoggingRepository(); var mailRepository = new MockMailRepository(); var dryRun = new DryRunValue(); var thresholdConfig = new ThresholdConfig(5, 3, 3, 10); var graphUpdaterService = new MockGraphUpdaterService(mailRepository); var deltaCalculator = new DeltaCalculatorService( calculator, syncjobRepository, loggingRepository, senderRecipients, graphUpdaterService, dryRun, thresholdConfig, _gmmResources, _localizationRepository); var targetGroupUsers = new List <AzureADUser>(); var ownersPage = new GroupOwnersPage(); var owners = new List <User>(GenerateGraphUsers(10)); owners.ForEach(ownersPage.Add); _job.LastRunTime = DateTime.UtcNow.AddDays(-1); _job.ThresholdViolations = 2; syncjobRepository.ExistingSyncJobs.Add((_partitionKey, _rowKey), _job); graphUpdaterService.GroupsToUsers.Add(_sources[0].ObjectId, _users); graphUpdaterService.GroupsToUsers.Add(_targetGroupId, targetGroupUsers); graphUpdaterService.Groups.Add(_sources[0].ObjectId, new Group { Id = _sources[0].ObjectId.ToString(), DisplayName = "Source Group" }); graphUpdaterService.Groups.Add(_targetGroupId, new Group { Id = _targetGroupId.ToString(), DisplayName = "Target Group", Owners = ownersPage }); var response = await deltaCalculator.CalculateDifferenceAsync(_membership, targetGroupUsers); var emailMessage = mailRepository.SentEmails.Single(); Assert.AreEqual(SyncStatus.Idle, response.SyncStatus); Assert.AreEqual(GraphUpdaterStatus.ThresholdExceeded, response.GraphUpdaterStatus); Assert.AreEqual(targetGroupUsers.Count, graphUpdaterService.GroupsToUsers[_targetGroupId].Count); Assert.IsTrue(loggingRepository.MessagesLogged.Any(x => x.Message.Contains("is greater than threshold value"))); Assert.AreEqual(SyncThresholdBothEmailBody, emailMessage.Content); Assert.AreEqual(_targetGroupId.ToString(), emailMessage.AdditionalContentParams[1]); Assert.AreEqual(5, emailMessage.AdditionalContentParams.Length); Assert.AreEqual(senderRecipients.SupportEmailAddresses, emailMessage.ToEmailAddresses); }
public async Task DoNotSendNotificationToRequestor(int currentThresoldViolations) { var calculator = new MembershipDifferenceCalculator <AzureADUser>(); var senderRecipients = new EmailSenderRecipient { SyncDisabledCCAddresses = "*****@*****.**" }; var syncjobRepository = new MockSyncJobRepository(); var loggingRepository = new MockLoggingRepository(); var mailRepository = new MockMailRepository(); var dryRun = new DryRunValue(); var thresholdConfig = new ThresholdConfig(5, 3, 3, 10); var graphUpdaterService = new MockGraphUpdaterService(mailRepository); var deltaCalculator = new DeltaCalculatorService( calculator, syncjobRepository, loggingRepository, senderRecipients, graphUpdaterService, dryRun, thresholdConfig, _gmmResources, _localizationRepository); var targetGroupUsers = new List <AzureADUser>(); var ownersPage = new GroupOwnersPage(); var owners = new List <User>(); foreach (var email in _job.Requestor.Split(",", StringSplitOptions.RemoveEmptyEntries)) { owners.Add(new User { Mail = email }); } owners.AddRange(GenerateGraphUsers(3)); owners.ForEach(ownersPage.Add); _job.LastRunTime = DateTime.UtcNow.AddDays(-1); _job.ThresholdViolations = currentThresoldViolations; syncjobRepository.ExistingSyncJobs.Add((_partitionKey, _rowKey), _job); graphUpdaterService.GroupsToUsers.Add(_sources[0].ObjectId, _users); graphUpdaterService.GroupsToUsers.Add(_targetGroupId, targetGroupUsers); graphUpdaterService.Groups.Add(_sources[0].ObjectId, new Group { Id = _sources[0].ObjectId.ToString(), DisplayName = "Source Group" }); graphUpdaterService.Groups.Add(_targetGroupId, new Group { Id = _targetGroupId.ToString(), DisplayName = "Target Group", Owners = ownersPage }); var response = await deltaCalculator.CalculateDifferenceAsync(_membership, targetGroupUsers); var emailMessage = mailRepository.SentEmails.Count(); Assert.AreEqual(SyncStatus.Idle, response.SyncStatus); Assert.AreEqual(GraphUpdaterStatus.ThresholdExceeded, response.GraphUpdaterStatus); Assert.AreEqual(targetGroupUsers.Count, graphUpdaterService.GroupsToUsers[_targetGroupId].Count); Assert.IsTrue(loggingRepository.MessagesLogged.Any(x => x.Message.Contains("is greater than threshold value"))); Assert.AreEqual(0, mailRepository.SentEmails.Count); }