public When_ProviderProximity_Controller_RefineSearchResults_Is_Called() { var locationService = Substitute.For <ILocationService>(); locationService.IsValidPostcodeAsync(Arg.Any <string>()).Returns((true, "CV1 2WT")); var opportunityProximityService = Substitute.For <IOpportunityProximityService>(); _routeService = Substitute.For <IRoutePathService>(); _routeService.GetRouteIdsAsync().Returns(new List <int> { 1, 2 }); var opportunityService = Substitute.For <IOpportunityService>(); var opportunityProximityController = new OpportunityProximityController(_routeService, opportunityProximityService, opportunityService, locationService); var viewModel = new SearchParametersViewModel { Postcode = "CV12WT", SelectedRouteId = 1, CompanyNameWithAka = "CompanyName (AlsoKnownAs)" }; _result = opportunityProximityController.RefineSearchResultsAsync(viewModel).GetAwaiter().GetResult(); }
public When_OpportunityProximity_Controller_RefineSearchResults_Is_Called_With_Invalid_Postcode() { const string requestPostcode = "CV1234"; var httpClient = new TestPostcodesIoHttpClient().Get(requestPostcode); var routes = new List <SelectListItem> { new SelectListItem { Text = "1", Value = "Route 1" } }; var locationService = new LocationService(new LocationApiClient(httpClient, new MatchingConfiguration { PostcodeRetrieverBaseUrl = "https://api.postcodes.io" })); var opportunityProximityService = new OpportunityProximityService(Substitute.For <ISearchProvider>(), locationService); var routePathService = Substitute.For <IRoutePathService>(); routePathService.GetRouteSelectListItemsAsync().Returns(routes); var opportunityService = Substitute.For <IOpportunityService>(); _opportunityProximityController = new OpportunityProximityController(routePathService, opportunityProximityService, opportunityService, locationService); var viewModel = new SearchParametersViewModel { Postcode = "CV1234", SelectedRouteId = 1 }; _result = _opportunityProximityController.RefineSearchResultsAsync(viewModel).GetAwaiter().GetResult(); }
public When_OpportunityProximity_Controller_RefineSearchResults_Is_Called_With_Unformatted_Postcode() { const string requestPostcode = "Cv 12 Wt"; var httpClient = new TestPostcodesIoHttpClient().Get(requestPostcode); var locationService = new LocationService(new LocationApiClient(httpClient, new MatchingConfiguration { PostcodeRetrieverBaseUrl = "https://api.postcodes.io" })); var opportunityProximityService = new OpportunityProximityService(Substitute.For <ISearchProvider>(), locationService); _routeService = Substitute.For <IRoutePathService>(); _routeService.GetRouteIdsAsync().Returns(new List <int> { 1, 2 }); var opportunityService = Substitute.For <IOpportunityService>(); var opportunityProximityController = new OpportunityProximityController(_routeService, opportunityProximityService, opportunityService, locationService); var viewModel = new SearchParametersViewModel { Postcode = requestPostcode, SelectedRouteId = 1 }; _result = opportunityProximityController.RefineSearchResultsAsync(viewModel).GetAwaiter().GetResult(); }
public When_OpportunityProximity_Controller_Index_Is_Loaded() { var proximityOpportunityService = Substitute.For <IOpportunityProximityService>(); var locationService = Substitute.For <ILocationService>(); var routeService = Substitute.For <IRoutePathService>(); _opportunityService = Substitute.For <IOpportunityService>(); var opportunityProximityController = new OpportunityProximityController(routeService, proximityOpportunityService, _opportunityService, locationService); _result = opportunityProximityController.Index().GetAwaiter().GetResult(); }
public When_OpportunityProximity_Controller_Results_Is_Loaded_With_No_Results_In_Selected_Route() { var providerSearchResultDto = new List <OpportunityProximitySearchResultViewModelItem>(); var providerSearchResultForOtherRoutesDto = new List <OpportunityProximitySearchResultByRouteViewModelItem> { new OpportunityProximitySearchResultByRouteViewModelItem { NumberOfResults = 1, RouteName = "another route" } }; var locationService = Substitute.For <ILocationService>(); locationService.IsValidPostcodeAsync(Arg.Any <string>()).Returns((true, Postcode)); var routeService = Substitute.For <IRoutePathService>(); routeService.GetRouteIdsAsync().Returns(new List <int> { 1, 2 }); _opportunityProximityService = Substitute.For <IOpportunityProximityService>(); _opportunityProximityService .SearchOpportunitiesByPostcodeProximityAsync( Arg.Is <OpportunityProximitySearchParametersDto>( a => a.Postcode == Postcode && a.SelectedRouteId == RouteId)) .Returns(providerSearchResultDto); _opportunityProximityService .SearchOpportunitiesForOtherRoutesByPostcodeProximityAsync( Arg.Is <OpportunityProximitySearchParametersDto>( a => a.Postcode == Postcode && a.SearchRadius == SearchParametersViewModel.ZeroResultsSearchRadius && a.SelectedRouteId == RouteId)) .Returns(providerSearchResultForOtherRoutesDto); _opportunityService = Substitute.For <IOpportunityService>(); var opportunityProximityController = new OpportunityProximityController(routeService, _opportunityProximityService, _opportunityService, locationService); _result = opportunityProximityController.GetOpportunityProviderResultsAsync(new SearchParametersViewModel { SelectedRouteId = RouteId, Postcode = Postcode }).GetAwaiter().GetResult(); }
public When_OpportunityProximity_Controller_Index_Is_Loaded_With_Opportunity() { var locationService = Substitute.For <ILocationService>(); var opportunityProximityService = Substitute.For <IOpportunityProximityService>(); var routeService = Substitute.For <IRoutePathService>(); _opportunityService = Substitute.For <IOpportunityService>(); _opportunityService .GetCompanyNameWithAkaAsync(1) .Returns("CompanyName (AlsoKnownAs)"); var opportunityProximityController = new OpportunityProximityController(routeService, opportunityProximityService, _opportunityService, locationService); _result = opportunityProximityController.Index(1).GetAwaiter().GetResult(); }
public When_OpportunityProximity_Controller_FindProviders_Is_Called_With_Invalid_Postcode() { const string requestPostcode = "cV12 34"; var httpClient = new TestPostcodesIoHttpClient().Get(requestPostcode); var routes = new List <SelectListItem> { new SelectListItem { Text = "1", Value = "Route 1" }, new SelectListItem { Text = "2", Value = "Route 2" } }; var config = new MapperConfiguration(c => c.AddMaps(typeof(SearchParametersViewModelMapper).Assembly)); IMapper mapper = new Mapper(config); var locationService = new LocationService( new LocationApiClient(httpClient, new MatchingConfiguration { PostcodeRetrieverBaseUrl = "https://api.postcodes.io" })); var opportunityProximityService = new OpportunityProximityService(Substitute.For <ISearchProvider>(), locationService); var routePathService = Substitute.For <IRoutePathService>(); routePathService.GetRouteSelectListItemsAsync().Returns(routes); var opportunityService = Substitute.For <IOpportunityService>(); _opportunityProximityController = new OpportunityProximityController(routePathService, opportunityProximityService, opportunityService, locationService); var selectedRouteId = routes.First().Text; const string postcode = requestPostcode; var viewModel = new SearchParametersViewModel { RoutesSelectList = mapper.Map <SelectListItem[]>(routes), SelectedRouteId = int.Parse(selectedRouteId), Postcode = postcode }; _result = _opportunityProximityController.FindProviders(viewModel).GetAwaiter().GetResult(); }
public When_OpportunityProximity_Controller_Results_Is_Loaded_With_No_Existing_Opportunity() { var providerSearchResultDto = new List <OpportunityProximitySearchResultViewModelItem> { new OpportunityProximitySearchResultViewModelItem { ProviderVenuePostcode = Postcode, Distance = 1.5d } }; var locationService = Substitute.For <ILocationService>(); locationService.IsValidPostcodeAsync(Arg.Any <string>()).Returns((true, Postcode)); var routeService = Substitute.For <IRoutePathService>(); routeService.GetRouteIdsAsync().Returns(new List <int> { 1, 2 }); _opportunityProximityService = Substitute.For <IOpportunityProximityService>(); _opportunityProximityService .SearchOpportunitiesByPostcodeProximityAsync(Arg.Is <OpportunityProximitySearchParametersDto>(a => a.Postcode == Postcode && a.SelectedRouteId == RouteId)) .Returns(providerSearchResultDto); _opportunityService = Substitute.For <IOpportunityService>(); var opportunityProximityController = new OpportunityProximityController(routeService, _opportunityProximityService, _opportunityService, locationService); _result = opportunityProximityController.GetOpportunityProviderResultsAsync(new SearchParametersViewModel { SelectedRouteId = RouteId, Postcode = Postcode }).GetAwaiter().GetResult(); }
public When_OpportunityProximity_Controller_FindProviders_Is_Called_For_Invalid_Postcode() { var locationService = Substitute.For <ILocationService>(); locationService.IsValidPostcodeAsync(Arg.Any <string>()).Returns((false, null)); var opportunityProximityService = Substitute.For <IOpportunityProximityService>(); _routeService = Substitute.For <IRoutePathService>(); _routeService.GetRouteIdsAsync().Returns(new List <int> { 1, 2 }); var opportunityService = Substitute.For <IOpportunityService>(); var opportunityProximityController = new OpportunityProximityController(_routeService, opportunityProximityService, opportunityService, locationService); const string postcode = "XYZ A12"; var viewModel = new SearchParametersViewModel { RoutesSelectList = new List <SelectListItem> { new SelectListItem { Text = "1", Value = "Route 1" }, new SelectListItem { Text = "2", Value = "Route 2" } }, SelectedRouteId = 1, Postcode = postcode }; _result = opportunityProximityController.FindProviders(viewModel).GetAwaiter().GetResult(); }
public When_OpportunityProximity_Controller_Results_Is_Loaded_With_Existing_Opportunity() { var providerSearchResultDto = new List <OpportunityProximitySearchResultViewModelItem> { new OpportunityProximitySearchResultViewModelItem { ProviderVenuePostcode = Postcode, Distance = 1.5d, ProviderVenueId = ProviderVenueId, ProviderVenueName = ProviderVenueDisplayName, ProviderDisplayName = ProviderDisplayName } }; var locationService = Substitute.For <ILocationService>(); locationService.IsValidPostcodeAsync(Arg.Any <string>()).Returns((true, Postcode)); var routeService = Substitute.For <IRoutePathService>(); routeService.GetRouteIdsAsync().Returns(new List <int> { 1, 2 }); _opportunityProximityService = Substitute.For <IOpportunityProximityService>(); _opportunityProximityService .SearchOpportunitiesByPostcodeProximityAsync(Arg.Is <OpportunityProximitySearchParametersDto>(a => a.Postcode == Postcode && a.SelectedRouteId == RouteId)) .Returns(providerSearchResultDto); _opportunityService = Substitute.For <IOpportunityService>(); _opportunityService.GetOpportunityItemAsync(OpportunityItemId) .Returns(new OpportunityItemDto { OpportunityId = OpportunityId, OpportunityItemId = OpportunityItemId, Postcode = Postcode, RouteId = RouteId }); _opportunityService.GetReferralsAsync(OpportunityItemId).Returns(new List <ReferralDto> { new ReferralDto { ProviderVenueId = ProviderVenueId, Name = "Referral" } }); _opportunityService .GetCompanyNameWithAkaAsync(OpportunityId) .Returns("CompanyName (AlsoKnownAs)"); var opportunityProximityController = new OpportunityProximityController(routeService, _opportunityProximityService, _opportunityService, locationService); _result = opportunityProximityController.GetOpportunityProviderResultsAsync(new SearchParametersViewModel { SelectedRouteId = RouteId, Postcode = Postcode, OpportunityId = OpportunityId, OpportunityItemId = OpportunityItemId }).GetAwaiter().GetResult(); }