public List <EditDelegateRegistrationPromptViewModel> GetEditDelegateRegistrationPromptViewModelsForCentre( int centreId, string?answer1, string?answer2, string?answer3, string?answer4, string?answer5, string?answer6 ) { var answers = new List <string?> { answer1, answer2, answer3, answer4, answer5, answer6 }; var centreRegistrationPrompts = centreRegistrationPromptsService.GetCentreRegistrationPromptsByCentreId(centreId); return(centreRegistrationPrompts.CustomPrompts.Select( cp => new EditDelegateRegistrationPromptViewModel( cp.RegistrationField.Id, cp.PromptText, cp.Mandatory, cp.Options, answers[cp.RegistrationField.Id - 1] ) ).ToList()); }
public void GetCentreRegistrationPromptsByCentreId_Returns_Populated_CentreRegistrationPrompts() { // Given var expectedPrompt1 = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(1, options: null, mandatory: true, promptId: 3); var expectedPrompt2 = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(2, "Department / team", null, true); var centreRegistrationPrompts = new List <CentreRegistrationPrompt> { expectedPrompt1, expectedPrompt2 }; var expectedPrompts = PromptsTestHelper.GetDefaultCentreRegistrationPrompts(centreRegistrationPrompts); A.CallTo(() => centreRegistrationPromptsDataService.GetCentreRegistrationPromptsByCentreId(29)) .Returns ( PromptsTestHelper.GetDefaultCentreRegistrationPromptsResult( centreRegistrationPrompt1Prompt: "Custom Prompt", centreRegistrationPrompt1Options: null ) ); // When var result = centreRegistrationPromptsService.GetCentreRegistrationPromptsByCentreId(29); // Then result.Should().BeEquivalentTo(expectedPrompts); }
public IActionResult Index() { TempData.Clear(); var centreId = User.GetCentreId(); var customPrompts = centreRegistrationPromptsService.GetCentreRegistrationPromptsByCentreId(centreId) .CustomPrompts; var model = new DisplayPromptsViewModel(customPrompts); return(View(model)); }
private void PopulateCourseDelegatesSheetForCourse( IXLWorkbook workbook, int customisationId, int centreId, string?sortBy, string?filterString, string sortDirection ) { var adminFields = courseAdminFieldsService.GetCourseAdminFieldsForCourse(customisationId); var customRegistrationPrompts = registrationPromptsService.GetCentreRegistrationPromptsByCentreId(centreId); var courseDelegates = courseDataService.GetDelegatesOnCourseForExport(customisationId, centreId) .ToList(); var filteredCourseDelegates = FilteringHelper.FilterItems(courseDelegates.AsQueryable(), filterString).ToList(); var sortedCourseDelegates = GenericSortingHelper.SortAllItems( filteredCourseDelegates.AsQueryable(), sortBy ?? nameof(CourseDelegateForExport.FullNameForSearchingSorting), sortDirection ); var dataTable = new DataTable(); SetUpDataTableColumns(customRegistrationPrompts, adminFields, dataTable); foreach (var courseDelegate in sortedCourseDelegates) { AddDelegateToDataTable(dataTable, courseDelegate, customRegistrationPrompts, adminFields); } if (dataTable.Rows.Count == 0) { var row = dataTable.NewRow(); dataTable.Rows.Add(row); } ClosedXmlHelper.AddSheetToWorkbook( workbook, $"Course {customisationId}", dataTable.AsEnumerable(), XLTableTheme.None ); FormatWorksheetColumns(workbook, dataTable); }
public void Index_calls_expected_methods_and_returns_view() { // When var result = emailDelegatesController.Index(); // Then using (new AssertionScope()) { A.CallTo(() => userService.GetDelegateUserCardsForWelcomeEmail(A <int> ._)).MustHaveHappened(); A.CallTo(() => centreRegistrationPromptsService.GetCentreRegistrationPromptsByCentreId(A <int> ._)) .MustHaveHappened(); A.CallTo( () => searchSortFilterPaginateService.SearchFilterSortAndPaginate( A <IEnumerable <DelegateUserCard> > ._, A <SearchSortFilterAndPaginateOptions> ._ ) ).MustHaveHappened(); A.CallTo( () => httpResponse.Cookies.Append( CookieName, A <string> ._, A <CookieOptions> ._ ) ) .MustHaveHappened(); result.Should().BeViewResult().WithDefaultViewName(); } }
public void GetAllDelegatesFileForCentre_returns_expected_excel_data() { // TODO: HEEDLS-810 - run the formatter once review complete. // Given const int centreId = 2; var centreRegistrationPrompts = new List <CentreRegistrationPrompt> { new CentreRegistrationPrompt(RegistrationField.CentreRegistrationField1, 1, "Role type", null, true), new CentreRegistrationPrompt(RegistrationField.CentreRegistrationField2, 2, "Manager", null, true), new CentreRegistrationPrompt(RegistrationField.CentreRegistrationField3, 3, "Base / office / place of work", null, true), new CentreRegistrationPrompt(RegistrationField.CentreRegistrationField4, 4, "Base / office / place of work", null, true), new CentreRegistrationPrompt(RegistrationField.CentreRegistrationField5, 5, "Contact telephone number", null, true), }; A.CallTo(() => centreRegistrationPromptsService.GetCentreRegistrationPromptsByCentreId(centreId)) .Returns(new CentreRegistrationPrompts(centreId, centreRegistrationPrompts)); A.CallTo(() => userDataService.GetDelegateUserCardsByCentreId(2)).Returns(delegateUserCards); // When var resultBytes = delegateDownloadFileService.GetAllDelegatesFileForCentre(2, null, null, GenericSortingHelper.Ascending, null); using var resultsStream = new MemoryStream(resultBytes); using var resultWorkbook = new XLWorkbook(resultsStream); // Then using var expectedWorkbook = new XLWorkbook( TestContext.CurrentContext.TestDirectory + TestAllDelegatesExportRelativeFilePath ); SpreadsheetTestHelper.AssertSpreadsheetsAreEquivalent(expectedWorkbook, resultWorkbook); }
public void GetDelegateDownloadFileForCourse_returns_expected_excel_data() { // Given const int customisationId = 1; const int centreId = 1; using var expectedWorkbook = new XLWorkbook( TestContext.CurrentContext.TestDirectory + CourseDelegateExportCurrentDataDownloadRelativeFilePath ); A.CallTo(() => courseDataService.GetDelegatesOnCourseForExport(customisationId, centreId)) .Returns(courseDelegates.Where(c => c.ApplicationName == "Course One")); var centreRegistrationPrompts = new List <CentreRegistrationPrompt> { new CentreRegistrationPrompt(1, 1, "Role type", null, true), new CentreRegistrationPrompt(2, 2, "Manager", null, true), new CentreRegistrationPrompt(3, 3, "Base / office / place of work", null, true), new CentreRegistrationPrompt(4, 4, "Base / office / place of work", null, true), new CentreRegistrationPrompt(5, 5, "Contact telephone number", null, true), }; A.CallTo(() => registrationPromptsService.GetCentreRegistrationPromptsByCentreId(centreId)) .Returns(new CentreRegistrationPrompts(centreId, centreRegistrationPrompts)); var adminFields = new List <CourseAdminField> { new CourseAdminField(1, "Access Permissions", null), }; A.CallTo(() => courseAdminFieldsService.GetCourseAdminFieldsForCourse(customisationId)) .Returns(new CourseAdminFields(customisationId, adminFields)); // When var resultBytes = courseDelegatesDownloadFileService.GetCourseDelegateDownloadFileForCourse( customisationId, centreId, null, null ); using var resultsStream = new MemoryStream(resultBytes); using var resultWorkbook = new XLWorkbook(resultsStream); // Then SpreadsheetTestHelper.AssertSpreadsheetsAreEquivalent(expectedWorkbook, resultWorkbook); }
public void EditDetailsPostSave_with_missing_delegate_answers_fails_validation() { // Given var myAccountController = new MyAccountController( centreRegistrationPromptsService, userService, imageResizeService, jobGroupsDataService, promptsService ).WithDefaultContext().WithMockUser(true, adminId: null); var customPromptLists = new List <CentreRegistrationPrompt> { PromptsTestHelper.GetDefaultCentreRegistrationPrompt(1, mandatory: true) }; A.CallTo (() => centreRegistrationPromptsService.GetCentreRegistrationPromptsByCentreId(2)).Returns( PromptsTestHelper.GetDefaultCentreRegistrationPrompts(customPromptLists, 2) ); var formData = new MyAccountEditDetailsFormData(); var expectedPrompt = new EditDelegateRegistrationPromptViewModel(1, "Custom Prompt", true, new List <string>(), null); var expectedModel = new MyAccountEditDetailsViewModel( formData, new List <(int id, string name)>(), new List <EditDelegateRegistrationPromptViewModel> { expectedPrompt }, DlsSubApplication.Default ); // When var result = myAccountController.EditDetails(formData, "save", DlsSubApplication.Default); // Then A.CallTo(() => userService.NewEmailAddressIsValid(A <string> ._, A <int?> ._, A <int?> ._, A <int> ._)) .MustNotHaveHappened(); result.As <ViewResult>().Model.As <MyAccountEditDetailsViewModel>().Should().BeEquivalentTo(expectedModel); myAccountController.ModelState[nameof(MyAccountEditDetailsFormData.Answer1)].ValidationState.Should().Be (ModelValidationState.Invalid); }
private void PopulateAllDelegatesSheet( IXLWorkbook workbook, int centreId, string?searchString, string?sortBy, string sortDirection, string?filterString ) { var registrationPrompts = centreRegistrationPromptsService.GetCentreRegistrationPromptsByCentreId(centreId); var delegatesToExport = GetDelegatesToExport(centreId, searchString, sortBy, sortDirection, filterString) .ToList(); var dataTable = new DataTable(); SetUpDataTableColumnsForAllDelegates(registrationPrompts, dataTable); foreach (var delegateRecord in delegatesToExport) { SetDelegateRowValues(dataTable, delegateRecord, registrationPrompts); } if (dataTable.Rows.Count == 0) { var row = dataTable.NewRow(); dataTable.Rows.Add(row); } ClosedXmlHelper.AddSheetToWorkbook( workbook, AllDelegatesSheetName, dataTable.AsEnumerable(), XLTableTheme.None ); FormatAllDelegateWorksheetColumns(workbook, dataTable); }
public void GetEditDelegateRegistrationPromptViewModelsForCentre_returns_populated_list() { // Given var registrationPrompt1 = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(1, options: "Clinical\r\nNon-Clinical"); var registrationPrompt2 = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(2); var centreRegistrationPrompts = PromptsTestHelper.GetDefaultCentreRegistrationPrompts( new List <CentreRegistrationPrompt> { registrationPrompt1, registrationPrompt2 }, 1 ); A.CallTo(() => centreRegistrationPromptsService.GetCentreRegistrationPromptsByCentreId(1)) .Returns(centreRegistrationPrompts); // When var result = promptsService.GetEditDelegateRegistrationPromptViewModelsForCentre( 1, Answer1, Answer2, null, null, null, null ); // Then using (new AssertionScope()) { result.Count.Should().Be(2); result[0].PromptNumber.Should().Be(1); result[0].Options.Count().Should().Be(2); result[0].Options.First().Value.Should().BeEquivalentTo("Clinical"); result[1].PromptNumber.Should().Be(2); result[1].Options.Count().Should().Be(0); } }
private IEnumerable <CentreRegistrationPrompt> GetRegistrationPromptsWithSetOptions(int centreId) { return(centreRegistrationPromptsService.GetCentreRegistrationPromptsByCentreId(centreId).CustomPrompts .Where(cp => cp.Options.Any())); }