public async Task Step_Perform_Search_Returns_Expected_Results() { const string postcode = "MK35 8UK"; const int numberOfItems = 9; const int qualificationId = 5; const int selectedItemIndex = 3; var viewModel = new FindViewModel { Postcode = postcode, NumberOfItemsToShow = numberOfItems, SelectedQualificationId = qualificationId, SelectedItemIndex = selectedItemIndex }; var context = new SearchContext(viewModel); var providerLocations = new List <ProviderLocation> { new ProviderLocation(), new ProviderLocation(), new ProviderLocation(), new ProviderLocation(), new ProviderLocation() }; _providerSearchService.Search(Arg.Is <SearchRequest>(sr => sr.Postcode == postcode && sr.NumberOfItems == numberOfItems && sr.QualificationId == qualificationId)) .Returns((providerLocations.Count, providerLocations)); var providerLocationViewModels = new List <ProviderLocationViewModel> { new ProviderLocationViewModel(), new ProviderLocationViewModel(), new ProviderLocationViewModel(), new ProviderLocationViewModel(), new ProviderLocationViewModel() }; _mapper.Map <IEnumerable <ProviderLocationViewModel> >(Arg.Is(providerLocations)).Returns(providerLocationViewModels); await _searchStep.Execute(context); context.ViewModel.TotalRecordCount.Should().Be(providerLocationViewModels.Count); providerLocationViewModels[context.ViewModel.SelectedItemIndex].HasFocus.Should().BeTrue(); context.ViewModel.SearchedQualificationId.Should().Be(qualificationId); context.ViewModel.ProviderLocations.Should().Equal(providerLocationViewModels); await _providerSearchService.Received(1).Search(Arg.Is <SearchRequest>(sr => sr.Postcode == postcode && sr.NumberOfItems == numberOfItems && sr.QualificationId == qualificationId)); _mapper.Received(1).Map <IEnumerable <ProviderLocationViewModel> >(Arg.Is(providerLocations)); }
public async Task Search_Returns_Empty_Providers_And_TotalRecordCount() { _providerDataService.GetProviders().Returns(new List <Provider>().AsQueryable()); var(totalCount, searchResults) = await _service.Search(new SearchRequest()); totalCount.Should().Be(0); searchResults.Count().Should().Be(0); _providerDataService.Received(1).GetProviders(); _journeyService.DidNotReceive() .GetDirectionsLink(Arg.Any <string>(), Arg.Any <ProviderLocation>()); }
public async Task Execute(ISearchContext context) { var searchRequest = new SearchRequest { Postcode = context.ViewModel.Postcode, OriginLatitude = context.ViewModel.Latitude, OriginLongitude = context.ViewModel.Longitude, NumberOfItems = context.ViewModel.NumberOfItemsToShow ?? 0, QualificationId = context.ViewModel.SelectedQualificationId }; var(totalCount, searchResults) = await _providerSearchService.Search(searchRequest); var providerViewModels = _mapper.Map <IEnumerable <ProviderLocationViewModel> >(searchResults).ToList(); context.ViewModel.TotalRecordCount = totalCount; if (providerViewModels.Count > context.ViewModel.SelectedItemIndex) { providerViewModels[context.ViewModel.SelectedItemIndex].HasFocus = true; } context.ViewModel.ProviderLocations = providerViewModels; context.ViewModel.SearchedQualificationId = context.ViewModel.SelectedQualificationId ?? -1; }