Exemple #1
0
        public void Section_content_view_model_should_properly_convert_consolidation_path()
        {
            // Given
            const string consolidationPath = "consolidation/path";
            var          sectionContent    = SectionContentHelper.CreateDefaultSectionContent(
                consolidationPath: consolidationPath
                );
            var expectedConsolidationPath = $"{BaseUrl}/tracking/dlconsolidation?client={consolidationPath}";

            // When
            var sectionContentViewModel = new SectionContentViewModel(config, sectionContent, CustomisationId, SectionId);

            // Then
            sectionContentViewModel.ConsolidationExercisePath.Should().Be(expectedConsolidationPath);
        }
Exemple #2
0
        public void Section_content_should_have_title()
        {
            // Given
            const string applicationName   = "Application name";
            const string customisationName = "Customisation name";
            var          sectionContent    = SectionContentHelper.CreateDefaultSectionContent(
                applicationName: applicationName,
                customisationName: customisationName
                );

            // When
            var sectionContentViewModel = new SectionContentViewModel(config, sectionContent, CustomisationId, SectionId);

            // Then
            sectionContentViewModel.CourseTitle.Should().Be($"{applicationName} - {customisationName}");
        }
Exemple #3
0
        public void Diagnostic_assessment_completion_status_does_not_use_plural_if_attempts_is_one()
        {
            // Given
            const int diagAttempts   = 1;
            const int secScore       = 10;
            const int secOutOf       = 15;
            var       sectionContent = SectionContentHelper.CreateDefaultSectionContent(
                diagAttempts: diagAttempts,
                secScore: secScore,
                secOutOf: secOutOf);

            // When
            var sectionContentViewModel = new SectionContentViewModel(config, sectionContent, CustomisationId, SectionId);

            // Then
            sectionContentViewModel.DiagnosticCompletionStatus.Should().Be($"{secScore}/{secOutOf} - {diagAttempts} attempt");
        }
Exemple #4
0
        public void Diagnostic_assessment_completion_status_shows_score_and_attempts_if_diag_attempts_is_more_than_0()
        {
            // Given
            const int diagAttempts   = 4;
            const int secScore       = 10;
            const int secOutOf       = 15;
            var       sectionContent = SectionContentHelper.CreateDefaultSectionContent(
                diagAttempts: diagAttempts,
                secScore: secScore,
                secOutOf: secOutOf);

            // When
            var sectionContentViewModel = new SectionContentViewModel(config, sectionContent, CustomisationId, SectionId);

            // Then
            sectionContentViewModel.DiagnosticCompletionStatus.Should().Be($"{secScore}/{secOutOf} - {diagAttempts} attempts");
        }
        public void Section_should_render_view()
        {
            // Given
            const int progressId            = 299;
            var       defaultSectionContent = SectionContentHelper.CreateDefaultSectionContent();

            A.CallTo(() => sectionContentDataService.GetSectionContent(CustomisationId, CandidateId, SectionId))
            .Returns(defaultSectionContent);
            A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, CustomisationId, CentreId)).
            Returns(progressId);

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

            // Then
            var expectedModel = new SectionContentViewModel(config, defaultSectionContent, CustomisationId, SectionId);

            result.Should().BeViewResult()
            .Model.Should().BeEquivalentTo(expectedModel);
        }
Exemple #6
0
        public void Post_learning_separator_displays_in_correct_situations(
            bool showPostLearningAssessment,
            bool showConsolidationExercise,
            bool separatorExpected
            )
        {
            // Given
            var consolidationPath = showConsolidationExercise
                ? "https://www.dls.nhs.uk/tracking/MOST/Word07Core/cons/WC07-Exercise_1.zip"
                : null;
            var sectionContent = SectionContentHelper.CreateDefaultSectionContent(
                isAssessed: showPostLearningAssessment,
                consolidationPath: consolidationPath
                );

            // When
            var sectionContentViewModel = new SectionContentViewModel(config, sectionContent, CustomisationId, SectionId);

            // Then
            sectionContentViewModel.DisplayPostLearningSeparator.Should().Be(separatorExpected);
        }
Exemple #7
0
        public void Section_content_with_mixed_status_tutorials_that_need_rounding_returns_correct_percent_complete()
        {
            // Given
            const bool hasLearning = true;
            var        tutorials   = new[]
            {
                SectionTutorialHelper.CreateDefaultSectionTutorial(tutStat: 2),
                SectionTutorialHelper.CreateDefaultSectionTutorial(tutStat: 0),
                SectionTutorialHelper.CreateDefaultSectionTutorial(tutStat: 0)
            };
            const int roundedPercentComplete = 33;
            var       sectionContent         = SectionContentHelper.CreateDefaultSectionContent(hasLearning: hasLearning);

            sectionContent.Tutorials.AddRange(tutorials);

            // When
            var sectionContentViewModel = new SectionContentViewModel(config, sectionContent, CustomisationId, SectionId);

            // Then
            sectionContentViewModel.PercentComplete.Should().Be($"{roundedPercentComplete}% learning complete");
        }
Exemple #8
0
        public void Section_content_with_all_started_tutorials_should_have_fifty_percent_complete()
        {
            // Given
            const bool hasLearning = true;
            var        tutorials   = new[]
            {
                SectionTutorialHelper.CreateDefaultSectionTutorial(tutStat: 1),
                SectionTutorialHelper.CreateDefaultSectionTutorial(tutStat: 1),
                SectionTutorialHelper.CreateDefaultSectionTutorial(tutStat: 1)
            };
            const int expectedPercentComplete = 50;
            var       sectionContent          = SectionContentHelper.CreateDefaultSectionContent(hasLearning: hasLearning);

            sectionContent.Tutorials.AddRange(tutorials);

            // When
            var sectionContentViewModel = new SectionContentViewModel(config, sectionContent, CustomisationId, SectionId);

            // Then
            sectionContentViewModel.PercentComplete.Should().Be($"{expectedPercentComplete}% learning complete");
        }
Exemple #9
0
        public void Section_content_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 sectionContent = SectionContentHelper.CreateDefaultSectionContent(
                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 sectionContentViewModel = new SectionContentViewModel(config, sectionContent, customisationId, SectionId);

            // Then
            sectionContentViewModel.CompletionSummaryCardViewModel
            .Should().BeEquivalentTo(expectedCompletionSummaryViewModel);
        }
Exemple #10
0
        public void Percent_complete_should_correctly_be_floored()
        {
            // Given
            const bool hasLearning = true;
            var        tutorials   = new[]
            {
                SectionTutorialHelper.CreateDefaultSectionTutorial(tutStat: 2),
                SectionTutorialHelper.CreateDefaultSectionTutorial(tutStat: 2),
                SectionTutorialHelper.CreateDefaultSectionTutorial(tutStat: 0)
            };
            // Percent complete will be 66.666667 which when floored should be 66
            const int roundedPercentComplete = 66;
            var       sectionContent         = SectionContentHelper.CreateDefaultSectionContent(hasLearning: hasLearning);

            sectionContent.Tutorials.AddRange(tutorials);

            // When
            var sectionContentViewModel = new SectionContentViewModel(config, sectionContent, CustomisationId, SectionId);

            // Then
            sectionContentViewModel.PercentComplete.Should().Be($"{roundedPercentComplete}% learning complete");
        }
Exemple #11
0
        public void Section_content_with_false_showPercentage_course_setting_should_not_show_percent_complete()
        {
            // Given
            const string courseSettings = "{\"lm.sp\":false}"; // ShowPercentage = false
            var          tutorials      = new[]
            {
                SectionTutorialHelper.CreateDefaultSectionTutorial(tutStat: 2),
                SectionTutorialHelper.CreateDefaultSectionTutorial(tutStat: 0),
                SectionTutorialHelper.CreateDefaultSectionTutorial(tutStat: 0)
            };
            var sectionContent = SectionContentHelper.CreateDefaultSectionContent(
                hasLearning: true,
                courseSettings: courseSettings
                );

            sectionContent.Tutorials.AddRange(tutorials);

            // When
            var sectionContentViewModel = new SectionContentViewModel(config, sectionContent, CustomisationId, SectionId);

            // Then
            sectionContentViewModel.ShowPercentComplete.Should().BeFalse();
        }
Exemple #12
0
        public IActionResult Section(int customisationId, int sectionId)
        {
            var candidateId    = User.GetCandidateIdKnownNotNull();
            var centreId       = User.GetCentreId();
            var sectionContent = sectionContentDataService.GetSectionContent(customisationId, candidateId, sectionId);

            if (sectionContent == null)
            {
                logger.LogError(
                    "Redirecting to 404 as section/centre id was not found. " +
                    $"Candidate id: {candidateId}, customisation id: {customisationId}, " +
                    $"centre id: {centreId.ToString() ?? "null"}, section id: {sectionId}");
                return(RedirectToAction("StatusCode", "LearningSolutions", new { code = 404 }));
            }
            if (!String.IsNullOrEmpty(sectionContent.Password) && !sectionContent.PasswordSubmitted)
            {
                return(RedirectToAction("CoursePassword", "LearningMenu", new { customisationId }));
            }
            var hasDiagnosticAssessment   = sectionContent.DiagnosticAssessmentPath != null && sectionContent.DiagnosticStatus;
            var hasPostLearningAssessment = sectionContent.PostLearningAssessmentPath != null && sectionContent.IsAssessed;
            var hasConsolidationMaterial  = sectionContent.ConsolidationPath != null;

            if (sectionContent.Tutorials.Count == 1 &&
                !hasDiagnosticAssessment &&
                !hasPostLearningAssessment &&
                !hasConsolidationMaterial
                )
            {
                var tutorialId = sectionContent.Tutorials.First().Id;
                return(RedirectToAction("Tutorial", "LearningMenu", new { customisationId, sectionId, tutorialId }));
            }

            var justHasAssessments = sectionContent.Tutorials.Count == 0 &&
                                     !hasConsolidationMaterial &&
                                     (hasDiagnosticAssessment || hasPostLearningAssessment);

            if (justHasAssessments && !hasDiagnosticAssessment)
            {
                return(RedirectToAction("PostLearning", "LearningMenu", new { customisationId, sectionId }));
            }

            if (justHasAssessments && !hasPostLearningAssessment)
            {
                return(RedirectToAction("Diagnostic", "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}, section id: {sectionId}");
                return(RedirectToAction("StatusCode", "LearningSolutions", new { code = 404 }));
            }

            sessionService.StartOrUpdateDelegateSession(candidateId, customisationId, HttpContext.Session);
            courseContentService.UpdateProgress(progressId.Value);

            var model = new SectionContentViewModel(config, sectionContent, customisationId, sectionId);

            return(View("Section/Section", model));
        }
Exemple #13
0
        public void UpdateAssignement(SectionContentViewModel model)
        {
            if (model.SimpleTexts != null)
            {
                var toAdd   = GetItems <SimpleText>(model.SimpleTexts).Select(x => x.Id);
                var current = GetCurrent <SimpleTextNode>(model.NodeId).Select(x => x.SimpleTextId);

                foreach (var item in toAdd)
                {
                    if (!current.Contains(item))
                    {
                        BindItem <SimpleTextNode>(item, model.NodeId, new SimpleTextNode());
                    }
                }

                foreach (var item in current)
                {
                    if (!toAdd.Contains(item))
                    {
                        //UnbindItem<SimpleTextNode>(item, model.NodeId);
                        var element = _db.Set <SimpleTextNode>()
                                      .FirstOrDefault(x => x.NodeId == model.NodeId && x.SimpleTextId == item);
                        _db.Remove(element);
                    }
                }
            }

            if (model.Collections != null)
            {
                var toAdd   = GetItems <Collection>(model.Collections).Select(x => x.Id);
                var current = GetCurrent <CollectionNode>(model.NodeId).Select(x => x.CollectionId);

                foreach (var item in toAdd)
                {
                    if (!current.Contains(item))
                    {
                        BindItem <CollectionNode>(item, model.NodeId, new CollectionNode());
                    }
                }

                foreach (var item in current)
                {
                    if (!toAdd.Contains(item))
                    {
                        var element = _db.Set <CollectionNode>()
                                      .FirstOrDefault(x => x.NodeId == model.NodeId && x.CollectionId == item);
                        _db.Remove(element);
                    }
                }
            }

            if (model.Baners != null)
            {
                var toAdd   = GetItems <Baner>(model.Baners).Select(x => x.Id);
                var current = GetCurrent <BanerNode>(model.NodeId).Select(x => x.BanerId);

                foreach (var item in toAdd)
                {
                    if (!current.Contains(item))
                    {
                        BindItem <BanerNode>(item, model.NodeId, new BanerNode());
                    }
                }

                foreach (var item in current)
                {
                    if (!toAdd.Contains(item))
                    {
                        var element = _db.Set <BanerNode>()
                                      .FirstOrDefault(x => x.NodeId == model.NodeId && x.BanerId == item);
                        _db.Remove(element);
                    }
                }
            }

            if (model.Businesses != null)
            {
                var toAdd   = GetItems <Business>(model.Businesses).Select(x => x.Id);
                var current = GetCurrent <BusinessNode>(model.NodeId).Select(x => x.BusinessId);

                foreach (var item in toAdd)
                {
                    if (!current.Contains(item))
                    {
                        BindItem <BusinessNode>(item, model.NodeId, new BusinessNode());
                    }
                }

                foreach (var item in current)
                {
                    if (!toAdd.Contains(item))
                    {
                        var element = _db.Set <BanerNode>()
                                      .FirstOrDefault(x => x.NodeId == model.NodeId && x.BanerId == item);
                        _db.Remove(element);
                    }
                }
            }

            if (model.Panels != null)
            {
                var toAdd   = GetItems <SimplePanel>(model.Panels).Select(x => x.Id);
                var current = GetCurrent <SimplePanelNode>(model.NodeId).Select(x => x.SimplePanelId);

                foreach (var item in toAdd)
                {
                    if (!current.Contains(item))
                    {
                        BindItem <SimplePanelNode>(item, model.NodeId, new SimplePanelNode());
                    }
                }

                foreach (var item in current)
                {
                    if (!toAdd.Contains(item))
                    {
                        var element = _db.Set <SimplePanelNode>()
                                      .FirstOrDefault(x => x.NodeId == model.NodeId && x.SimplePanelId == item);
                        _db.Remove(element);
                    }
                }
            }

            if (model.Portfolios != null)
            {
                var toAdd   = GetItems <Portfolio>(model.Portfolios).Select(x => x.Id);
                var current = GetCurrent <PortfolioNode>(model.NodeId).Select(x => x.PortfolioId);

                foreach (var item in toAdd)
                {
                    if (!current.Contains(item))
                    {
                        BindItem <PortfolioNode>(item, model.NodeId, new PortfolioNode());
                    }
                }

                foreach (var item in current)
                {
                    if (!toAdd.Contains(item))
                    {
                        var element = _db.Set <PortfolioNode>()
                                      .FirstOrDefault(x => x.NodeId == model.NodeId && x.PortfolioId == item);
                        _db.Remove(element);
                    }
                }
            }

            if (model.Sliders != null)
            {
                var toAdd   = GetItems <Slider>(model.Sliders).Select(x => x.Id);
                var current = GetCurrent <SliderNode>(model.NodeId).Select(x => x.SliderId);

                foreach (var item in toAdd)
                {
                    if (!current.Contains(item))
                    {
                        BindItem <SliderNode>(item, model.NodeId, new SliderNode());
                    }
                }

                foreach (var item in current)
                {
                    if (!toAdd.Contains(item))
                    {
                        var element = _db.Set <SliderNode>()
                                      .FirstOrDefault(x => x.NodeId == model.NodeId && x.SliderId == item);
                        _db.Remove(element);
                    }
                }
            }
        }
 public IActionResult Edit(SectionContentViewModel model)
 {
     _sectionService.UpdateAssignement(model);
     _sectionService.Commit();
     return(RedirectToAction("Index"));
 }