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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }