public void Setup() { _fatSearchItemMapperMock = new Mock <IApprenticeshipItemViewModelMapper>(MockBehavior.Strict); _fatSearchItemMapperMock.Setup(s => s.Map(It.IsAny <ApprenticeshipSearchResultsItem>())).Returns(new ApprenticeshipItemViewModel() { Title = "Apprenticeship" }); _sut = new FatSearchResultsViewModelMapper(_fatSearchItemMapperMock.Object); _cssClassMock = new Mock <ICssViewModel>(); _itemToMap = new ApprenticeshipSearchResults() { ActualPage = 1, LastPage = 20, SearchTerm = "Apprenticeship", ResultsToTake = 20, TotalResults = 400, SortOrder = "1", Results = new List <ApprenticeshipSearchResultsItem>() { new ApprenticeshipSearchResultsItem() { Title = "apprenticeship" }, new ApprenticeshipSearchResultsItem() { Title = "apprenticeship" } } }; }
public void Setup() { _sut = new FatSearchFilterViewModelMapper(); _resultsItemToMap = new ApprenticeshipSearchResults() { ActualPage = 1, LastPage = 20, SearchTerm = "Apprenticeship", ResultsToTake = 20, TotalResults = 400, SortOrder = "1", Results = new List <ApprenticeshipSearchResultsItem>() { new ApprenticeshipSearchResultsItem() { Title = "apprenticeship" }, new ApprenticeshipSearchResultsItem() { Title = "apprenticeship" } }, LevelAggregation = new Dictionary <int, long?>() { { 3, 20 }, { 4, 10 }, { 5, 40 } }, SelectedLevels = new List <int>() { 4, 5 } }; _queryItemToMap = new SearchQueryViewModel() { Keywords = "Apprenticeship", Page = 1, ResultsToTake = 20, SortOrder = 1, SelectedLevels = new List <int>() { 4, 5 } }; }
public void ShouldReturnSearchValues() { var searchResults = new ApprenticeshipSearchResults { LastPage = 3, TotalResults = 10, Results = new List <ApprenticeshipSearchResultsItem> { new ApprenticeshipSearchResultsItem() }, ActualPage = 2, LevelAggregation = new Dictionary <int, long?> { { 1, 2 } }, HasError = false, ResultsToTake = 4, SortOrder = "5", SearchTerm = "test term", SelectedLevels = new[] { 1, 2 } }; _mockApprenticeshipSearchService.Setup(x => x.SearchByKeyword( It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <List <int> >())) .ReturnsAsync(searchResults); var query = new ApprenticeshipSearchQuery { Keywords = "Test term", Order = 2 }; var response = _sut.Handle(query, _cancellationToken).Result; response.LastPage.Should().Be(searchResults.LastPage); response.TotalResults.Should().Be(searchResults.TotalResults); response.Results.Should().BeEquivalentTo(searchResults.Results); response.ActualPage.Should().Be(query.Page); response.AggregationLevel.ShouldBeEquivalentTo(searchResults.LevelAggregation); response.HasError.Should().Be(searchResults.HasError); response.ResultsToTake.Should().Be(searchResults.ResultsToTake); response.SelectedLevels.ShouldBeEquivalentTo(searchResults.SelectedLevels); response.SearchTerm.Should().Be(query.Keywords); response.SortOrder.Should().Be(query.Order.ToString()); }
public FatSearchFilterViewModel Map(ApprenticeshipSearchResults source, SearchQueryViewModel searchQueryModel) { var item = new FatSearchFilterViewModel(); foreach (var level in source.LevelAggregation) { var isChecked = searchQueryModel.SelectedLevels.Contains(level.Key); item.LevelsAggregate.Add(new LevelAggregationViewModel() { Checked = isChecked, Count = level.Value ?? level.Value.Value, Value = level.Key.ToString() }); } return(item); }
public FatSearchResultsViewModel Map(ApprenticeshipSearchResults source) { var item = new FatSearchResultsViewModel() { SearchResults = source.Results?.Select(s => _apprenticeshipItemViewModelMapper.Map(s)), TotalResults = source.TotalResults, LastPage = source.LastPage, SearchQuery = { Page = source.ActualPage, ResultsToTake = source.ResultsToTake, SortOrder = !string.IsNullOrWhiteSpace(source.SortOrder) ? int.Parse(source.SortOrder) : 0, Keywords = source.SearchTerm, SelectedLevels = source.SelectedLevels?.ToList() } }; return(item); }
public void Setup() { mappingReturnObject = new ApprenticeshipSearchResults() { Results = new List <ApplicationServices.Models.ApprenticeshipSearchResultsItem>() }; clientResultsItems = new SFADASApprenticeshipsApiTypesV3ApprenticeshipSearchResults() { Results = new List <SFADASApprenticeshipsApiTypesV3ApprenticeshipSearchResultsItem>() { new SFADASApprenticeshipsApiTypesV3ApprenticeshipSearchResultsItem() { Id = "123" }, new SFADASApprenticeshipsApiTypesV3ApprenticeshipSearchResultsItem() { Id = "234" }, new SFADASApprenticeshipsApiTypesV3ApprenticeshipSearchResultsItem() { Id = "ABC-12-34" } } }; _apprenticeshipProgrammeApiClientMock = new Mock <ISearchV3Api>(); _apprenticeshipSearchResultsMappingMock = new Mock <IApprenticeshipSearchResultsMapping>(); _apprenticeshipProgrammeApiClientMock .Setup(s => s.SearchActiveApprenticeshipsAsync(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())) .ReturnsAsync(clientResultsItems); _apprenticeshipSearchResultsMappingMock .Setup(s => s.Map(It.IsAny <SFADASApprenticeshipsApiTypesV3ApprenticeshipSearchResults>())) .Returns(mappingReturnObject); _sut = new ApprenticeshipsSearchApiProvider(_apprenticeshipProgrammeApiClientMock.Object, _apprenticeshipSearchResultsMappingMock.Object); }
public ApprenticeshipSearchResults Map(SFADASApprenticeshipsApiTypesV3ApprenticeshipSearchResults document) { var apprenticeshipSearchResults = new ApprenticeshipSearchResults(); if (document != null) { apprenticeshipSearchResults.ActualPage = document.PageNumber; apprenticeshipSearchResults.LevelAggregation = document.LevelAggregation?.ToDictionary(s => int.Parse(s.Key), s => s.Value as long?); apprenticeshipSearchResults.TotalResults = document.TotalResults; apprenticeshipSearchResults.ResultsToTake = document.PageSize; apprenticeshipSearchResults.LastPage = document.PageSize > 0 ? (int)System.Math.Ceiling((double)document.TotalResults / document.PageSize) : 0; if (document.Results.Any()) { apprenticeshipSearchResults.Results = document.Results.Select(_apprenticeshipSearchResultsItemMapping.Map); } return(apprenticeshipSearchResults); } return(null); }