Пример #1
0
        public IActionResult SetSectionContent(int sectionIndex)
        {
            var data = multiPageFormService.GetMultiPageFormData <AddNewCentreCourseTempData>(
                MultiPageFormDataFeature.AddNewCourse,
                TempData
                );

            if (data.CourseContentData == null || data.Application == null)
            {
                throw new Exception(
                          "Application amd CourseContentData should not be null at this point in the journey"
                          );
            }

            var section   = data !.CourseContentData !.GetSelectedSections().ElementAt(sectionIndex);
            var tutorials = tutorialService.GetTutorialsForSection(section.SectionId).ToList();

            if (!tutorials.Any())
            {
                return(RedirectToNextSectionOrSummary(
                           sectionIndex,
                           new SetCourseContentViewModel(data.CourseContentData)
                           ));
            }

            var showDiagnostic = data.Application !.DiagAssess;
            var model          = new SetSectionContentViewModel(section, sectionIndex, showDiagnostic, tutorials);

            return(View("AddNewCentreCourse/SetSectionContent", model));
        }
        public void GetTutorialsForSection_calls_data_service_and_returns_expected_tutorials()
        {
            // Given
            var tutorialOne = new Tutorial(1, "Test", true, true, null, null);
            var tutorialTwo = new Tutorial(2, "Case", false, false, null, null);
            var tutorials   = new List <Tutorial> {
                tutorialOne, tutorialTwo
            };

            A.CallTo(
                () => tutorialContentDataService.GetTutorialsForSection(1)
                ).Returns(tutorials);

            // When
            var result = tutorialService.GetTutorialsForSection(1);

            // Then
            using (new AssertionScope())
            {
                A.CallTo(() => tutorialContentDataService.GetTutorialsForSection(1))
                .MustHaveHappenedOnceExactly();
                result.Should().BeEquivalentTo(tutorials);
            }
        }
        public void SetCourseContent_post_updates_temp_data_and_redirects_to_summary_if_IncludeAllSections_is_selected()
        {
            // Given
            var section = new Section(1, "Test name");
            var model   = new SetCourseContentViewModel(
                new List <Section> {
                section
            },
                true,
                new List <int> {
                1
            }
                );

            controller.ModelState.AddModelError("SelectedSectionIds", "test message");
            SetAddNewCentreCourseTempData(application);

            A.CallTo(
                () => tutorialService.GetTutorialsForSection(1)
                ).Returns(new List <Tutorial> {
                new Tutorial(1, "Test name", true, true)
            });

            // When
            var result = controller.SetCourseContent(model);

            // Then
            using (new AssertionScope())
            {
                A.CallTo(
                    () => multiPageFormService.SetMultiPageFormData(
                        A <AddNewCentreCourseTempData> .That.Matches(d => d.CourseContentData != null),
                        MultiPageFormDataFeature.AddNewCourse,
                        controller.TempData
                        )
                    ).MustHaveHappenedOnceExactly();
                result.Should().BeRedirectToActionResult().WithActionName("Summary");
            }
        }