public ActionResult Index(PsfModel model, PsfSearchResultsViewModel resultsViewModel) { CheckForBackState(model); // If the previous page is search page then, there will not be any sections in the passed PSFModel var previousPsfPage = model?.Section == null ? resultsViewModel?.PreSearchFiltersModel : model; if (previousPsfPage != null) { preSearchFilterStateManager.RestoreState(previousPsfPage.OptionsSelected); if (preSearchFilterStateManager.ShouldSaveState(ThisPageNumber, previousPsfPage.Section.PageNumber)) { var previousFilterSection = autoMapper.Map <PreSearchFilterSection>(previousPsfPage.Section); preSearchFilterStateManager.SaveState(previousFilterSection); } } var currentPageFilter = GetCurrentPageFilter(); if (ThisPageNumber > 1 && UsePageProfileCount) { var numberOfMatches = asyncHelper.Synchronise(() => GetNumberOfMatches(currentPageFilter)); currentPageFilter.NumberOfMatchesMessage = string.Format(NumberOfMatchesMessage, numberOfMatches); currentPageFilter.UsePageProfileCount = UsePageProfileCount; } return(View(currentPageFilter)); }
private PsfSearchResultsViewModel GetPsfSearchResultsViewModel(PsfModel model, bool notPaging) { preSearchFilterStateManager.RestoreState(model.OptionsSelected); if (notPaging) { if (model.Section.SingleSelectedValue != null) { model.Section.SingleSelectOnly = true; var optionSelec = model.Section.Options.FirstOrDefault(o => o.OptionKey == model.Section.SingleSelectedValue); if (optionSelec != null) { optionSelec.IsSelected = true; } } else { model.Section.SingleSelectOnly = false; } var psfilterSection = mapper.Map <PreSearchFilterSection>(model.Section); preSearchFilterStateManager.UpdateSectionState(psfilterSection); } var filterState = preSearchFilterStateManager.GetPreSearchFilterState(); model.Sections = mapper.Map <List <PsfSection> >(filterState.Sections); var resultModel = new PsfSearchResultsViewModel { MainPageTitle = MainPageTitle, SecondaryText = SecondaryText, OverviewMessage = OverviewMessage, PreSearchFiltersModel = new PsfModel { OptionsSelected = preSearchFilterStateManager.GetStateJson(), Section = new PsfSection { PageNumber = notPaging ? model.Section.PageNumber++ : model.Section.PageNumber } }, BackPageUrl = new Uri(BackPageUrl, UriKind.RelativeOrAbsolute), BackPageUrlText = BackPageUrlText, JobProfileCategoryPage = JobProfileCategoryPage, SalaryBlankText = SalaryBlankText, CaveatTagMarkup = CaveatTagMarkup, CaveatMarkup = CaveatMarkup }; //Need to do this to force the model we have changed to refresh ModelState.Clear(); return(resultModel); }
public ActionResult Index(PsfModel model, PsfSearchResultsViewModel resultsViewModel, int page = 1) { if (model?.Section != null) { return(Search(model, page)); } else { return(Search(resultsViewModel?.PreSearchFiltersModel, page, false)); } }
public void ShowMatchingProfileCountOnPageTest(int pageNumber, bool showMatchingProfileCount, bool expectingToShowCount) { //Setup the fakes and dummies for test SetUpFakesAndCalls(); SetUpStateMangerFakesAndCalls(PreSearchFilterType.Interest, true); var config = new MapperConfiguration(cfg => { cfg.AddProfile <JobProfilesAutoMapperProfile>(); }); var mapper = config.CreateMapper(); var searchResults = new SearchResult <JobProfileIndex>() { Count = 5 }; A.CallTo(() => fakeBuildSearchFilterService.BuildPreSearchFilters(A <PreSearchFiltersResultsModel> ._, A <Dictionary <string, PreSearchFilterLogicalOperator> > ._)).Returns(nameof(SearchProperties.FilterBy)); A.CallTo(() => fakeBuildSearchFilterService.GetIndexFieldDefinitions(A <string> .Ignored)).Returns(new List <KeyValuePair <string, PreSearchFilterLogicalOperator> >()); A.CallTo(() => fakeSearchQueryService.SearchAsync(A <string> ._, A <SearchProperties> ._)).Returns(searchResults); //Instantiate & Act var preSearchFiltersController = new PreSearchFiltersController(loggerFake, mapper, psfRepositoryFactoryFake, fakePsfStateManager, fakeSearchQueryService, fakeBuildSearchFilterService, fakeAsyncHelper, fakeTaxonomyRepository) { FilterType = PreSearchFilterType.Interest }; preSearchFiltersController.ThisPageNumber = pageNumber; preSearchFiltersController.UsePageProfileCount = showMatchingProfileCount; //Act on the index var firstVm = new PsfModel(); var resultsViewModel = new PsfSearchResultsViewModel { PreSearchFiltersModel = GeneratePreSEarchFiltersViewModel(PreSearchFilterType.Interest) }; var postFromResultsPageCall = preSearchFiltersController.WithCallTo(c => c.Index(firstVm, resultsViewModel)); postFromResultsPageCall.ShouldRenderDefaultView().WithModel <PsfModel>(vm => { vm.UsePageProfileCount.Should().Be(expectingToShowCount); }).AndNoModelErrors(); if (expectingToShowCount) { A.CallTo(() => fakeSearchQueryService.SearchAsync(A <string> ._, A <SearchProperties> ._)).MustHaveHappened(); } else { A.CallTo(() => fakeSearchQueryService.SearchAsync(A <string> ._, A <SearchProperties> ._)).MustNotHaveHappened(); } }
public void IndexWithPsfResultsTest() { //Setup the fakes and dummies for test SetUpFakesAndCalls(); SetUpStateMangerFakesAndCalls(PreSearchFilterType.Interest, true); var config = new MapperConfiguration(cfg => { cfg.AddProfile <JobProfilesAutoMapperProfile>(); }); var mapper = config.CreateMapper(); //Instantiate & Act var preSearchFiltersController = new PreSearchFiltersController(loggerFake, mapper, psfRepositoryFactoryFake, fakePsfStateManager) { FilterType = PreSearchFilterType.Interest }; //Act on the index var firstVm = new PsfModel(); var resultsViewModel = new PsfSearchResultsViewModel { PreSearchFiltersModel = GeneratePreSEarchFiltersViewModel(PreSearchFilterType.Interest) }; var postFromResultsPageCall = preSearchFiltersController.WithCallTo(c => c.Index(firstVm, resultsViewModel)); postFromResultsPageCall.ShouldRenderDefaultView().WithModel <PsfModel>(vm => { vm.Section.Should().NotBeNull(); }) .AndNoModelErrors(); A.CallTo(() => psfFakeIntrestRepository.GetAllFilters()).MustHaveHappened(); A.CallTo(() => psfFakeIntrestRepository.GetAllFilters()).MustHaveHappened(); A.CallTo(() => fakePsfStateManager.RestoreState(A <string> ._)).MustHaveHappened(); A.CallTo(() => fakePsfStateManager.ShouldSaveState(A <int> ._, A <int> ._)).MustHaveHappened(); A.CallTo(() => fakePsfStateManager.SaveState(A <PreSearchFilterSection> ._)).MustHaveHappened(); A.CallTo(() => fakePsfStateManager.GetSavedSection(A <string> ._, A <PreSearchFilterType> ._)).MustHaveHappened(); A.CallTo(() => fakePsfStateManager.RestoreOptions(A <PreSearchFilterSection> ._, A <IEnumerable <PreSearchFilter> > ._)).MustHaveHappened(); A.CallTo(() => fakePsfStateManager.GetStateJson()).MustHaveHappened(); }
public ActionResult Index(PsfModel model, PsfSearchResultsViewModel resultsViewModel) { // If the previous page is search page then, there will not be any sections in the passed PSFModel var previousPsfPage = model?.Section == null ? resultsViewModel?.PreSearchFiltersModel : model; if (previousPsfPage != null) { preSearchFilterStateManager.RestoreState(previousPsfPage.OptionsSelected); if (preSearchFilterStateManager.ShouldSaveState(ThisPageNumber, previousPsfPage.Section.PageNumber)) { var previousFilterSection = autoMapper.Map <PreSearchFilterSection>(previousPsfPage.Section); preSearchFilterStateManager.SaveState(previousFilterSection); } } var currentPageFilter = GetCurrentPageFilter(); return(View(currentPageFilter)); }