public void Diagnostic_assessment_should_have_section_id()
        {
            // Given
            const int sectionId            = 22;
            var       diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment();

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, CustomisationId, sectionId);

            // Then
            diagnosticAssessmentViewModel.SectionId.Should().Be(sectionId);
        }
        public void Get_diagnostic_assessment_should_return_diagnostic_assessment_from_data_service()
        {
            // Given
            var diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment();

            A.CallTo(() => diagnosticAssessmentDataService.GetDiagnosticAssessment(CustomisationId, CandidateId, SectionId))
            .Returns(diagnosticAssessment);

            // When
            var result = diagnosticAssessmentService.GetDiagnosticAssessment(CustomisationId, CandidateId, SectionId);

            // Then
            result.Should().BeEquivalentTo(diagnosticAssessment);
        }
        public void Diagnostic_assessment_can_have_no_next_section_id()
        {
            // Given
            var diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment(
                nextSectionId: null
                );

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, CustomisationId, SectionId);

            // Then
            diagnosticAssessmentViewModel.NextSectionId.Should().BeNull();
        }
        public void Diagnostic_assessment_start_button_should_say_start_if_attempts_is_zero()
        {
            // Given
            var diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment(
                diagnosticAttempts: 0
                );

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, CustomisationId, SectionId);

            // Then
            diagnosticAssessmentViewModel.DiagnosticStartButtonText.Should().Be("Start assessment");
        }
        public void Diagnostic_assessment_start_button_colour_should_be_grey_if_attempts_is_more_than_zero()
        {
            // Given
            var diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment(
                diagnosticAttempts: 2
                );

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, CustomisationId, SectionId);

            // Then
            diagnosticAssessmentViewModel.DiagnosticStartButtonAdditionalStyling.Should().Be("nhsuk-button--secondary");
        }
        public void Diagnostic_assessment_start_button_should_have_no_colour_if_attempts_is_zero()
        {
            // Given
            var diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment(
                diagnosticAttempts: 0
                );

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, CustomisationId, SectionId);

            // Then
            diagnosticAssessmentViewModel.DiagnosticStartButtonAdditionalStyling.Should().Be("");
        }
        public void Diagnostic_assessment_attempts_information_with_no_attempts_should_be_not_attempted()
        {
            // Given
            const int diagnosticAttempts   = 0;
            var       diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment(
                diagnosticAttempts: diagnosticAttempts
                );

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, CustomisationId, SectionId);

            // Then
            diagnosticAssessmentViewModel.AttemptsInformation.Should().Be("Not attempted");
        }
        public void Diagnostic_assessment_select_tutorials_can_be_false()
        {
            // Given
            const bool selectTutorials      = false;
            var        diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment(
                canSelectTutorials: selectTutorials
                );

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, CustomisationId, SectionId);

            // Then
            diagnosticAssessmentViewModel.CanSelectTutorials.Should().BeFalse();
        }
        public void Diagnostic_assessment_can_have_next_tutorial_id()
        {
            // Given
            const int nextTutorialId       = 501;
            var       diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment(
                nextTutorialId: nextTutorialId
                );

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, CustomisationId, SectionId);

            // Then
            diagnosticAssessmentViewModel.NextTutorialId.Should().Be(nextTutorialId);
        }
        public void Diagnostic_assessment_should_have_section_name()
        {
            // Given
            const string sectionName          = "Section name";
            var          diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment(
                sectionName: sectionName
                );

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, CustomisationId, SectionId);

            // Then
            diagnosticAssessmentViewModel.SectionName.Should().Be(sectionName);
        }
        public void Diagnostic_assessment_can_have_post_learning()
        {
            // Given
            var diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment(
                postLearningAssessmentPath: "https://www.dls.nhs.uk/tracking/MOST/Excel10Core/Assess/L2_Excel_2010_Post_4.dcr",
                isAssessed: true
                );

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, CustomisationId, SectionId);

            // Then
            diagnosticAssessmentViewModel.HasPostLearningAssessment.Should().BeTrue();
        }
        public void Diagnostic_assessment_should_not_StartOrUpdate_course_sessions_if_unable_to_enrol()
        {
            // Given
            var defaultDiagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment();

            A.CallTo(() => diagnosticAssessmentService.GetDiagnosticAssessment(CustomisationId, CandidateId, SectionId))
            .Returns(defaultDiagnosticAssessment);
            A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, CustomisationId, CentreId))
            .Returns(null);

            // When
            controller.Diagnostic(CustomisationId, SectionId);

            // Then
            A.CallTo(() => sessionService.StartOrUpdateDelegateSession(A <int> ._, A <int> ._, A <ISession> ._)).MustNotHaveHappened();
        }
        public void Diagnostic_assessment_should_have_path()
        {
            // Given
            const string diagnosticAssessmentPath =
                "https://www.dls.nhs.uk/tracking/MOST/Excel07Core/Assess/L2_Excel_2007_Diag_7.dcr";
            var diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment(
                diagnosticAssessmentPath: diagnosticAssessmentPath
                );

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, CustomisationId, SectionId);

            // Then
            diagnosticAssessmentViewModel.DiagnosticAssessmentPath.Should().Be(diagnosticAssessmentPath);
        }
        public void Diagnostic_assessment_should_have_onlyItemInThisSection(
            bool otherItemsInSectionExist,
            bool expectedOnlyItemInThisSection
            )
        {
            // Given
            var diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment(
                otherItemsInSectionExist: otherItemsInSectionExist
                );

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, CustomisationId, SectionId);

            // Then
            diagnosticAssessmentViewModel.OnlyItemInThisSection.Should().Be(expectedOnlyItemInThisSection);
        }
        public void Diagnostic_assessment_should_UpdateProgress_if_valid_diagnostic_assessment()
        {
            // Given
            const int progressId = 299;
            var       defaultDiagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment();

            A.CallTo(() => diagnosticAssessmentService.GetDiagnosticAssessment(CustomisationId, CandidateId, SectionId))
            .Returns(defaultDiagnosticAssessment);
            A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, CustomisationId, CentreId))
            .Returns(progressId);

            // When
            controller.Diagnostic(CustomisationId, SectionId);

            // Then
            A.CallTo(() => courseContentService.UpdateProgress(progressId)).MustHaveHappened();
        }
        public void Diagnostic_assessment_should_have_title()
        {
            // Given
            const string applicationName      = "Application name";
            const string customisationName    = "Customisation name";
            var          diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment(
                applicationName: applicationName,
                customisationName: customisationName
                );

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, CustomisationId, SectionId);

            // Then
            diagnosticAssessmentViewModel.CourseTitle.Should().Be($"{applicationName} - {customisationName}");
        }
        public void Diagnostic_assessment_can_have_no_post_learning(
            string?postLearningAssessmentPath,
            bool isAssessed
            )
        {
            // Given
            var diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment(
                postLearningAssessmentPath: postLearningAssessmentPath,
                isAssessed: isAssessed
                );

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, CustomisationId, SectionId);

            // Then
            diagnosticAssessmentViewModel.HasPostLearningAssessment.Should().BeFalse();
        }
        public void Diagnostic_assessment_should_404_if_failed_to_enrol()
        {
            // Given
            var defaultDiagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment();

            A.CallTo(() => diagnosticAssessmentService.GetDiagnosticAssessment(CustomisationId, CandidateId, SectionId))
            .Returns(defaultDiagnosticAssessment);
            A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, CustomisationId, CentreId)).Returns(null);

            // When
            var result = controller.Diagnostic(CustomisationId, SectionId);

            // Then
            result.Should()
            .BeRedirectToActionResult()
            .WithControllerName("LearningSolutions")
            .WithActionName("StatusCode")
            .WithRouteValue("code", 404);
        }
        public void Diagnostic_assessment_should_have_tutorials()
        {
            // Given
            var tutorials = new[]
            {
                new DiagnosticTutorial("Tutorial 1", 1),
                new DiagnosticTutorial("Tutorial 2", 2)
            };
            var diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment();

            diagnosticAssessment.Tutorials.AddRange(tutorials);

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, CustomisationId, SectionId);

            // Then
            diagnosticAssessmentViewModel.Tutorials.Should().BeEquivalentTo <DiagnosticTutorial>(tutorials);
        }
        public void Diagnostic_assessment_attempts_information_with_attempts_should_be_last_score()
        {
            // Given
            const int diagnosticAttempts   = 3;
            const int sectionScore         = 10;
            const int maxSectionScore      = 20;
            var       diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment(
                diagnosticAttempts: diagnosticAttempts,
                sectionScore: sectionScore,
                maxSectionScore: maxSectionScore
                );

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, CustomisationId, SectionId);

            // Then
            diagnosticAssessmentViewModel.AttemptsInformation.Should().Be("10/20 - 3 attempts");
        }
        public void Diagnostic_assessment_should_render_view()
        {
            // Given
            const int progressId = 299;
            var       defaultDiagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment();

            A.CallTo(() => diagnosticAssessmentService.GetDiagnosticAssessment(CustomisationId, CandidateId, SectionId))
            .Returns(defaultDiagnosticAssessment);
            A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, CustomisationId, CentreId)).
            Returns(progressId);

            // When
            var result = controller.Diagnostic(CustomisationId, SectionId);

            // Then
            var expectedModel = new DiagnosticAssessmentViewModel(defaultDiagnosticAssessment, CustomisationId, SectionId);

            result.Should().BeViewResult()
            .Model.Should().BeEquivalentTo(expectedModel);
        }
        public void Diagnostic_assessment_should_StartOrUpdate_course_sessions_if_valid_diagnostic_assessment()
        {
            // Given
            const int progressId = 299;
            var       defaultDiagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment();

            A.CallTo(() => diagnosticAssessmentService.GetDiagnosticAssessment(CustomisationId, CandidateId, SectionId))
            .Returns(defaultDiagnosticAssessment);
            A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, CustomisationId, CentreId))
            .Returns(progressId);

            // When
            controller.Diagnostic(CustomisationId, SectionId);

            // 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();
        }
        public void Diagnostic_assessment_should_have_showCompletionSummary(
            bool otherSectionsExist,
            bool otherItemsInSectionExist,
            bool includeCertification,
            bool expectedShowCompletionSummary
            )
        {
            // Given
            var diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment(
                otherSectionsExist: otherSectionsExist,
                otherItemsInSectionExist: otherItemsInSectionExist,
                includeCertification: includeCertification
                );

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, CustomisationId, SectionId);

            // Then
            diagnosticAssessmentViewModel.ShowCompletionSummary.Should().Be(expectedShowCompletionSummary);
        }
        public void Diagnostic_assessment_should_have_showNextButton(
            bool otherSectionsExist,
            bool otherItemsInSectionExist,
            int diagnosticAttempts,
            bool expectedShowNextButton
            )
        {
            // Given
            var diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment(
                otherSectionsExist: otherSectionsExist,
                otherItemsInSectionExist: otherItemsInSectionExist,
                diagnosticAttempts: diagnosticAttempts
                );

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, CustomisationId, SectionId);

            // Then
            diagnosticAssessmentViewModel.ShowNextButton.Should().Be(expectedShowNextButton);
        }
        public void Diagnostic_assessment_should_have_completion_summary_card_view_model(
            int customisationId,
            string?completed,
            int maxPostLearningAssessmentAttempts,
            bool isAssessed,
            int postLearningAssessmentPassThreshold,
            int diagnosticAssessmentCompletionThreshold,
            int tutorialsCompletionThreshold
            )
        {
            // Given
            var completedDateTime = completed != null?DateTime.Parse(completed) : (DateTime?)null;

            var diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment(
                completed: completedDateTime,
                maxPostLearningAssessmentAttempts: maxPostLearningAssessmentAttempts,
                isAssessed: isAssessed,
                postLearningAssessmentPassThreshold: postLearningAssessmentPassThreshold,
                diagnosticAssessmentCompletionThreshold: diagnosticAssessmentCompletionThreshold,
                tutorialsCompletionThreshold: tutorialsCompletionThreshold
                );

            var expectedCompletionSummaryViewModel = new CompletionSummaryCardViewModel(
                customisationId,
                completedDateTime,
                maxPostLearningAssessmentAttempts,
                isAssessed,
                postLearningAssessmentPassThreshold,
                diagnosticAssessmentCompletionThreshold,
                tutorialsCompletionThreshold
                );

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, customisationId, SectionId);

            // Then
            diagnosticAssessmentViewModel.CompletionSummaryCardViewModel
            .Should().BeEquivalentTo(expectedCompletionSummaryViewModel);
        }
        public void Diagnostic_assessment_select_tutorials_with_tutorials_should_be_canSelectTutorials(
            bool selectTutorials
            )
        {
            // Given
            var tutorials = new[]
            {
                new DiagnosticTutorial("Tutorial 1", 1),
                new DiagnosticTutorial("Tutorial 2", 2)
            };
            var diagnosticAssessment = DiagnosticAssessmentTestHelper.CreateDefaultDiagnosticAssessment(
                canSelectTutorials: selectTutorials
                );

            diagnosticAssessment.Tutorials.AddRange(tutorials);

            // When
            var diagnosticAssessmentViewModel =
                new DiagnosticAssessmentViewModel(diagnosticAssessment, CustomisationId, SectionId);

            // Then
            diagnosticAssessmentViewModel.CanSelectTutorials.Should().Be(selectTutorials);
        }