public void CourseCompletion_should_have_formatted_completion_summary(
            string?completed,
            int maxPostLearningAssessmentAttempts,
            bool isAssessed,
            int postLearningAssessmentPassThreshold,
            int diagnosticAssessmentCompletionThreshold,
            int tutorialsCompletionThreshold,
            string expectedSummary
            )
        {
            // Given
            var expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(
                completed: completed != null ? DateTime.Parse(completed) : (DateTime?)null,
                maxPostLearningAssessmentAttempts: maxPostLearningAssessmentAttempts,
                isAssessed: isAssessed,
                postLearningAssessmentPassThreshold: postLearningAssessmentPassThreshold,
                diagnosticAssessmentCompletionThreshold: diagnosticAssessmentCompletionThreshold,
                tutorialsCompletionThreshold: tutorialsCompletionThreshold
                );

            // When
            var courseCompletionViewModel = new CourseCompletionViewModel(config, expectedCourseCompletion, ProgressId);

            // Then
            courseCompletionViewModel.SummaryText.Should().Be(expectedSummary);
        }
        public void CourseCompletion_should_have_incomplete_status_for_null_completed()
        {
            // Given
            var expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(completed: null);

            // When
            var courseCompletionViewModel = new CourseCompletionViewModel(config, expectedCourseCompletion, ProgressId);

            // Then
            courseCompletionViewModel.CompletionStatus.Should().Be("incomplete");
        }
        public void CourseCompletion_FinaliseAriaLabel_should_be_null_when_completed_is_null()
        {
            // Given
            var expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(completed: null);

            // When
            var courseCompletionViewModel = new CourseCompletionViewModel(config, expectedCourseCompletion, ProgressId);

            // Then
            courseCompletionViewModel.FinaliseAriaLabel.Should().BeNull();
        }
        public void CourseCompletion_should_have_FinaliseUrl()
        {
            // Given
            var expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion();
            var expectedFinaliseUrl      = $"{BaseUrl}/tracking/finalise?ProgressID={ProgressId}";

            // When
            var courseCompletionViewModel = new CourseCompletionViewModel(config, expectedCourseCompletion, ProgressId);

            // Then
            courseCompletionViewModel.FinaliseUrl.Should().Be(expectedFinaliseUrl);
        }
        public void CourseCompletion_should_have_customisationId()
        {
            // Given
            const int customisationId          = 1234;
            var       expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(customisationId);

            // When
            var courseCompletionViewModel = new CourseCompletionViewModel(config, expectedCourseCompletion, ProgressId);

            // Then
            courseCompletionViewModel.CustomisationId.Should().Be(customisationId);
        }
        public void CourseCompletion_should_show_PercentageTutorialsCompleted_when_not_0()
        {
            // Given
            var expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(
                percentageTutorialsCompleted: 10
                );

            // When
            var courseCompletionViewModel = new CourseCompletionViewModel(config, expectedCourseCompletion, ProgressId);

            // Then
            courseCompletionViewModel.ShowPercentageTutorialsCompleted.Should().BeTrue();
        }
        public void CourseCompletion_should_not_show_DiagnosticScore_when_null()
        {
            // Given
            var expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(
                diagnosticScore: null
                );

            // When
            var courseCompletionViewModel = new CourseCompletionViewModel(config, expectedCourseCompletion, ProgressId);

            // Then
            courseCompletionViewModel.ShowDiagnosticScore.Should().BeFalse();
        }
        public void CourseCompletion_should_round_percentageTutorialsCompleted_down()
        {
            // Given
            const double percentageTutorialsCompleted = 44.4;
            var          expectedCourseCompletion     = CourseCompletionHelper.CreateDefaultCourseCompletion(
                percentageTutorialsCompleted: percentageTutorialsCompleted
                );

            // When
            var courseCompletionViewModel = new CourseCompletionViewModel(config, expectedCourseCompletion, ProgressId);

            // Then
            courseCompletionViewModel.PercentageTutorialsCompleted.Should().Be(44);
        }
        public void CourseCompletion_should_have_isAssessed()
        {
            // Given
            const bool isAssessed = true;
            var        expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(
                isAssessed: isAssessed
                );

            // When
            var courseCompletionViewModel = new CourseCompletionViewModel(config, expectedCourseCompletion, ProgressId);

            // Then
            courseCompletionViewModel.IsAssessed.Should().Be(isAssessed);
        }
        public void CourseCompletion_should_have_diagnosticScore()
        {
            // Given
            const int diagnosticScore          = 42;
            var       expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(
                diagnosticScore: diagnosticScore
                );

            // When
            var courseCompletionViewModel = new CourseCompletionViewModel(config, expectedCourseCompletion, ProgressId);

            // Then
            courseCompletionViewModel.DiagnosticScore.Should().Be(diagnosticScore);
        }
        public void CourseCompletion_should_show_DiagnosticScore_when_attempts_are_not_0()
        {
            // Given
            var expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(
                diagnosticScore: 10,
                diagnosticAttempts: 1
                );

            // When
            var courseCompletionViewModel = new CourseCompletionViewModel(config, expectedCourseCompletion, ProgressId);

            // Then
            courseCompletionViewModel.ShowDiagnosticScore.Should().BeTrue();
        }
        public void CourseCompletion_should_have_postLearningPasses()
        {
            // Given
            const int postLearningPasses       = 61;
            var       expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(
                postLearningPasses: postLearningPasses
                );

            // When
            var courseCompletionViewModel = new CourseCompletionViewModel(config, expectedCourseCompletion, ProgressId);

            // Then
            courseCompletionViewModel.PostLearningPasses.Should().Be(postLearningPasses);
        }
        public void CourseCompletion_should_have_sectionCount()
        {
            // Given
            const int sectionCount             = 62;
            var       expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(
                sectionCount: sectionCount
                );

            // When
            var courseCompletionViewModel = new CourseCompletionViewModel(config, expectedCourseCompletion, ProgressId);

            // Then
            courseCompletionViewModel.SectionCount.Should().Be(sectionCount);
        }
        public void CourseCompletion_FinaliseAriaLabel_should_be_null_when_course_is_not_assessed_and_already_evaluated()
        {
            // Given
            var expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(
                completed: DateTime.UtcNow.AddDays(-1),
                evaluated: DateTime.UtcNow,
                isAssessed: false
                );

            // When
            var courseCompletionViewModel = new CourseCompletionViewModel(config, expectedCourseCompletion, ProgressId);

            // Then
            courseCompletionViewModel.FinaliseAriaLabel.Should().BeNull();
        }
        public void CourseCompletion_FinaliseText_should_be_evaluate_when_course_is_not_assessed_and_not_evaluated()
        {
            // Given
            var expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(
                completed: DateTime.UtcNow,
                evaluated: null,
                isAssessed: false
                );

            // When
            var courseCompletionViewModel = new CourseCompletionViewModel(config, expectedCourseCompletion, ProgressId);

            // Then
            courseCompletionViewModel.FinaliseText.Should().Be("Evaluate");
        }
        public void CourseCompletion_FinaliseAriaLabel_should_be_certificate_when_course_is_assessed_and_evaluated()
        {
            // Given
            var expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(
                completed: DateTime.UtcNow.AddDays(-1),
                evaluated: DateTime.UtcNow,
                isAssessed: true
                );

            // When
            var courseCompletionViewModel = new CourseCompletionViewModel(config, expectedCourseCompletion, ProgressId);

            // Then
            courseCompletionViewModel.FinaliseAriaLabel.Should().Be("View or print certificate");
        }
        public void CourseCompletion_should_not_UpdateProgress_if_unable_to_enrol()
        {
            // Given
            var expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(CustomisationId);

            A.CallTo(() => courseCompletionService.GetCourseCompletion(CandidateId, CustomisationId))
            .Returns(expectedCourseCompletion);
            A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, CustomisationId, CentreId))
            .Returns(null);

            // When
            controller.CompletionSummary(CustomisationId);

            // Then
            A.CallTo(() => courseContentService.UpdateProgress(A <int> ._)).MustNotHaveHappened();
        }
        public void CourseCompletion_should_have_courseTitle()
        {
            // Given
            const string applicationName          = "Application Name";
            const string customisationName        = "Customisation Name";
            var          expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(
                applicationName: applicationName,
                customisationName: customisationName
                );

            // When
            var courseCompletionViewModel = new CourseCompletionViewModel(config, expectedCourseCompletion, ProgressId);

            // Then
            var courseTitle = $"{applicationName} - {customisationName}";

            courseCompletionViewModel.CourseTitle.Should().BeEquivalentTo(courseTitle);
        }
        public void CourseCompletion_should_UpdateProgress_if_valid_course()
        {
            // Given
            var       expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(CustomisationId);
            const int progressId = 3;

            A.CallTo(() => courseCompletionService.GetCourseCompletion(CandidateId, CustomisationId))
            .Returns(expectedCourseCompletion);
            A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, CustomisationId, CentreId))
            .Returns(progressId);

            // When
            controller.CompletionSummary(CustomisationId);

            // Then
            A.CallTo(() => courseContentService.UpdateProgress(progressId)).MustHaveHappened();
            A.CallTo(() => courseContentService.UpdateProgress(A <int> ._))
            .WhenArgumentsMatch((int id) => id != progressId)
            .MustNotHaveHappened();
        }
        public void CourseCompletion_should_render_view()
        {
            // Given
            var       expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(CustomisationId);
            const int progressId = 101;

            A.CallTo(() => courseCompletionService.GetCourseCompletion(CandidateId, CustomisationId))
            .Returns(expectedCourseCompletion);
            A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, CustomisationId, CentreId))
            .Returns(progressId);

            // When
            var result = controller.CompletionSummary(CustomisationId);

            // Then
            var expectedModel = new CourseCompletionViewModel(config, expectedCourseCompletion, progressId);

            result.Should().BeViewResult()
            .Model.Should().BeEquivalentTo(expectedModel);
        }
        public void CompletionSummary_should_return_404_if_unable_to_enrol()
        {
            // Given
            var expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(CustomisationId);

            A.CallTo(() => courseCompletionService.GetCourseCompletion(CandidateId, CustomisationId))
            .Returns(expectedCourseCompletion);
            A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, CustomisationId, CentreId))
            .Returns(null);

            // When
            var result = controller.CompletionSummary(CustomisationId);

            // Then
            result.Should()
            .BeRedirectToActionResult()
            .WithControllerName("LearningSolutions")
            .WithActionName("StatusCode")
            .WithRouteValue("code", 404);
        }
        public void CompletionSummary_should_StartOrUpdateDelegateSession_if_valid_course()
        {
            // Given
            var       expectedCourseCompletion = CourseCompletionHelper.CreateDefaultCourseCompletion(CustomisationId);
            const int progressId = 3;

            A.CallTo(() => courseCompletionService.GetCourseCompletion(CandidateId, CustomisationId))
            .Returns(expectedCourseCompletion);
            A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, CustomisationId, CentreId))
            .Returns(progressId);

            // When
            controller.CompletionSummary(CustomisationId);

            // Then
            A.CallTo(() => sessionService.StartOrUpdateDelegateSession(CandidateId, CustomisationId, httpContextSession))
            .MustHaveHappenedOnceExactly();
            A.CallTo(() => sessionService.StartOrUpdateDelegateSession(A <int> ._, A <int> ._, A <ISession> ._))
            .WhenArgumentsMatch((int candidateId, int customisationId, ISession session) =>
                                candidateId != CandidateId || customisationId != CustomisationId)
            .MustNotHaveHappened();
        }