예제 #1
0
        public void Index_should_not_redirect_to_section_page_if_more_than_one_section_in_course()
        {
            // Given
            const int customisationId = 123;
            const int sectionId       = 456;
            var       section1        = CourseContentHelper.CreateDefaultCourseSection(id: sectionId + 1);
            var       section2        = CourseContentHelper.CreateDefaultCourseSection(id: sectionId + 2);
            var       section3        = CourseContentHelper.CreateDefaultCourseSection(id: sectionId + 3);

            var expectedCourseContent = CourseContentHelper.CreateDefaultCourseContent(customisationId);

            expectedCourseContent.Sections.AddRange(new[] { section1, section2, section3 });

            A.CallTo(() => courseContentService.GetCourseContent(CandidateId, customisationId))
            .Returns(expectedCourseContent);
            A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, customisationId, CentreId)).Returns(10);

            // When
            var result = controller.Index(customisationId);

            // Then
            var expectedModel = new InitialMenuViewModel(expectedCourseContent);

            result.Should().BeViewResult()
            .Model.Should().BeEquivalentTo(expectedModel);
        }
예제 #2
0
        public void Initial_menu_should_have_list_of_section_card_view_model()
        {
            // Given
            const string sectionName     = "TestSectionName";
            const bool   hasLearning     = true;
            const double percentComplete = 12.00;
            const int    customisationId = 1;
            const bool   showPercentage  = true;
            const string courseSettings  = "{\"lm.sp\":true}"; // ShowPercentage = true

            var courseContent = CourseContentHelper.CreateDefaultCourseContent(
                customisationId: customisationId,
                courseSettings: courseSettings
                );
            var section = CourseSectionHelper.CreateDefaultCourseSection(
                sectionName: sectionName,
                hasLearning: hasLearning,
                percentComplete: percentComplete
                );

            courseContent.Sections.Add(section);
            var expectedSection     = new SectionCardViewModel(section, customisationId, showPercentage);
            var expectedSectionList = new List <SectionCardViewModel>
            {
                expectedSection
            };

            // When
            var initialMenuViewModel = new InitialMenuViewModel(courseContent);

            // Then
            initialMenuViewModel.Sections.Should().BeEquivalentTo(expectedSectionList);
        }
예제 #3
0
        public void Initial_menu_formats_average_duration(int?averageDuration, string?expectedFormattedTime)
        {
            // Given
            var expectedCourseContent = CourseContentHelper.CreateDefaultCourseContent(averageDuration: averageDuration);

            // When
            var initialMenuViewModel = new InitialMenuViewModel(expectedCourseContent);

            // Then
            initialMenuViewModel.AverageDuration.Should().Be(expectedFormattedTime);
        }
예제 #4
0
        public void Initial_menu_banner_text_can_be_null()
        {
            // Given
            var expectedCourseContent = CourseContentHelper.CreateDefaultCourseContent(
                bannerText: null
                );

            // When
            var initialMenuViewModel = new InitialMenuViewModel(expectedCourseContent);

            // Then
            initialMenuViewModel.BannerText.Should().BeNullOrEmpty();
        }
예제 #5
0
        public void Initial_menu_should_have_false_show_time_if_setting_is_false()
        {
            // Given
            const string courseSettings        = "{\"lm.st\":false}"; // ShowTime = false
            var          expectedCourseContent = CourseContentHelper.CreateDefaultCourseContent(
                courseSettings: courseSettings
                );

            // When
            var initialMenuViewModel = new InitialMenuViewModel(expectedCourseContent);

            // Then
            initialMenuViewModel.ShowTime.Should().BeFalse();
        }
예제 #6
0
        public void Initial_menu_should_have_centre_name()
        {
            // Given
            const string centreName            = "CentreName";
            var          expectedCourseContent = CourseContentHelper.CreateDefaultCourseContent(
                centreName: centreName
                );

            // When
            var initialMenuViewModel = new InitialMenuViewModel(expectedCourseContent);

            // Then
            initialMenuViewModel.CentreName.Should().Be(centreName);
        }
예제 #7
0
        public void Initial_menu_should_have_id()
        {
            // Given
            const int customisationId       = 12;
            var       expectedCourseContent = CourseContentHelper.CreateDefaultCourseContent(
                customisationId: customisationId
                );

            // When
            var initialMenuViewModel = new InitialMenuViewModel(expectedCourseContent);

            // Then
            initialMenuViewModel.Id.Should().Be(customisationId);
        }
예제 #8
0
        public void Initial_menu_should_not_show_completion_summary_when_include_certification_is_false()
        {
            // Given
            const bool includeCertification  = false;
            var        expectedCourseContent = CourseContentHelper.CreateDefaultCourseContent(
                includeCertification: includeCertification
                );

            // When
            var initialMenuViewModel = new InitialMenuViewModel(expectedCourseContent);

            // Then
            initialMenuViewModel.ShouldShowCompletionSummary.Should().Be(includeCertification);
        }
예제 #9
0
        public void Initial_menu_can_have_banner_text()
        {
            // Given
            const string bannerText            = "BannerText";
            var          expectedCourseContent = CourseContentHelper.CreateDefaultCourseContent(
                bannerText: bannerText
                );

            // When
            var initialMenuViewModel = new InitialMenuViewModel(expectedCourseContent);

            // Then
            initialMenuViewModel.BannerText.Should().Be(bannerText);
        }
예제 #10
0
        public IActionResult Index(int customisationId)
        {
            var centreId = User.GetCentreId();

            if (config.GetValue <string>("LegacyLearningMenu") != "")
            {
                if ((config.GetValue <bool>("LegacyLearningMenu") && !configService.GetCentreBetaTesting(centreId)) | (!config.GetValue <bool>("LegacyLearningMenu") && configService.GetCentreBetaTesting(centreId)))
                {
                    string baseUrl = config.GetValue <string>("CurrentSystemBaseUrl");
                    string url     = $"{baseUrl}/tracking/learn?customisationid={customisationId}&lp=1";
                    return(Redirect(url));
                }
            }
            var candidateId   = User.GetCandidateIdKnownNotNull();
            var courseContent = courseContentService.GetCourseContent(candidateId, customisationId);

            if (courseContent == null)
            {
                logger.LogError(
                    "Redirecting to 404 as course/centre id was not found. " +
                    $"Candidate id: {candidateId}, customisation id: {customisationId}, " +
                    $"centre id: {centreId.ToString() ?? "null"}");
                return(RedirectToAction("StatusCode", "LearningSolutions", new { code = 404 }));
            }
            if (!String.IsNullOrEmpty(courseContent.Password) && !courseContent.PasswordSubmitted)
            {
                return(RedirectToAction("CoursePassword", "LearningMenu", new { customisationId }));
            }
            if (courseContent.Sections.Count == 1)
            {
                var sectionId = courseContent.Sections.First().Id;
                return(RedirectToAction("Section", "LearningMenu", new { customisationId, sectionId }));
            }
            var progressId = courseContentService.GetOrCreateProgressId(candidateId, customisationId, centreId);

            if (progressId == null)
            {
                logger.LogError(
                    "Redirecting to 404 as no progress id was returned. " +
                    $"Candidate id: {candidateId}, customisation id: {customisationId}, centre id: {centreId}");
                return(RedirectToAction("StatusCode", "LearningSolutions", new { code = 404 }));
            }
            sessionService.StartOrUpdateDelegateSession(candidateId, customisationId, HttpContext.Session);
            courseContentService.UpdateProgress(progressId.Value);
            var model = new InitialMenuViewModel(courseContent);

            return(View(model));
        }
예제 #11
0
        public void Initial_menu_should_have_name()
        {
            // Given
            const string customisationName     = "Custom";
            const string applicationName       = "My course";
            var          expectedCourseContent = CourseContentHelper.CreateDefaultCourseContent(
                customisationName: customisationName,
                applicationName: applicationName
                );

            // When
            var initialMenuViewModel = new InitialMenuViewModel(expectedCourseContent);

            // Then
            initialMenuViewModel.Title.Should().Be($"{applicationName} - {customisationName}");
        }
예제 #12
0
        public IActionResult CoursePassword(int customisationId, bool error = false)
        {
            var centreId      = User.GetCentreId();
            var candidateId   = User.GetCandidateIdKnownNotNull();
            var courseContent = courseContentService.GetCourseContent(candidateId, customisationId);

            if (courseContent == null)
            {
                logger.LogError(
                    "Redirecting to 404 as course/centre id was not found. " +
                    $"Candidate id: {candidateId}, customisation id: {customisationId}, " +
                    $"centre id: {centreId.ToString() ?? "null"}");
                return(RedirectToAction("StatusCode", "LearningSolutions", new { code = 404 }));
            }
            var model = new InitialMenuViewModel(courseContent);

            return(View(model));
        }
예제 #13
0
        public void Index_should_render_view()
        {
            // Given
            var expectedCourseContent = CourseContentHelper.CreateDefaultCourseContent(CustomisationId);

            A.CallTo(() => courseContentService.GetCourseContent(CandidateId, CustomisationId))
            .Returns(expectedCourseContent);
            A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, CustomisationId, CentreId)).Returns(10);

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

            // Then
            var expectedModel = new InitialMenuViewModel(expectedCourseContent);

            result.Should().BeViewResult()
            .Model.Should().BeEquivalentTo(expectedModel);
        }
예제 #14
0
        public void Initial_menu_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 courseContent = CourseContentHelper.CreateDefaultCourseContent(
                customisationId: customisationId,
                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 initialMenuViewModel = new InitialMenuViewModel(courseContent);

            // Then
            initialMenuViewModel.CompletionSummaryCardViewModel
            .Should().BeEquivalentTo(expectedCompletionSummaryViewModel);
        }