private PsfModel GetCurrentPageFilter() { var savedSection = preSearchFilterStateManager.GetSavedSection(SectionTitle, FilterType); var restoredSection = preSearchFilterStateManager.RestoreOptions(savedSection, GetFilterOptions()); //create the section for this page var currentSection = autoMapper.Map <PsfSection>(restoredSection); var filterSection = currentSection ?? new PsfSection(); filterSection.Name = SectionTitle; filterSection.Description = SectionDescription; filterSection.SingleSelectOnly = SingleSelectOnly; filterSection.NextPageUrl = NextPageUrl; filterSection.PreviousPageUrl = PreviousPageUrl; filterSection.PageNumber = ThisPageNumber; filterSection.TotalNumberOfPages = TotalNumberOfPages; filterSection.SectionDataType = FilterType.ToString(); var thisPageModel = new PsfModel { //Throw the state out again OptionsSelected = preSearchFilterStateManager.GetStateJson(), Section = filterSection, }; //Need to do this to force the model we have changed to refresh ModelState.Clear(); return(thisPageModel); }
public void IndexNoModelTest() { //Setup the fakes and dummies for test SetUpFakesAndCalls(); SetUpStateMangerFakesAndCalls(PreSearchFilterType.Interest, false); 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 indexResult = preSearchFiltersController.WithCallTo(c => c.Index()); PsfModel firstVm = null; //Assert indexResult.ShouldRenderDefaultView().WithModel <PsfModel>(vm => { CheckFilterSecton(preSearchFiltersController, vm.Section, PreSearchFilterType.Interest); firstVm = vm; }).AndNoModelErrors(); A.CallTo(() => psfFakeIntrestRepository.GetAllFilters()).MustHaveHappened(); A.CallTo(() => fakePsfStateManager.RestoreState(A <string> ._)).MustNotHaveHappened(); A.CallTo(() => fakePsfStateManager.ShouldSaveState(A <int> ._, A <int> ._)).MustNotHaveHappened(); A.CallTo(() => fakePsfStateManager.SaveState(A <PreSearchFilterSection> ._)).MustNotHaveHappened(); A.CallTo(() => fakePsfStateManager.GetSavedSection(A <string> ._, A <PreSearchFilterType> ._)).MustHaveHappened(); A.CallTo(() => fakePsfStateManager.RestoreOptions(A <PreSearchFilterSection> ._, A <IEnumerable <PreSearchFilter> > ._)).MustHaveHappened(); A.CallTo(() => fakePsfStateManager.GetStateJson()).MustHaveHappened(); }
private void SetUpStateMangerFakesAndCalls(PreSearchFilterType filterType, bool shouldSaveState, bool addNotApplicable = true) { var dummyStateSection = new PreSearchFilterSection { SectionDataType = filterType, Options = GetDummyPreSearchFilterOption(addNotApplicable) }; fakePsfStateManager = A.Fake <IPreSearchFilterStateManager>(ops => ops.Strict()); A.CallTo(() => fakePsfStateManager.GetSavedSection(A <string> ._, A <PreSearchFilterType> ._)).Returns(dummyStateSection); A.CallTo(() => fakePsfStateManager.RestoreOptions(A <PreSearchFilterSection> ._, A <IEnumerable <PreSearchFilter> > ._)).Returns(dummyStateSection); A.CallTo(() => fakePsfStateManager.GetStateJson()).Returns("DummyStateJson"); A.CallTo(() => fakePsfStateManager.ShouldSaveState(A <int> ._, A <int> ._)).Returns(shouldSaveState); A.CallTo(() => fakePsfStateManager.RestoreState(A <string> ._)).DoesNothing(); A.CallTo(() => fakePsfStateManager.SaveState(A <PreSearchFilterSection> ._)).DoesNothing(); }
private PsfModel GetCurrentPageFilter() { var savedSection = preSearchFilterStateManager.GetSavedSection(SectionTitle, FilterType); var restoredSection = preSearchFilterStateManager.RestoreOptions(savedSection, GetFilterOptions()); var groupedSections = restoredSection.Options.GroupBy(o => o.PSFCategory).OrderBy(g => g.Key); //create the section for this page var currentSection = autoMapper.Map <PsfSection>(restoredSection); var filterSection = currentSection ?? new PsfSection(); filterSection.Name = SectionTitle; filterSection.Description = SectionDescription; filterSection.SingleSelectOnly = SingleSelectOnly; filterSection.NextPageUrl = NextPageUrl; filterSection.PreviousPageUrl = PreviousPageUrl; filterSection.PageNumber = ThisPageNumber; filterSection.EnableAccordion = EnableAccordion; filterSection.GroupFieldsBy = GroupFieldsBy; filterSection.TotalNumberOfPages = TotalNumberOfPages; filterSection.SectionDataType = FilterType.ToString(); filterSection.SelectMessage = SelectMessage; var thisPageModel = new PsfModel { //Throw the state out again OptionsSelected = preSearchFilterStateManager.GetStateJson(), Section = filterSection, GroupedOptions = groupedSections, NumberOfMatchesMessage = NumberOfMatchesMessage, }; //Need to do this to force the model we have changed to refresh ModelState.Clear(); SetDefaultForCovidJobProfiles(thisPageModel, savedSection == null); return(thisPageModel); }