public IActionResult Index(int customisationId) { TempData.Clear(); var courseAdminFields = courseAdminFieldsService.GetCustomPromptsForCourse(customisationId); var model = new AdminFieldsViewModel(courseAdminFields.AdminFields, customisationId); return(View(model)); }
public void AdminFields_returns_AdminFields_page_when_appropriate_course_found_and_clears_TempData() { // Given var samplePrompt1 = CustomPromptsTestHelper.GetDefaultCustomPrompt(1, "System Access Granted", "Yes\r\nNo"); var customPrompts = new List <CustomPrompt> { samplePrompt1 }; A.CallTo(() => courseAdminFieldsService.GetCustomPromptsForCourse(A <int> ._)) .Returns(CustomPromptsTestHelper.GetDefaultCourseAdminFields(customPrompts)); controller.TempData.Set(samplePrompt1); // When var result = controller.Index(1); // Then controller.TempData.Peek <CustomPrompt>().Should().BeNull(); result.Should().BeViewResult().WithDefaultViewName().ModelAs <AdminFieldsViewModel>(); }
public void GetCustomPromptsForCourse_Returns_Populated_CourseAdminFields() { // Given var expectedPrompt1 = CustomPromptsTestHelper.GetDefaultCustomPrompt(1, "System Access Granted", "Test"); var expectedPrompt2 = CustomPromptsTestHelper.GetDefaultCustomPrompt(2, "Priority Access"); var customPrompts = new List <CustomPrompt> { expectedPrompt1, expectedPrompt2 }; var expectedCourseAdminFields = CustomPromptsTestHelper.GetDefaultCourseAdminFields(customPrompts); A.CallTo(() => courseAdminFieldsDataService.GetCourseAdminFields(100)) .Returns(CustomPromptsTestHelper.GetDefaultCourseAdminFieldsResult()); // When var result = courseAdminFieldsService.GetCustomPromptsForCourse(100); // Then result.Should().BeEquivalentTo(expectedCourseAdminFields); }