public void IndexRepositoryTest(PreSearchFilterType filterType)
        {
            //Setup the fakes and dummies
            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 = filterType
            };

            //Act on the index
            var indexResult = preSearchFiltersController.WithCallTo(c => c.Index());

            //Assert
            indexResult.ShouldRenderDefaultView().WithModel <PsfModel>(vm =>
            {
                vm.Section.Should().NotBeNull();
                CheckFilterSecton(preSearchFiltersController, vm.Section, filterType);
            }).AndNoModelErrors();
        }
        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 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();
        }
        public void BackOptionSelectedStateIsUsedIfSet()
        {
            //Setup the fakes and dummies for test
            SetUpFakesAndCalls();
            SetUpStateMangerFakesAndCalls(PreSearchFilterType.JobArea, false);

            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <JobProfilesAutoMapperProfile>();
            });
            var mapper = config.CreateMapper();

            var firstVm = new PsfModel()
            {
                Back = new PsfBack()
                {
                    OptionsSelected = "DummyOptionsSelectd"
                }
            };

            A.CallTo(() => fakePsfStateManager.GetStateJson()).Returns(firstVm.OptionsSelected);

            //Instantiate & Act
            var preSearchFiltersController = new PreSearchFiltersController(loggerFake, mapper, psfRepositoryFactoryFake, fakePsfStateManager, fakeSearchQueryService, fakeBuildSearchFilterService, fakeAsyncHelper, fakeTaxonomyRepository)
            {
                FilterType = PreSearchFilterType.Interest
            };

            //Act on the index
            var postFromResultsPageCall = preSearchFiltersController.WithCallTo(c => c.Index(firstVm, null));

            postFromResultsPageCall.ShouldRenderDefaultView().WithModel <PsfModel>(vm =>
            {
                vm.Section.Should().NotBeNull();
                vm.Section.SectionDataType.Should().Be(PreSearchFilterType.Interest.ToString());
            })
            .AndNoModelErrors();
        }
        private void CheckFilterSecton(PreSearchFiltersController controller, PsfSection filterSection, PreSearchFilterType expectedFilterType, bool addNotApplicable = true)
        {
            filterSection.Description.Should().BeEquivalentTo(controller.SectionDescription);
            filterSection.Name.Should().BeEquivalentTo(controller.SectionTitle);
            filterSection.NextPageUrl.Should().BeEquivalentTo(controller.NextPageUrl);
            filterSection.PreviousPageUrl.Should().BeEquivalentTo(controller.PreviousPageUrl);
            filterSection.SectionDataType.Should().BeEquivalentTo(expectedFilterType.ToString());
            filterSection.PageNumber.Should().Be(controller.ThisPageNumber);
            filterSection.TotalNumberOfPages.Should().Be(controller.TotalNumberOfPages);
            filterSection.Options.Count.Should().Be(5);

            int idx = 0;

            foreach (PreSearchFilterOption p in GetDummyPreSearchFilterOption(addNotApplicable))
            {
                filterSection.Options[idx].Id.Should().BeEquivalentTo(p.Id);
                filterSection.Options[idx].Name.Should().BeEquivalentTo(p.Name);
                filterSection.Options[idx].Description.Should().BeEquivalentTo(p.Description);
                filterSection.Options[idx].IsSelected.Should().Be(false);
                filterSection.Options[idx].ClearOtherOptionsIfSelected.Should().Be(p.ClearOtherOptionsIfSelected);
                filterSection.Options[idx].OptionKey.Should().BeEquivalentTo(p.OptionKey);
                idx++;
            }
        }