public void SendProgressCompletionNotification_calls_data_service_and_sends_email_to_correct_delegate_email() { // Given var progress = ProgressTestHelper.GetDefaultDetailedCourseProgress(); SetUpSendProgressCompletionNotificationEmailFakes(); // When notificationService.SendProgressCompletionNotificationEmail(progress, 2, 3); // Then A.CallTo(() => notificationDataService.GetProgressCompletionData(ProgressId, DelegateId, CustomisationId)) .MustHaveHappenedOnceExactly(); A.CallTo( () => emailService.SendEmail( A <Email> .That.Matches( e => e.To.SequenceEqual(new[] { progress.DelegateEmail }) ) ) ).MustHaveHappenedOnceExactly(); }
public void SendProgressCompletionNotificationEmail( DelegateCourseInfo progress, int completionStatus, int numLearningLogItemsAffected ) { var progressCompletionData = notificationDataService.GetProgressCompletionData( progress.ProgressId, progress.DelegateId, progress.CustomisationId ); if (progressCompletionData == null || progress.DelegateEmail == null || progress.DelegateEmail.Trim() == string.Empty) { return; } var finaliseUrl = configuration.GetCurrentSystemBaseUrl() + "/tracking/finalise" + $@"?SessionID={progressCompletionData.SessionId}&ProgressID={progress.ProgressId}&UserCentreID={progressCompletionData.CentreId}"; var htmlActivityCompletionInfo = completionStatus == 2 ? $@"<a href='{finaliseUrl}'><p>Evaluate the activity and access your certificate of completion here.</p></a>" : $@"<p>If you haven't already done so, please <a href='{finaliseUrl}'>evaluate the activity</a> to help us to improve provision for future delegates. Only one evaluation can be submitted per completion.</p>"; var textActivityCompletionInfo = completionStatus == 2 ? $@"To evaluate the activity and access your certificate of completion, visit this URL: {finaliseUrl}." : "If you haven't already done so, please evaluate the activity to help us to improve provision " + $@"for future delegates by visiting this URL: {finaliseUrl}. Only one evaluation can be submitted per completion."; if (numLearningLogItemsAffected == 1) { htmlActivityCompletionInfo += "<p>This activity is related to <b>1</b> planned development log action in another activity " + "in your Learning Portal. This has automatically been marked as complete.</p>"; textActivityCompletionInfo += " This activity is related to 1 planned development log action in another activity " + "in your Learning Portal. This has automatically been marked as complete."; } else if (numLearningLogItemsAffected > 1) { htmlActivityCompletionInfo += $@"<p>This activity is related to <b>{numLearningLogItemsAffected}</b> planned development log actions " + "in other activities in your Learning Portal. These have automatically been marked as complete.</p>"; textActivityCompletionInfo += $@" This activity is related to {numLearningLogItemsAffected} planned development log actions " + "in other activities in your Learning Portal. These have automatically been marked as complete."; } if (progressCompletionData.AdminEmail != null || progressCompletionData.CourseNotificationEmail != null) { htmlActivityCompletionInfo += "<p><b>Note:</b> This message has been copied to the administrator(s) managing this activity, for their information.</p>"; textActivityCompletionInfo += " Note: This message has been copied to the administrator(s) managing this activity, for their information."; } const string emailSubjectLine = "Digital Learning Solutions Activity Complete"; var delegateNameOrGenericTitle = progress.DelegateFirstName ?? "Digital Learning Solutions Delegate"; var emailsToCc = GetEmailsToCc( progressCompletionData.AdminEmail, progressCompletionData.CourseNotificationEmail ); var builder = new BodyBuilder { TextBody = $@"Dear {delegateNameOrGenericTitle}, You have completed the Digital Learning Solutions learning activity - {progressCompletionData.CourseName}. {textActivityCompletionInfo}", HtmlBody = $@"<body style=""font-family: Calibri; font-size: small;""> <p>Dear {delegateNameOrGenericTitle},</p> <p>You have completed the Digital Learning Solutions learning activity - {progressCompletionData.CourseName}.</p> {htmlActivityCompletionInfo} </body>", }; var email = new Email( emailSubjectLine, builder, new[] { progress.DelegateEmail }, emailsToCc ); emailService.SendEmail(email); }