public void GetSavedSectionTest(PreSearchFilterType preSearchFilter, string sectionTitle) { // Assign var stateJson = "{\"Sections\":[]}"; var section = GetPreSearchFilterSection(preSearchFilter, sectionTitle); // Act var testObject = new PreSearchFilterStateManager(); testObject.RestoreState(stateJson); testObject.UpdateSectionState(section); var result = testObject.GetSavedSection(sectionTitle, preSearchFilter); // Assert result.Should().BeEquivalentTo(section); }
private static PreSearchFilterSection GetPreSearchFilterSection(PreSearchFilterType preSearchFilter, string sectionTitle) { var section = new PreSearchFilterSection { SectionDataType = preSearchFilter, Name = sectionTitle, Options = new List <PreSearchFilterOption> { new PreSearchFilterOption { Name = nameof(PreSearchFilterOption.Name), IsSelected = true, OptionKey = $"URL-{NumberDummyFilterOptions - 2}" } } }; return(section); }
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(); A.CallTo(() => fakePsfStateManager.GetPreSearchFilterState()).Returns(A.Dummy <PreSearchFilterState>()); }
private IEnumerable <PreSearchFilter> GetFilterOptions(PreSearchFilterType preSearchFilterType) { switch (preSearchFilterType) { case PreSearchFilterType.Enabler: { return(psfRepositoryFactoryFake.GetRepository <PsfEnabler>().GetAllFilters().OrderBy(o => o.Order)); } case PreSearchFilterType.EntryQualification: { return(psfRepositoryFactoryFake.GetRepository <PsfEntryQualification>().GetAllFilters().OrderBy(o => o.Order)); } case PreSearchFilterType.Interest: { return(psfRepositoryFactoryFake.GetRepository <PsfInterest>().GetAllFilters().OrderBy(o => o.Order)); } case PreSearchFilterType.TrainingRoute: { return(psfRepositoryFactoryFake.GetRepository <PsfTrainingRoute>().GetAllFilters().OrderBy(o => o.Order)); } case PreSearchFilterType.JobArea: { return(psfRepositoryFactoryFake.GetRepository <PsfJobArea>().GetAllFilters().OrderBy(o => o.Order)); } case PreSearchFilterType.CareerFocus: { return(psfRepositoryFactoryFake.GetRepository <PsfCareerFocus>().GetAllFilters().OrderBy(o => o.Order)); } case PreSearchFilterType.PreferredTaskType: { return(psfRepositoryFactoryFake.GetRepository <PsfPreferredTaskType>().GetAllFilters().OrderBy(o => o.Order)); } default: { return(Enumerable.Empty <PreSearchFilter>()); } } }
public void RestoreOptionsTest(PreSearchFilterType preSearchFilter, string sectionTitle) { // Assign var stateJson = "{\"Sections\":[]}"; var section = GetPreSearchFilterSection(preSearchFilter, sectionTitle); SetUpFakesAndCalls(false); // Act var testObject = new PreSearchFilterStateManager(); testObject.RestoreState(stateJson); testObject.UpdateSectionState(section); var result = testObject.RestoreOptions(section, GetFilterOptions(preSearchFilter)); // Assert result.Options.First(x => x.IsSelected).OptionKey.Should().BeEquivalentTo(section.Options.First().OptionKey); }
private PsfModel GeneratePreSEarchFiltersViewModel(PreSearchFilterType filterType) { var filtersModel = new PsfModel { OptionsSelected = "DummyJsonState" }; var filterSectionOne = new PsfSection { Name = "Multi Select Section One", Description = "Dummy Title One", SingleSelectOnly = false, NextPageUrl = "NextSectionURL", PreviousPageUrl = "HomePageURL", PageNumber = 1, TotalNumberOfPages = 2, SectionDataType = filterType.ToString() }; filterSectionOne.Options = new List <PsfOption>(); for (int ii = 0; ii < 3; ii++) { var iiString = ii.ToString(); filterSectionOne.Options.Add(item: new PsfOption { Id = iiString, IsSelected = false, Name = $"Title-{iiString}", Description = $"Description-{iiString}", OptionKey = $"{iiString}-UrlName", ClearOtherOptionsIfSelected = false }); } filtersModel.Section = filterSectionOne; return(filtersModel); }
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++; } }
public PreSearchFilterSection GetSavedSection(string sectionTitle, PreSearchFilterType filterType) { return(StateModel?.Sections? .FirstOrDefault(s => s.Name.Equals(sectionTitle, StringComparison.InvariantCultureIgnoreCase) && s.SectionDataType == filterType)); }