protected static void AssertTitles(MockEmail email, IList <string> locations, int totalMatches, bool checkEachLocation) { if (totalMatches == 1) { email.AssertHtmlViewContains("<strong>1 new job</strong>"); } else { email.AssertHtmlViewContains("<strong>" + totalMatches + " new jobs</strong>"); } if (locations.Count != totalMatches) { var check = "top " + locations.Count + " out of total"; email.AssertHtmlViewContains(check); } if (checkEachLocation) { foreach (var location in locations) { email.AssertHtmlViewContains(location); } } }
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); }
private static void AssertEmail(MockEmail email, IList <JobAd> jobAds, IList <IList <Member> > members) { var document = new HtmlDocument(); document.LoadHtml(email.GetHtmlView().Body); var spans = document.DocumentNode.SelectNodes("//p/span[@class='jobAdTitle']"); var divs = document.DocumentNode.SelectNodes("//p/div[@class='alert-container']"); Assert.AreEqual(jobAds.Count, members.Count); Assert.AreEqual(jobAds.Count, spans.Count); Assert.AreEqual(jobAds.Count, divs.Count); for (var index = 0; index < jobAds.Count; ++index) { Assert.AreEqual(jobAds[index].Id.ToString(), spans[index].Attributes["data-jobadid"].Value); var candidateDivs = divs[index].SelectNodes("div[@class='candidate']"); Assert.AreEqual(members[index].Count, candidateDivs.Count); for (var candidateIndex = 0; candidateIndex < candidateDivs.Count; ++candidateIndex) { var id = candidateDivs[candidateIndex].Attributes["data-id"].Value; Assert.AreEqual(members[index][candidateIndex].Id.ToString(), id); } } }
private static void AssertEmail(MockEmail email, ICommunicationUser employer, int newCandidates) { email.AssertAddresses(Return, Return, employer); email.AssertSubject(GetSubject(newCandidates)); email.AssertHtmlViewContains(employer.FirstName); email.AssertHtmlViewContains(GetBodySnippet(newCandidates)); }
protected static void AssertCompatibleAddresses(MockEmail email) { // Should not be being sent to the same address. if (email.To.Contains(email.From)) { Assert.Fail("Email being sent to the same address it is from."); } // Based upon who the message is from check who it is going to. if (email.From.Equals(Return)) { // Should be an external address. if (email.To.Contains(Return) || email.To.Contains(System)) { Assert.Fail("Email being sent from [email protected] is being sent to an internal address."); } } else if (email.From.Equals(System) || email.From.Equals(AllStaff)) { // No email should be coming from these addresses. Assert.Fail("Email is being sent from in incorrect address"); } }
private void AssertEmail(IEmployer employer, IList <Member> members, MockEmail email) { email.AssertSubject("Job candidates from LinkMe"); email.AssertHtmlViewContains("4 suggested candidates"); var view = _employerMemberViewsQuery.GetEmployerMemberView(employer, members[0]); email.AssertHtmlViewContains(view.GetDisplayText(false)); }
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); } }
private void Add(Community community, TemplateEmail templateEmail, MockEmail mockEmail) { CommunityEmails emails; _communityEmails.TryGetValue(community == null ? string.Empty : community.Name, out emails); if (emails == null) { emails = new CommunityEmails(); _communityEmails[community == null ? string.Empty : community.Name] = emails; } if (templateEmail.GetType().IsSubclassOf(typeof(EmployerToMemberNotification))) { emails.EmployerToMemberNotifications[templateEmail] = mockEmail; } else if (templateEmail.GetType().IsSubclassOf(typeof(MemberToMemberNotification))) { emails.MemberToMemberNotifications[templateEmail] = mockEmail; } else if (templateEmail.GetType().IsSubclassOf(typeof(MemberAlertEmail))) { emails.MemberAlerts[templateEmail] = mockEmail; } else if (templateEmail.GetType().IsSubclassOf(typeof(MemberEmail))) { emails.MemberEmails[templateEmail] = mockEmail; } else if (templateEmail.GetType().IsSubclassOf(typeof(EmployerEmail))) { emails.EmployerEmails[templateEmail] = mockEmail; } else if (templateEmail.GetType().IsSubclassOf(typeof(CustodianEmail))) { emails.CustodianEmails[templateEmail] = mockEmail; } else if (templateEmail.GetType().IsSubclassOf(typeof(UserEmail))) { emails.RegisteredUserEmails[templateEmail] = mockEmail; } else if (templateEmail.GetType().IsSubclassOf(typeof(InternalEmail))) { emails.InternalEmails[templateEmail] = mockEmail; } else { throw new ApplicationException("Non-recognised email type '" + templateEmail.GetType() + "'."); } }
private void AssertEmail(MockEmail email, string expectedSnippet, string expectedHeaderSnippet) { foreach (var snippet in _snippets) { if (snippet == expectedSnippet) { email.AssertHtmlViewContains(snippet); } else { email.AssertHtmlViewDoesNotContain(snippet); } } var links = email.GetHtmlView().GetLinks(); AssertLink(links[0], expectedHeaderSnippet); }
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); }
private static void AssertClientEmail(MockEmail email, IOrganisation organisation, params ReportStatus[] statuses) { // Subject. email.AssertSubject(GetSubject(organisation)); // Attachments. email.AssertAttachments(GetAttachments(organisation, statuses)); // Contents. if (statuses.Any(a => a.Report is ResumeSearchActivityReport && !a.IsActivity)) { email.AssertHtmlViewContains("your organisation has not performed any searches in the past month"); } else { email.AssertHtmlViewContains("Please find attached the activity report for " + organisation.FullName); } }
private static void AssertAdministratorEmail(MockEmail email, ICommunicationUser administrator, IOrganisation organisation, params ReportStatus[] statuses) { email.AssertAddresses(Return, Return, administrator); // Subject. email.AssertSubject(GetAdministratorSubject(organisation, statuses)); // Attachments. email.AssertAttachments(GetAttachments(organisation, statuses)); // Contents. if (statuses.Any(s => s.IsActivity)) { email.AssertHtmlViewContains("Please find attached the activity report for " + organisation.FullName); } else { if (statuses.Length == 1) { if (statuses[0].Report is ResumeSearchActivityReport) { email.AssertHtmlViewContains("No resume search activity recorded for " + organisation.FullName); } else { email.AssertHtmlViewContains("No job board activity recorded for " + organisation.FullName); } } else { email.AssertHtmlViewContains("No job board activity and no resume search activity recorded for " + organisation.FullName); } } }
protected void AssertEmail(MockEmail email, Employer employer, string subject, string body, string from, MockEmailAttachment[] attachments) { if (from == null) { email.AssertAddresses(Return, Return, employer); } else { email.AssertAddresses(Return, Return, new EmailRecipient(from, employer.FullName)); } email.AssertSubject(subject); email.AssertHtmlViewContains(body); email.AssertHtmlViewDoesNotContain("<%= To.FirstName %>"); email.AssertHtmlViewDoesNotContain("<%= To.LastName %>"); if (attachments == null || attachments.Length == 0) { email.AssertNoAttachments(); } else { email.AssertAttachments(attachments); } }
protected void AssertJobAds(MockEmail email, params JobAdEntry[] jobAds) { var urls = GetJobAdUrls(email.GetHtmlView().Body); Assert.AreEqual(urls.Count, jobAds.Length); var browser = new HttpClient(); foreach (var jobAd in jobAds) { var found = false; foreach (var url in urls) { browser.Get(HttpStatusCode.OK, url.ToString()); if (browser.CurrentPageText.IndexOf(jobAd.Id.ToString().ToLower(), StringComparison.Ordinal) > -1) { found = true; break; } } Assert.IsTrue(found); } }
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); }
private static void AssertEmail <TCredit>(ICommunicationUser expected, MockEmail email, int?quantity) { email.AssertAddresses(Return, Return, expected); email.AssertSubject(GetSubject <TCredit>(quantity)); email.AssertHtmlViewContains(GetBodySnippet <TCredit>(quantity)); }
private void AssertHtmlView(MockEmail email, TemplateEmail templateEmail, ICommunicationRecipient inviter, RegisteredUser invitee, Request invitation, EmailVerification emailVerification) { email.AssertHtmlView(GetBody(templateEmail, invitee, GetContent(templateEmail, inviter, invitee, invitation, emailVerification))); }
private static void AssertClientEmail(MockEmail email, ICommunicationUser administrator, IOrganisation organisation, params ReportStatus[] statuses) { email.AssertAddresses(administrator, Return, new EmailRecipient(ClientEmail, ClientFirstName.CombineLastName(ClientLastName), ClientFirstName, ClientLastName)); AssertClientEmail(email, organisation, statuses); }
private static void AssertSecondaryClientEmail(MockEmail email, ICommunicationUser administrator, IOrganisation organisation, params ReportStatus[] statuses) { email.AssertAddresses(administrator, Return, new EmailRecipient(SecondaryClientEmail)); AssertClientEmail(email, organisation, statuses); }
private void TestReportActivity <TReport>(Func <IEmployer, bool> createActivity, bool sendToAccountManager, bool sendToClient, bool sendToSecondaryClients) where TReport : EmployerReport, new() { // Create everyone. var administrator = CreateAdministrator(); var organisation = CreateOrganisation(administrator.Id); var employer = CreateEmployer(organisation); // Define the report. var report = new TReport { ClientId = organisation.Id, SendToAccountManager = sendToAccountManager, SendToClient = sendToClient, }; _reportsCommand.CreateReport(report); // Create activity to report on. var isActivity = createActivity(employer); var status = new ReportStatus(report, isActivity); // No contact details set. if (sendToClient) { if (!sendToAccountManager) { // Check that no email is sent to the client if no contact details set. Execute(); _emailServer.AssertNoEmailSent(); } // Set the contact details. organisation.ContactDetails = new ContactDetails { FirstName = ClientFirstName, LastName = ClientLastName, EmailAddress = ClientEmail }; if (sendToSecondaryClients) { organisation.ContactDetails.SecondaryEmailAddresses = SecondaryClientEmail; } _organisationsCommand.UpdateOrganisation(organisation); } // Run the report. Execute(); MockEmail administratorEmail = null; MockEmail clientEmail = null; MockEmail secondaryClientEmail = null; var emails = _emailServer.GetEmails().ToList(); if (sendToAccountManager) { Assert.IsTrue(emails.Count > 0); administratorEmail = emails[0]; emails.RemoveAt(0); } if (sendToClient) { Assert.IsTrue(emails.Count > 0); clientEmail = emails[0]; emails.RemoveAt(0); } if (sendToSecondaryClients) { Assert.IsTrue(emails.Count > 0); secondaryClientEmail = emails[0]; emails.RemoveAt(0); } Assert.AreEqual(0, emails.Count); if (administratorEmail != null) { AssertAdministratorEmail(administratorEmail, administrator, organisation, status); } if (clientEmail != null) { AssertClientEmail(clientEmail, administrator, organisation, status); } if (secondaryClientEmail != null) { AssertSecondaryClientEmail(secondaryClientEmail, administrator, organisation, status); } }
private void AssertHtmlView(MockEmail email, TemplateEmail templateEmail, Member inviter, RegisteredUser invitee, Request invitation, EmailVerification emailVerification) { var friendCount = Resolve <IMemberContactsQuery>().GetFirstDegreeContacts(inviter.Id).Count; email.AssertHtmlView(GetBody(templateEmail, invitee, GetContent(templateEmail, inviter, invitee, friendCount, invitation, emailVerification))); }
public void HandlesErroredJobs() { 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 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); }