public void SaveAutoRefreshOptions_does_not_call_service_with_invalid_model() { // Given var learningPathwayModel = new EditLearningPathwayDefaultsViewModel(1, "6", "12", false, false); var autoRefreshModel = GetEditAutoRefreshOptionsViewModel(autoRefreshMonths: 13); controller.ModelState.AddModelError("AutoRefreshMonths", "Enter a whole number from 0 to 12"); var learningPathwayData = new EditLearningPathwayDefaultsData(learningPathwayModel); controller.TempData.Set(learningPathwayData); var courseOptions = new List <(int, string)> { (1, "courseName") }; A.CallTo(() => courseService.GetCourseOptionsAlphabeticalListForCentre(A <int> ._, A <int> ._)) .Returns(courseOptions); A.CallTo( () => courseService.UpdateLearningPathwayDefaultsForCourse( A <int> ._, A <int> ._, A <int> ._, A <bool> ._, A <bool> ._, A <int> ._, A <int> ._, A <bool> ._ ) ).DoesNothing(); controller.ModelState.AddModelError("RefreshToCustomisationId", "Select a course"); // When var result = controller.EditAutoRefreshOptions(1, autoRefreshModel); // Then A.CallTo( () => courseService.UpdateLearningPathwayDefaultsForCourse( A <int> ._, A <int> ._, A <int> ._, A <bool> ._, A <bool> ._, A <int> ._, A <int> ._, A <bool> ._ ) ).MustNotHaveHappened(); result.Should().BeViewResult().ModelAs <EditAutoRefreshOptionsViewModel>(); controller.ModelState.IsValid.Should().BeFalse(); }
public void SaveAutoRefreshOptions_saves_if_number_input_is_null() { // Given var learningPathwayModel = new EditLearningPathwayDefaultsViewModel(1, "6", "12", false, false); var autoRefreshModel = GetEditAutoRefreshOptionsViewModel(autoRefreshMonths: null); var learningPathwayData = new EditLearningPathwayDefaultsData(learningPathwayModel); controller.TempData.Set(learningPathwayData); var courseOptions = new List <(int, string)> { (1, "courseName") }; A.CallTo(() => courseService.GetCourseOptionsAlphabeticalListForCentre(A <int> ._, A <int> ._)) .Returns(courseOptions); A.CallTo( () => courseService.UpdateLearningPathwayDefaultsForCourse( A <int> ._, A <int> ._, A <int> ._, A <bool> ._, A <bool> ._, A <int> ._, A <int> ._, A <bool> ._ ) ).DoesNothing(); // When var result = controller.EditAutoRefreshOptions(1, autoRefreshModel); // Then A.CallTo( () => courseService.UpdateLearningPathwayDefaultsForCourse( 1, 6, 12, false, false, 1, 0, true ) ).MustHaveHappened(); result.Should().BeRedirectToActionResult().WithActionName("Index"); }
public void AddAdminField_post_updates_temp_data_and_redirects() { // Given var initialEditViewModel = new EditLearningPathwayDefaultsViewModel(1, "0", "0", false, false); var initialTempData = new EditLearningPathwayDefaultsData(initialEditViewModel); var inputViewModel = new EditLearningPathwayDefaultsViewModel(1, "12", "3", true, true); controller.TempData.Set(initialTempData); // When var result = controller.EditLearningPathwayDefaults(1, inputViewModel); // Then using (new AssertionScope()) { controller.TempData.Peek <EditLearningPathwayDefaultsData>() !.LearningPathwayDefaultsModel.Should() .BeEquivalentTo(inputViewModel); result.Should().BeRedirectToActionResult().WithActionName("EditAutoRefreshOptions"); } }
private void SetEditLearningPathwayDefaultsTempData(EditLearningPathwayDefaultsViewModel model) { var data = new EditLearningPathwayDefaultsData(model); TempData.Set(data); }