SaveCourseContent_does_not_redirect_with_invalid_model() { // Given var sectionModel = new Section(1, "Test name"); var model = new SetCourseContentViewModel(new List <Section> { sectionModel }, false, null); controller.ModelState.AddModelError("SelectedSectionIds", "test message"); SetAddNewCentreCourseTempData(new ApplicationDetails()); 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()) { result.Should().BeViewResult().ModelAs <SetCourseContentViewModel>(); controller.ModelState["SelectedSectionIds"].Errors[0].ErrorMessage.Should() .Be("test message"); } }
public IActionResult SetCourseContent(SetCourseContentViewModel model) { var data = multiPageFormService.GetMultiPageFormData <AddNewCentreCourseTempData>( MultiPageFormDataFeature.AddNewCourse, TempData ); if (data.Application == null) { throw new Exception("Application should not be null at this point in the journey"); } if (model.IncludeAllSections) { ModelState.ClearErrorsOnField(nameof(model.SelectedSectionIds)); model.SelectAllSections(); data !.SectionContentData = GetSectionContentDataWithAllContentEnabled(model, data !.Application !.DiagAssess).ToList(); } else { data !.SectionContentData = null; } if (!ModelState.IsValid) { return(View("AddNewCentreCourse/SetCourseContent", model)); } data.CourseContentData = model.ToDataCourseContentTempData(); multiPageFormService.SetMultiPageFormData(data, MultiPageFormDataFeature.AddNewCourse, TempData); return(RedirectToAction(model.IncludeAllSections ? "Summary" : "SetSectionContent")); }
public static CourseContentTempData ToDataCourseContentTempData(this SetCourseContentViewModel model) { return(new CourseContentTempData( model.AvailableSections, model.IncludeAllSections, model.SelectedSectionIds )); }
private IActionResult RedirectToNextSectionOrSummary( int index, SetCourseContentViewModel setCourseContentViewModel ) { var nextSectionIndex = index + 1; return(nextSectionIndex == setCourseContentViewModel.GetSelectedSections().Count() ? RedirectToAction("Summary") : RedirectToAction("SetSectionContent", new { sectionIndex = nextSectionIndex })); }
private IEnumerable <SectionContentTempData> GetSectionContentDataWithAllContentEnabled( SetCourseContentViewModel model, bool diagAssess ) { return(model.GetSelectedSections() .Select( (s, index) => { var tutorials = tutorialService.GetTutorialsForSection(s.SectionId).ToList(); foreach (var tutorial in tutorials) { tutorial.Status = true; tutorial.DiagStatus = diagAssess; } return new SectionContentTempData(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"); } }