public void SyncsGroupsCorrectly() { var mockGroups = new MockGraphGroupRepository(); var mockSyncJobs = new MockSyncJobRepository(); var mockLogs = new MockLoggingRepository(); var mockMails = new MockMailRepository(); var mockGraph = new MockGraphGroupRepository(); var mockEmail = new MockEmail <IEmailSenderRecipient>(); var updater = new GraphUpdaterApplication(new MembershipDifferenceCalculator <AzureADUser>(), mockGroups, mockSyncJobs, mockLogs, mockMails, mockGraph, mockEmail); var sessionCollector = new SessionMessageCollector(updater); var mockSession = new MockMessageSession() { SessionId = "someId" }; var syncJobKeys = (Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); var syncJob = new SyncJob(syncJobKeys.Item1, syncJobKeys.Item2) { Enabled = true, Status = "InProgress", }; mockSyncJobs.ExistingSyncJobs.Add(syncJobKeys, syncJob); var incomingMessages = MakeMembershipMessages(); mockGroups.GroupsToUsers.Add(incomingMessages.First().Body.Destination.ObjectId, new List <AzureADUser>() { new AzureADUser { ObjectId = Guid.NewGuid() } }); foreach (var message in incomingMessages) { message.Body.SyncJobPartitionKey = syncJobKeys.Item1; message.Body.SyncJobRowKey = syncJobKeys.Item2; } foreach (var message in incomingMessages.SkipLast(1)) { sessionCollector.HandleNewMessage(message, mockSession); // sessionCollector doesn't do anything until it gets the last message. Assert.AreEqual(0, mockLogs.MessagesLogged); Assert.IsFalse(mockSession.Closed); Assert.AreEqual(0, mockSession.CompletedLockTokens.Count); } sessionCollector.HandleNewMessage(incomingMessages.Last(), mockSession); Assert.IsTrue(mockSession.Closed); Assert.AreEqual(9, mockLogs.MessagesLogged); Assert.AreEqual("Idle", syncJob.Status); Assert.IsTrue(syncJob.Enabled); Assert.AreEqual(1, mockGroups.GroupsToUsers.Count); Assert.AreEqual(MockGroupMembershipHelper.UserCount, mockGroups.GroupsToUsers.Values.Single().Count); }
public async Task UpdateSyncJobStatusDryRunModeTest() { var mockLogs = new MockLoggingRepository(); var telemetryClient = new TelemetryClient(TelemetryConfiguration.CreateDefault()); var mockGraphGroup = new MockGraphGroupRepository(); var mockMail = new MockMailRepository(); var mailSenders = new EmailSenderRecipient("*****@*****.**", "fake_pass", "*****@*****.**", "*****@*****.**", "*****@*****.**"); var mockSynJobs = new MockSyncJobRepository(); var dryRun = new DryRunValue(false); var graphUpdaterService = new GraphUpdaterService(mockLogs, telemetryClient, mockGraphGroup, mockMail, mailSenders, mockSynJobs, dryRun); var runId = Guid.NewGuid(); var lastRunTime = DateTime.UtcNow.AddDays(-1); var job = new SyncJob { PartitionKey = "00-00-00", RowKey = Guid.NewGuid().ToString(), Status = SyncStatus.InProgress.ToString(), Enabled = true, DryRunTimeStamp = lastRunTime }; mockSynJobs.ExistingSyncJobs.Add((job.PartitionKey, job.RowKey), job); await graphUpdaterService.UpdateSyncJobStatusAsync(job, SyncStatus.Idle, true, runId); Assert.AreEqual(SyncStatus.Idle.ToString(), job.Status); Assert.IsTrue(job.DryRunTimeStamp > lastRunTime); Assert.IsTrue(job.LastRunTime < lastRunTime); Assert.IsNotNull(job.RunId); }
public async Task GroupExistsSocketExceptionTest() { var mockLogs = new MockLoggingRepository(); var telemetryClient = new TelemetryClient(TelemetryConfiguration.CreateDefault()); var mockGraphGroup = new Mock <IGraphGroupRepository>(); var mockMail = new MockMailRepository(); var mailSenders = new EmailSenderRecipient("*****@*****.**", "fake_pass", "*****@*****.**", "*****@*****.**", "*****@*****.**"); var mockSynJobs = new MockSyncJobRepository(); var dryRun = new DryRunValue(false); var attemptNumber = 1; mockGraphGroup.Setup(x => x.GroupExists(It.IsAny <Guid>())).Callback(() => { if (attemptNumber == 1) { attemptNumber++; throw new SocketException(); } }).ReturnsAsync(true); var graphUpdaterService = new GraphUpdaterService(mockLogs, telemetryClient, mockGraphGroup.Object, mockMail, mailSenders, mockSynJobs, dryRun); var groupId = Guid.NewGuid(); var runId = Guid.NewGuid(); var response = await graphUpdaterService.GroupExistsAsync(groupId, runId); Assert.IsTrue(response.Result); Assert.IsTrue(mockLogs.MessagesLogged.Any(x => x.Message.Contains("Got a transient SocketException"))); }
public async Task CalculateDeltaForInitialGroupSyncWithMissingTargetGroup() { var calculator = new MembershipDifferenceCalculator <AzureADUser>(); var senderRecipients = new EmailSenderRecipient(); 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); syncjobRepository.ExistingSyncJobs.Add((_partitionKey, _rowKey), _job); graphUpdaterService.GroupsToUsers.Add(_sources[0].ObjectId, _users); var response = await deltaCalculator.CalculateDifferenceAsync(_membership, new List <AzureADUser>()); Assert.AreEqual(SyncStatus.Error, response.SyncStatus); Assert.AreEqual(GraphUpdaterStatus.Error, response.GraphUpdaterStatus); Assert.IsTrue(loggingRepository.MessagesLogged.Any(x => x.Message.Contains($"destination group {_membership.Destination} doesn't exist"))); }
public async Task CalculateDeltaWithMissingSyncJob() { var calculator = new MembershipDifferenceCalculator <AzureADUser>(); var senderRecipients = new EmailSenderRecipient(); 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>(); graphUpdaterService.GroupsToUsers.Add(_sources[0].ObjectId, _users); graphUpdaterService.GroupsToUsers.Add(_targetGroupId, targetGroupUsers); var response = await deltaCalculator.CalculateDifferenceAsync(_membership, targetGroupUsers); Assert.AreEqual(SyncStatus.Error, response.SyncStatus); Assert.AreEqual(GraphUpdaterStatus.Error, response.GraphUpdaterStatus); }
public async Task GetNextMembersPageTest() { var mockLogs = new MockLoggingRepository(); var telemetryClient = new TelemetryClient(TelemetryConfiguration.CreateDefault()); var mockGraphGroup = new Mock <IGraphGroupRepository>(); var mockMail = new MockMailRepository(); var mailSenders = new EmailSenderRecipient("*****@*****.**", "fake_pass", "*****@*****.**", "*****@*****.**", "*****@*****.**"); var mockSynJobs = new MockSyncJobRepository(); var dryRun = new DryRunValue(false); var samplePageResponse = GetPageSampleResponse(100, true); var userCount = 100; mockGraphGroup.Setup(x => x.GetNextUsersPageAsync(It.IsAny <string>(), It.IsAny <IGroupTransitiveMembersCollectionWithReferencesPage>())) .ReturnsAsync(samplePageResponse); var graphUpdaterService = new GraphUpdaterService(mockLogs, telemetryClient, mockGraphGroup.Object, mockMail, mailSenders, mockSynJobs, dryRun); var groupId = Guid.NewGuid(); var runId = Guid.NewGuid(); var nextPageUrl = samplePageResponse.nextPageUrl; var response = await graphUpdaterService.GetNextMembersPageAsync(nextPageUrl, samplePageResponse.usersFromGroup, runId); Assert.IsNotNull(response.NextPageUrl); Assert.AreEqual(userCount, response.Members.Count); }
public async Task RemoveUsersToGroupInDryRunMode() { var mockLogs = new MockLoggingRepository(); var telemetryClient = new TelemetryClient(TelemetryConfiguration.CreateDefault()); var mockGraphGroup = new MockGraphGroupRepository(); var mockMail = new MockMailRepository(); var mailSenders = new EmailSenderRecipient("*****@*****.**", "fake_pass", "*****@*****.**", "*****@*****.**", "*****@*****.**"); var mockSynJobs = new MockSyncJobRepository(); var dryRun = new DryRunValue(true); var graphUpdaterService = new GraphUpdaterService(mockLogs, telemetryClient, mockGraphGroup, mockMail, mailSenders, mockSynJobs, dryRun); var runId = Guid.NewGuid(); var groupId = Guid.NewGuid(); bool isInitialSync = false; var newUsers = new List <AzureADUser>(); var userCount = 10; for (int i = 0; i < userCount; i++) { newUsers.Add(new AzureADUser { ObjectId = Guid.NewGuid() }); } mockGraphGroup.GroupsToUsers.Add(groupId, newUsers); var status = await graphUpdaterService.RemoveUsersFromGroupAsync(newUsers.Take(5).ToList(), groupId, runId, isInitialSync); Assert.AreEqual(GraphUpdaterStatus.Ok, status.Status); Assert.AreEqual(newUsers.Count, mockGraphGroup.GroupsToUsers[groupId].Count); }
public void InitializeTest() { _syncJobRepository = new MockSyncJobRepository(); _loggingRepository = new MockLoggingRepository(); _serviceBusTopicsRepository = new MockServiceBusTopicsRepository(); _graphGroupRepository = new MockGraphGroupRepository(); _syncJobTopicsService = new SyncJobTopicsService(_loggingRepository, _syncJobRepository, _serviceBusTopicsRepository, _graphGroupRepository, new MockKeyVaultSecret <ISyncJobTopicService>()); }
public void HandlesErroredJobs() { var mockGroups = new MockGraphGroupRepository(); var mockSyncJobs = new MockSyncJobRepository(); var mockLogs = new MockLoggingRepository(); var updater = new GraphUpdaterApplication(new MembershipDifferenceCalculator <AzureADUser>(), mockGroups, mockSyncJobs, mockLogs); var sessionCollector = new SessionMessageCollector(updater); var mockSession = new MockMessageSession() { SessionId = "someId" }; var syncJobKeys = (Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); var syncJob = new SyncJob(syncJobKeys.Item1, syncJobKeys.Item2) { Enabled = true, Status = "InProgress", }; mockSyncJobs.ExistingSyncJobs.Add(syncJobKeys, syncJob); var incomingMessage = new GroupMembershipMessage { LockToken = "hi", Body = new Entities.ServiceBus.GroupMembership { Errored = true, Sources = new[] { new AzureADGroup { ObjectId = Guid.NewGuid() } }, Destination = new AzureADGroup { ObjectId = Guid.NewGuid() }, IsLastMessage = true, RunId = Guid.NewGuid(), SourceMembers = new List <AzureADUser>(), SyncJobPartitionKey = syncJobKeys.Item1.ToString(), SyncJobRowKey = syncJobKeys.Item2.ToString() } }; mockGroups.GroupsToUsers.Add(incomingMessage.Body.Destination.ObjectId, new List <AzureADUser>() { new AzureADUser { ObjectId = Guid.NewGuid() } }); sessionCollector.HandleNewMessage(incomingMessage, mockSession); Assert.IsTrue(mockSession.Closed); Assert.AreEqual("Error", syncJob.Status); Assert.IsFalse(syncJob.Enabled); Assert.AreEqual(1, mockGroups.GroupsToUsers.Count); Assert.AreEqual(1, mockGroups.GroupsToUsers.Values.Single().Count); }
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 void InitializeTest() { _syncJobRepository = new MockSyncJobRepository(); _loggingRepository = new MockLoggingRepository(); _serviceBusTopicsRepository = new MockServiceBusTopicsRepository(); _graphGroupRepository = new MockGraphGroupRepository(); _mailRepository = new MockMailRepository(); _jobTriggerService = new JobTriggerService(_loggingRepository, _syncJobRepository, _serviceBusTopicsRepository, _graphGroupRepository, new MockKeyVaultSecret <IJobTriggerService>(), _mailRepository, new MockEmail <IEmailSenderRecipient>()); }
public void SetupTest() { _instanceId = "1234567890"; _durableClientMock = new Mock <IDurableOrchestrationClient>(); _loggerMock = new MockLoggingRepository(); _messageSessionMock = new Mock <IMessageSession>(); _messageService = new Mock <IServiceBusMessageService>(); _configuration = new Mock <IConfiguration>(); }
public async Task CalculateDeltaForNonInitialGroupSyncExceedingBothThresholds() { var calculator = new MembershipDifferenceCalculator <AzureADUser>(); var senderRecipients = new EmailSenderRecipient(); 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 users = _membership.SourceMembers; _membership.SourceMembers = users.Take(2).ToList(); _job.LastRunTime = DateTime.UtcNow.AddDays(-1); _job.ThresholdViolations = 2; var targetGroupUsers = users.Skip(2).Take(2).ToList(); syncjobRepository.ExistingSyncJobs.Add((_partitionKey, _rowKey), _job); graphUpdaterService.GroupsToUsers.Add(_sources[0].ObjectId, _membership.SourceMembers); graphUpdaterService.GroupsToUsers.Add(_targetGroupId, targetGroupUsers); graphUpdaterService.Groups.Add(_sources[0].ObjectId, new Microsoft.Graph.Group { Id = _sources[0].ObjectId.ToString(), DisplayName = "Source Group" }); graphUpdaterService.Groups.Add(_targetGroupId, new Microsoft.Graph.Group { Id = _targetGroupId.ToString(), DisplayName = "Target Group" }); 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 lesser than threshold value"))); Assert.AreEqual(SyncThresholdBothEmailBody, emailMessage.Content); Assert.AreEqual(_targetGroupId.ToString(), emailMessage.AdditionalContentParams[1]); Assert.AreEqual(5, emailMessage.AdditionalContentParams.Length); }
public void InitializeTest() { _mockSyncJobRepository = new MockSyncJobRepository(); _defaultRuntimeRetrievalService = new DefaultRuntimeRetrievalService(DEFAULT_RUNTIME_SECONDS); _mockLoggingRepository = new MockLoggingRepository(); _jobSchedulerConfig = new JobSchedulerConfig(true, 0, true, false, START_TIME_DELAY_MINUTES, BUFFER_SECONDS, DEFAULT_RUNTIME_SECONDS);; _jobSchedulingService = new JobSchedulingService( _jobSchedulerConfig, _mockSyncJobRepository, _defaultRuntimeRetrievalService, _mockLoggingRepository ); }
public void IgnoresMissingDestinationGroup() { var mockGroups = new MockGraphGroupRepository(); var mockSyncJobs = new MockSyncJobRepository(); var mockLogs = new MockLoggingRepository(); var updater = new GraphUpdaterApplication(new MembershipDifferenceCalculator <AzureADUser>(), mockGroups, mockSyncJobs, mockLogs); var sessionCollector = new SessionMessageCollector(updater); var mockSession = new MockMessageSession() { SessionId = "someId" }; var syncJobKeys = (Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); var syncJob = new SyncJob(syncJobKeys.Item1, syncJobKeys.Item2) { Enabled = true, Status = "InProgress", }; mockSyncJobs.ExistingSyncJobs.Add(syncJobKeys, syncJob); var incomingMessages = MakeMembershipMessages(); foreach (var message in incomingMessages) { message.Body.SyncJobPartitionKey = syncJobKeys.Item1; message.Body.SyncJobRowKey = syncJobKeys.Item2; } foreach (var message in incomingMessages.SkipLast(1)) { sessionCollector.HandleNewMessage(message, mockSession); // sessionCollector doesn't do anything until it gets the last message. Assert.AreEqual(0, mockLogs.MessagesLogged); Assert.IsFalse(mockSession.Closed); Assert.AreEqual(0, mockSession.CompletedLockTokens.Count); } sessionCollector.HandleNewMessage(incomingMessages.Last(), mockSession); Assert.IsTrue(mockSession.Closed); Assert.AreEqual(4, mockLogs.MessagesLogged); Assert.AreEqual("Error", syncJob.Status); Assert.IsFalse(syncJob.Enabled); Assert.AreEqual(0, mockGroups.GroupsToUsers.Count); }
public async Task CalculateDeltaForInitialGroupSync() { var calculator = new MembershipDifferenceCalculator <AzureADUser>(); var senderRecipients = new EmailSenderRecipient(); var syncjobRepository = new MockSyncJobRepository(); var loggingRepository = new MockLoggingRepository(); var mailRepository = new MockMailRepository(); var graphUpdaterService = new MockGraphUpdaterService(mailRepository); var dryRun = new DryRunValue(); var thresholdConfig = new ThresholdConfig(5, 3, 3, 10); dryRun.DryRunEnabled = false; var deltaCalculator = new DeltaCalculatorService( calculator, syncjobRepository, loggingRepository, senderRecipients, graphUpdaterService, dryRun, thresholdConfig, _gmmResources, _localizationRepository); var targetGroupUsers = new List <AzureADUser>(); 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 Microsoft.Graph.Group { Id = _sources[0].ObjectId.ToString(), DisplayName = "Source Group" }); graphUpdaterService.Groups.Add(_targetGroupId, new Microsoft.Graph.Group { Id = _targetGroupId.ToString(), DisplayName = "Target Group" }); var response = await deltaCalculator.CalculateDifferenceAsync(_membership, targetGroupUsers); Assert.AreEqual(SyncStatus.Idle, response.SyncStatus); Assert.AreEqual(_users.Count, response.MembersToAdd.Count); Assert.IsTrue(response.IsInitialSync); Assert.AreEqual(GraphUpdaterStatus.Ok, response.GraphUpdaterStatus); }
public async Task GetGroupNameTest() { var mockLogs = new MockLoggingRepository(); var telemetryClient = new TelemetryClient(TelemetryConfiguration.CreateDefault()); var mockGraphGroup = new Mock <IGraphGroupRepository>(); var mockMail = new MockMailRepository(); var mailSenders = new EmailSenderRecipient("*****@*****.**", "fake_pass", "*****@*****.**", "*****@*****.**", "*****@*****.**"); var mockSynJobs = new MockSyncJobRepository(); var dryRun = new DryRunValue(false); var graphUpdaterService = new GraphUpdaterService(mockLogs, telemetryClient, mockGraphGroup.Object, mockMail, mailSenders, mockSynJobs, dryRun); var groupName = "MyTestGroup"; mockGraphGroup.Setup(x => x.GetGroupNameAsync(It.IsAny <Guid>())).ReturnsAsync(groupName); var response = await graphUpdaterService.GetGroupNameAsync(Guid.NewGuid()); Assert.AreEqual(groupName, response); }
public async Task SendEmailTest() { var mockLogs = new MockLoggingRepository(); var telemetryClient = new TelemetryClient(TelemetryConfiguration.CreateDefault()); var mockGraphGroup = new MockGraphGroupRepository(); var mockMail = new MockMailRepository(); var mailSenders = new EmailSenderRecipient("*****@*****.**", "fake_pass", "*****@*****.**", "*****@*****.**", "*****@*****.**"); var mockSynJobs = new MockSyncJobRepository(); var dryRun = new DryRunValue(false); var graphUpdaterService = new GraphUpdaterService(mockLogs, telemetryClient, mockGraphGroup, mockMail, mailSenders, mockSynJobs, dryRun); var toEmail = "user@domain"; var template = "SampleTemplate"; var runId = Guid.NewGuid(); await graphUpdaterService.SendEmailAsync(toEmail, template, new string[0] { }, runId); Assert.AreEqual(1, mockMail.SentEmails.Count); }
public async Task GroupExistsTest() { var mockLogs = new MockLoggingRepository(); var telemetryClient = new TelemetryClient(TelemetryConfiguration.CreateDefault()); var mockGraphGroup = new MockGraphGroupRepository(); var mockMail = new MockMailRepository(); var mailSenders = new EmailSenderRecipient("*****@*****.**", "fake_pass", "*****@*****.**", "*****@*****.**", "*****@*****.**"); var mockSynJobs = new MockSyncJobRepository(); var dryRun = new DryRunValue(false); var graphUpdaterService = new GraphUpdaterService(mockLogs, telemetryClient, mockGraphGroup, mockMail, mailSenders, mockSynJobs, dryRun); var groupId = Guid.NewGuid(); var runId = Guid.NewGuid(); mockGraphGroup.GroupsToUsers.Add(groupId, new List <AzureADUser>()); var response = await graphUpdaterService.GroupExistsAsync(groupId, runId); Assert.IsTrue(response.Result); }
public async Task AccumulatesMessages() { var mockLogs = new MockLoggingRepository(); var sessionCollector = new MessageCollector(mockLogs); var mockSession = new MockMessageSession() { SessionId = "someId" }; var sessionId = "someId"; var incomingMessages = MakeMembershipMessages(); foreach (var message in incomingMessages.SkipLast(1)) { var result = await sessionCollector.HandleNewMessageAsync(message, sessionId); // sessionCollector doesn't do anything until it gets the last message. Assert.IsFalse(mockSession.Closed); Assert.AreEqual(0, mockSession.CompletedLockTokens.Count); Assert.AreEqual(false, result.ShouldCompleteMessage); } var groupMembershipMessageResponse = await sessionCollector.HandleNewMessageAsync(incomingMessages.Last(), sessionId); var mergedMembership = groupMembershipMessageResponse.CompletedGroupMembershipMessages.Select(x => x.Body).FirstOrDefault(); Assert.IsFalse(mockSession.Closed); Assert.IsTrue(groupMembershipMessageResponse.ShouldCompleteMessage); Assert.AreEqual(incomingMessages.Length, groupMembershipMessageResponse.CompletedGroupMembershipMessages.Count); for (int i = 0; i < incomingMessages.Length; i++) { var currentBody = incomingMessages[i].Body; Assert.AreEqual(currentBody.SyncJobRowKey, mergedMembership.SyncJobRowKey); Assert.AreEqual(currentBody.SyncJobPartitionKey, mergedMembership.SyncJobPartitionKey); Assert.AreEqual(currentBody.RunId, mergedMembership.RunId); Assert.AreEqual(currentBody.Destination, mergedMembership.Destination); } }
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); }