public void SendUnlockRequest(int progressId) { var unlockData = notificationDataService.GetUnlockData(progressId); if (unlockData == null) { throw new NotificationDataException($"No record found when trying to fetch Unlock Data. Progress ID: {progressId}"); } unlockData.ContactForename = unlockData.ContactForename == "" ? "Colleague" : unlockData.ContactForename; var trackingSystemBaseUrl = configService.GetConfigValue(ConfigService.TrackingSystemBaseUrl) ?? throw new ConfigValueMissingException(configService.GetConfigValueMissingExceptionMessage("TrackingSystemBaseUrl")); var unlockUrl = new UriBuilder(trackingSystemBaseUrl); unlockUrl.Path += "coursedelegates"; unlockUrl.Query = $"CustomisationID={unlockData.CustomisationId}"; string emailSubjectLine = "Digital Learning Solutions Progress Unlock Request"; var builder = new BodyBuilder { TextBody = $@"Dear {unlockData?.ContactForename} Digital Learning Solutions Delegate, {unlockData?.DelegateName}, has requested that you unlock their progress for the course {unlockData?.CourseName}. They have reached the maximum number of assessment attempt allowed without passing. To review and unlock their progress, visit the this url: ${unlockUrl.Uri}.", HtmlBody = $@"<body style= 'font-family: Calibri; font-size: small;'> <p>Dear {unlockData?.ContactForename}</p> <p>Digital Learning Solutions Delegate, {unlockData?.DelegateName}, has requested that you unlock their progress for the course {unlockData?.CourseName}</p> <p>They have reached the maximum number of assessment attempt allowed without passing.</p><p>To review and unlock their progress, <a href='{unlockUrl.Uri}'>click here</a>.</p> </body>" }; emailService.SendEmail(new Email(emailSubjectLine, builder, unlockData.ContactEmail, unlockData.DelegateEmail)); }
public void Setup() { configuration = A.Fake <IConfiguration>(); notificationDataService = A.Fake <INotificationDataService>(); emailService = A.Fake <IEmailService>(); featureManager = A.Fake <IFeatureManager>(); A.CallTo(() => notificationDataService.GetUnlockData(A <int> ._)).Returns( new UnlockData { ContactEmail = "*****@*****.**", ContactForename = "Forename", CourseName = "Activity Name", CustomisationId = 22, DelegateEmail = "*****@*****.**", DelegateName = "Delegate Name", } ); notificationService = new NotificationService( configuration, notificationDataService, emailService, featureManager ); A.CallTo(() => configuration["AppRootPath"]).Returns("https://new-tracking-system.com"); A.CallTo(() => configuration["CurrentSystemBaseUrl"]) .Returns("https://old-tracking-system.com"); }
public void Trying_to_send_unlock_request_with_null_unlock_data_should_throw_an_exception() { // Given A.CallTo(() => notificationDataService.GetUnlockData(A <int> ._)).Returns(null); // Then Assert.Throws <NotificationDataException>(() => notificationService.SendUnlockRequest(1)); }
public async Task SendUnlockRequest(int progressId) { var unlockData = notificationDataService.GetUnlockData(progressId); if (unlockData == null) { throw new NotificationDataException( $"No record found when trying to fetch Unlock Data. Progress ID: {progressId}" ); } unlockData.ContactForename = unlockData.ContactForename == "" ? "Colleague" : unlockData.ContactForename; var refactoredTrackingSystemEnabled = await featureManager.IsEnabledAsync("RefactoredTrackingSystem"); var baseUrlConfigOption = refactoredTrackingSystemEnabled ? configuration.GetAppRootPath() : configuration.GetCurrentSystemBaseUrl(); if (string.IsNullOrEmpty(baseUrlConfigOption)) { var missingConfigValue = refactoredTrackingSystemEnabled ? "AppRootPath" : "CurrentSystemBaseUrl"; throw new ConfigValueMissingException( $"Encountered an error while trying to send an email: The value of {missingConfigValue} is null" ); } var baseUrl = refactoredTrackingSystemEnabled ? $"{baseUrlConfigOption}/TrackingSystem/Delegates/CourseDelegates" : $"{baseUrlConfigOption}/Tracking/CourseDelegates"; var unlockUrl = new UriBuilder(baseUrl) { Query = $"CustomisationID={unlockData.CustomisationId}", }; const string emailSubjectLine = "Digital Learning Solutions Progress Unlock Request"; var builder = new BodyBuilder { TextBody = $@"Dear {unlockData.ContactForename} Digital Learning Solutions Delegate, {unlockData.DelegateName}, has requested that you unlock their progress for the course {unlockData.CourseName}. They have reached the maximum number of assessment attempt allowed without passing. To review and unlock their progress, visit this url: ${unlockUrl.Uri}.", HtmlBody = $@"<body style= 'font-family: Calibri; font-size: small;'> <p>Dear {unlockData.ContactForename}</p> <p>Digital Learning Solutions Delegate, {unlockData.DelegateName}, has requested that you unlock their progress for the course {unlockData.CourseName}</p> <p>They have reached the maximum number of assessment attempt allowed without passing.</p><p>To review and unlock their progress, <a href='{unlockUrl.Uri}'>click here</a>.</p> </body>", }; emailService.SendEmail( new Email(emailSubjectLine, builder, unlockData.ContactEmail, unlockData.DelegateEmail) ); }
public void Setup() { notificationDataService = A.Fake <INotificationDataService>(); configService = A.Fake <IConfigService>(); emailService = A.Fake <IEmailService>(); A.CallTo(() => notificationDataService.GetUnlockData(A <int> ._)).Returns(new UnlockData { ContactEmail = "*****@*****.**", ContactForename = "Forename", CourseName = "Activity Name", CustomisationId = 22, DelegateEmail = "*****@*****.**", DelegateName = "Delegate Name" }); A.CallTo(() => configService.GetConfigValue(ConfigService.TrackingSystemBaseUrl)).Returns("https://example.com"); notificationService = new NotificationService(notificationDataService, configService, emailService); }