예제 #1
0
        public void CheckProgressForCompletion_does_not_call_data_services_if_completionStatus_is_zero_or_less(
            int completionStatus
            )
        {
            // Given
            var detailedCourseProgress = ProgressTestHelper.GetDefaultDetailedCourseProgress();

            A.CallTo(() => progressDataService.GetCompletionStatusForProgress(detailedCourseProgress.ProgressId))
            .Returns(completionStatus);

            // When
            progressService.CheckProgressForCompletionAndSendEmailIfCompleted(detailedCourseProgress);

            // Then
            A.CallTo(
                () => progressDataService.SetCompletionDate(
                    A <int> ._,
                    A <DateTime> ._
                    )
                ).MustNotHaveHappened();
            A.CallTo(
                () => learningLogItemsDataService.MarkLearningLogItemsCompleteByProgressId(
                    A <int> ._
                    )
                ).MustNotHaveHappened();
            A.CallTo(
                () => notificationService.SendProgressCompletionNotificationEmail(
                    A <DetailedCourseProgress> ._,
                    A <int> ._,
                    A <int> ._
                    )
                ).MustNotHaveHappened();
        }
예제 #2
0
        public void SetUp()
        {
            connection = ServiceTestHelper.GetDatabaseConnection();
            var logger = A.Fake <ILogger <ProgressDataService> >();

            progressDataService       = new ProgressDataService(connection, logger);
            tutorialContentTestHelper = new TutorialContentTestHelper(connection);
            progressTestHelper        = new ProgressTestHelper(connection);
        }
예제 #3
0
        public void CheckProgressForCompletion_does_nothing_if_progress_is_already_completed()
        {
            // Given
            var completedDate          = new DateTime(2022, 1, 1, 1, 1, 1);
            var detailedCourseProgress = ProgressTestHelper.GetDefaultDetailedCourseProgress(completed: completedDate);

            // When
            progressService.CheckProgressForCompletionAndSendEmailIfCompleted(detailedCourseProgress);

            // Then
            A.CallTo(
                () => progressDataService.GetCompletionStatusForProgress(A <int> ._)
                ).MustNotHaveHappened();
        }
        public void SendProgressCompletionNotification_does_not_send_email_if_delegate_email_is_null()
        {
            // Given
            var progress = ProgressTestHelper.GetDefaultDetailedCourseProgress(delegateEmail: null);

            SetUpSendProgressCompletionNotificationEmailFakes();

            // When
            notificationService.SendProgressCompletionNotificationEmail(progress, 2, 3);

            // Then
            A.CallTo(() => emailService.SendEmail(A <Email> ._))
            .MustNotHaveHappened();
        }
        public void SendProgressCompletionNotification_does_not_send_email_if_progress_completion_data_is_null()
        {
            // Given
            var progress = ProgressTestHelper.GetDefaultDetailedCourseProgress();

            A.CallTo(() => notificationDataService.GetProgressCompletionData(ProgressId, DelegateId, CustomisationId))
            .Returns(null);

            // When
            notificationService.SendProgressCompletionNotificationEmail(progress, 2, 3);

            // Then
            A.CallTo(() => emailService.SendEmail(A <Email> ._))
            .MustNotHaveHappened();
        }
        public void AddCourseToGroup_adds_new_progress_record_when_existing_progress_record_is_removed()
        {
            // Given
            const int adminId = 1;
            var       existingProgressRecord = ProgressTestHelper.GetDefaultProgress(removedDate: testDate);
            var       groupCourse            = GroupTestHelper.GetDefaultGroupCourse(supervisorAdminId: adminId);

            SetupEnrolProcessFakes(
                GenericNewProgressId,
                GenericRelatedTutorialId,
                existingProgressRecord
                );
            SetUpAddCourseEnrolProcessFakes(groupCourse);

            // When
            groupsService.AddCourseToGroup(
                groupCourse.GroupId,
                groupCourse.CustomisationId,
                8,
                adminId,
                true,
                adminId,
                centreId
                );

            // Then
            using (new AssertionScope())
            {
                DelegateProgressRecordMustNotHaveBeenUpdated();
                A.CallTo(
                    () => progressDataService.CreateNewDelegateProgress(
                        reusableGroupDelegate.DelegateId,
                        groupCourse.CustomisationId,
                        groupCourse.CurrentVersion,
                        testDate,
                        3,
                        adminId,
                        A <DateTime?> ._,
                        adminId
                        )
                    ).MustHaveHappened();
                A.CallTo(() => progressDataService.CreateNewAspProgress(GenericRelatedTutorialId, GenericNewProgressId))
                .MustHaveHappened();
            }
        }
예제 #7
0
        CheckProgressForCompletion_calls_data_services_with_correct_values_if_completionStatus_is_greater_than_zero()
        {
            // Given
            var detailedCourseProgress      = ProgressTestHelper.GetDefaultDetailedCourseProgress();
            var numLearningLogItemsAffected = 3;

            A.CallTo(() => progressDataService.GetCompletionStatusForProgress(detailedCourseProgress.ProgressId))
            .Returns(1);
            A.CallTo(
                () => progressDataService.SetCompletionDate(
                    A <int> ._,
                    A <DateTime> ._
                    )
                ).DoesNothing();
            A.CallTo(
                () => learningLogItemsDataService.MarkLearningLogItemsCompleteByProgressId(
                    A <int> ._
                    )
                ).Returns(numLearningLogItemsAffected);
            A.CallTo(
                () => notificationService.SendProgressCompletionNotificationEmail(
                    A <DetailedCourseProgress> ._,
                    A <int> ._,
                    A <int> ._
                    )
                ).DoesNothing();

            // When
            progressService.CheckProgressForCompletionAndSendEmailIfCompleted(detailedCourseProgress);

            // Then
            A.CallTo(() => progressDataService.GetCompletionStatusForProgress(detailedCourseProgress.ProgressId))
            .MustHaveHappenedOnceExactly();
            A.CallTo(() => progressDataService.SetCompletionDate(A <int> ._, A <DateTime> ._))
            .MustHaveHappenedOnceExactly();
            A.CallTo(() => learningLogItemsDataService.MarkLearningLogItemsCompleteByProgressId(A <int> ._))
            .MustHaveHappenedOnceExactly();
            A.CallTo(
                () => notificationService.SendProgressCompletionNotificationEmail(
                    A <DetailedCourseProgress> ._,
                    A <int> ._,
                    A <int> ._
                    )
                ).MustHaveHappenedOnceExactly();
        }
        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 SendProgressCompletionNotification_does_not_add_line_of_text_about_admin_if_admin_email_is_null()
        {
            // Given
            var progress = ProgressTestHelper.GetDefaultDetailedCourseProgress();

            SetUpSendProgressCompletionNotificationEmailFakes(adminEmail: null);

            // When
            notificationService.SendProgressCompletionNotificationEmail(progress, 2, 3);

            // Then
            A.CallTo(
                () => emailService.SendEmail(
                    A <Email> .That.Matches(
                        e => e.Body.TextBody.Contains(
                            "Note: This message has been copied to the administrator(s) managing this activity, for their information."
                            )
                        )
                    )
                ).MustNotHaveHappened();
        }
        public void EnrolDelegateOnGroupCourses_adds_new_progress_record_when_existing_progress_record_is_removed()
        {
            // Given
            var existingProgressRecord = ProgressTestHelper.GetDefaultProgress(removedDate: testDate);

            SetupEnrolProcessFakes(
                GenericNewProgressId,
                GenericRelatedTutorialId,
                existingProgressRecord
                );
            SetUpAddDelegateEnrolProcessFakes(reusableGroupCourse);

            // When
            groupsService.EnrolDelegateOnGroupCourses(
                reusableDelegateDetails,
                reusableMyAccountDetailsData,
                8
                );

            // Then
            using (new AssertionScope())
            {
                DelegateProgressRecordMustNotHaveBeenUpdated();
                A.CallTo(
                    () => progressDataService.CreateNewDelegateProgress(
                        reusableDelegateDetails.Id,
                        reusableGroupCourse.CustomisationId,
                        reusableGroupCourse.CurrentVersion,
                        testDate,
                        3,
                        null,
                        A <DateTime?> ._,
                        A <int> ._
                        )
                    ).MustHaveHappened();
                A.CallTo(() => progressDataService.CreateNewAspProgress(GenericRelatedTutorialId, GenericNewProgressId))
                .MustHaveHappened();
            }
        }
        public void SendProgressCompletionNotification_ccs_admin_if_email_found()
        {
            // Given
            const string adminEmail = "*****@*****.**";

            var progress = ProgressTestHelper.GetDefaultDetailedCourseProgress();

            SetUpSendProgressCompletionNotificationEmailFakes(adminEmail: adminEmail);

            // When
            notificationService.SendProgressCompletionNotificationEmail(progress, 2, 3);

            // Then
            A.CallTo(
                () => emailService.SendEmail(
                    A <Email> .That.Matches(
                        e => e.Cc.SequenceEqual(new[] { adminEmail }) && e.Body.TextBody.Contains(
                            "Note: This message has been copied to the administrator(s) managing this activity, for their information."
                            )
                        )
                    )
                ).MustHaveHappenedOnceExactly();
        }
        SendProgressCompletionNotification_does_not_add_the_extra_learning_log_item_line_of_text_when_number_affected_is_zero(
            string lineOfText
            )
        {
            // Given
            var progress = ProgressTestHelper.GetDefaultDetailedCourseProgress();

            SetUpSendProgressCompletionNotificationEmailFakes();

            // When
            notificationService.SendProgressCompletionNotificationEmail(progress, 2, 0);

            // Then
            A.CallTo(
                () => emailService.SendEmail(
                    A <Email> .That.Matches(
                        e => e.Body.TextBody.Contains(
                            lineOfText
                            )
                        )
                    )
                ).MustNotHaveHappened();
        }
        public void SendProgressCompletionNotification_forms_url_correctly()
        {
            // Given
            const string finaliseUrl = "/tracking/finalise?SessionID=123&ProgressID=1&UserCentreID=101";

            var progress = ProgressTestHelper.GetDefaultDetailedCourseProgress();

            SetUpSendProgressCompletionNotificationEmailFakes();

            // When
            notificationService.SendProgressCompletionNotificationEmail(progress, 2, 3);

            // Then
            A.CallTo(
                () => emailService.SendEmail(
                    A <Email> .That.Matches(
                        e => e.Body.HtmlBody.Contains(
                            finaliseUrl
                            )
                        )
                    )
                ).MustHaveHappenedOnceExactly();
        }
        public void SendProgressCompletionNotification_shows_correct_text_for_number_of_learning_log_items_affected(
            int numLearningLogItemsAffected,
            string lineOfText
            )
        {
            // Given
            var progress = ProgressTestHelper.GetDefaultDetailedCourseProgress();

            SetUpSendProgressCompletionNotificationEmailFakes();

            // When
            notificationService.SendProgressCompletionNotificationEmail(progress, 2, numLearningLogItemsAffected);

            // Then
            A.CallTo(
                () => emailService.SendEmail(
                    A <Email> .That.Matches(
                        e => e.Body.TextBody.Contains(
                            lineOfText
                            )
                        )
                    )
                ).MustHaveHappenedOnceExactly();
        }
        public void SendProgressCompletionNotification_shows_correct_text_for_completion_status(
            int completionStatus,
            string lineOfText
            )
        {
            // Given
            var progress = ProgressTestHelper.GetDefaultDetailedCourseProgress();

            SetUpSendProgressCompletionNotificationEmailFakes();

            // When
            notificationService.SendProgressCompletionNotificationEmail(progress, completionStatus, 3);

            // Then
            A.CallTo(
                () => emailService.SendEmail(
                    A <Email> .That.Matches(
                        e => e.Body.TextBody.Contains(
                            lineOfText
                            )
                        )
                    )
                ).MustHaveHappenedOnceExactly();
        }