コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        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);
        }