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));
        }
        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();
        }
        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));
        }