Exemple #1
0
        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_FindProviders_Is_Called_With_Unformatted_Postcode()
        {
            const string requestPostcode = "cV12 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
            {
                RoutesSelectList = new List <SelectListItem>
                {
                    new SelectListItem {
                        Text = "1", Value = "Route 1"
                    },
                    new SelectListItem {
                        Text = "2", Value = "Route 2"
                    }
                },
                SelectedRouteId = 1,
                Postcode        = requestPostcode
            };

            _result = opportunityProximityController.FindProviders(viewModel).GetAwaiter().GetResult();
        }
Exemple #3
0
        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();
        }