public When_LocationService_Is_Called_To_Validate_An_Invalid_Postcode() { var locationService = new LocationApiClient(new HttpClient(), new MatchingConfiguration { PostcodeRetrieverBaseUrl = "https://api.postcodes.io/postcodes" }); _result = locationService.IsValidPostcodeAsync("CV1234").GetAwaiter().GetResult(); }
public When_LocationService_Is_Called_To_GetProximity_Data_For_Valid_Postcode() { var httpClient = new TestPostcodesIoHttpClient().Get(); var locationService = new LocationApiClient(httpClient, new MatchingConfiguration { PostcodeRetrieverBaseUrl = "https://api.postcodes.io/" }); _postcodeLookupResultDto = locationService.GetGeoLocationDataAsync("CV1 2WT").GetAwaiter().GetResult(); }
public When_LocationService_Is_Called_To_Validate_A_Terminated_Postcode() { const string requestPostcode = "S70 2YW"; var httpClient = new TestPostcodesIoHttpClient().Get(requestPostcode); var locationService = new LocationApiClient(httpClient, new MatchingConfiguration { PostcodeRetrieverBaseUrl = "https://api.postcodes.io/" }); _postcodeResultDto = locationService.IsTerminatedPostcodeAsync(requestPostcode).GetAwaiter().GetResult(); }
public async Task Then_Postcode_Is_Returned_Correctly() { var httpClient = IntializeHttpClient(GoodPostcode); var locationApiClient = new LocationApiClient(httpClient); var postcodeData = await locationApiClient.GetGeoLocationDataAsync(GoodPostcode); postcodeData.Should().NotBeNull(); postcodeData.Postcode.Should().Be(GoodPostcode); postcodeData.Latitude.Should().Be(52.400997); postcodeData.Longitude.Should().Be(-1.508122); }
public async Task Then_Outcode_Is_Returned_Correctly() { var httpClient = IntializeOutcodeHttpClient(Outcode); var locationApiClient = new LocationApiClient(httpClient); var postcodeData = await locationApiClient .GetGeoLocationDataAsync(Outcode); postcodeData.Should().NotBeNull(); postcodeData.Postcode.Should().Be(Outcode); postcodeData.Latitude.Should().Be(52.5198364972316); postcodeData.Longitude.Should().Be(-1.45313659025471); }
public async Task Then_Terminated_Postcode_Is_Returned_Correctly() { var httpClient = IntializeTerminatedHttpClient(TerminatedPostcode); var locationApiClient = new LocationApiClient(httpClient); var postcodeData = await locationApiClient .GetGeoLocationDataAsync(TerminatedPostcode); postcodeData.Should().NotBeNull(); postcodeData.Postcode.Should().Be(TerminatedPostcode); postcodeData.Latitude.Should().Be(53.551618); postcodeData.Longitude.Should().Be(-1.482797); }
public static ILocationRepository GetLocationRepository(AuthenticationToken authToken) { if (authToken == null) { throw new ArgumentNullException(nameof(authToken)); } EnforceInitialization(); var urlBuilderFactory = new LocationsUrlBuilderFactory(ApiKey, _signatureGenerator); var urlFactory = new LocationsUrlFactory(urlBuilderFactory); var responseParser = new Http.Api.Locations.ResponseParser(); var locationApiClient = new LocationApiClient(urlFactory, ApiClient, authToken, responseParser); var locationCache = new InMemoryLocationCache(); return(new LocationRepository(locationApiClient, locationCache)); }
public When_LocationApiClient_Is_Called_To_GetGeoLocationData() { var responseData = new PostcodeLookupResultDto { Postcode = "CV1 2WT", Latitude = "50.001", Longitude = "-1.234" }; var httpClient = new PostcodesTestHttpClientFactory() .Get("CV1 2WT", responseData); _locationApiClient = new LocationApiClient(httpClient, new MatchingConfiguration { PostcodeRetrieverBaseUrl = "https://example.com/" }); }
public async Task Then_Postcode_Is_Returned_Correctly() { // Arrange var responseData = new PostcodeLookupResultDto { Postcode = "CV1 2WT", Latitude = 50.001, Longitude = -1.234 }; var httpClient = IntializeHttpClient("CV1 2WT", responseData); var locationApiClient = new LocationApiClient(httpClient, _configurationOptions); // Act var postcodeData = await locationApiClient.GetGeoLocationDataAsync("CV12WT"); // Assert postcodeData.Should().NotBeNull(); postcodeData.Postcode.Should().Be("CV1 2WT"); postcodeData.Latitude.Should().Be(50.001); postcodeData.Longitude.Should().Be(-1.234); }
private static async Task LookupPostcodes(string path) { var postcodes = await GetPostcodesFromCsv(path); var locations = new List <Location>(); var locationClient = new LocationApiClient(new HttpClient(), Configuration); foreach (var postcode in postcodes) { try { var location = await locationClient.GetGeoLocationData(postcode); Console.WriteLine($"{location.Postcode} - {location.Latitude}, {location.Longitude}"); locations.Add(location); } catch (Exception ex) { Console.WriteLine($"Lookup of {postcode} failed - {ex.Message}"); try { var location = await locationClient.GetTerminatedPostcodeGeoLocationData(postcode); Console.WriteLine($"Terminated - {location.Postcode} - {location.Latitude}, {location.Longitude}. Terminated {location.TerminatedMonth}-{location.TerminatedYear}"); locations.Add(location); } catch (Exception e2) { Console.WriteLine($"Lookup of terminated {postcode} failed - {e2.Message}"); } } } await WriteToCsv(locations, @".\Data\locations_from_postcodes.csv"); }