public async Task CalculateProviderLocationDistanceInMiles_Calculate_Distance_In_Miles_From_StudentPostcode_To_ProviderLocation_Using_LocationApi( string studentPostcode, double studentLat, double studentLon, double providerLat, double providerLon, int expectedMileageInMilesAfterRounding) { var postcodeLookupResultDto = new PostcodeLookupResultDto { Postcode = studentPostcode, Latitude = studentLat, Longitude = studentLon }; _locationApiClient.GetGeoLocationDataAsync(studentPostcode).Returns(postcodeLookupResultDto); var providerLocation = new ProviderLocation { Latitude = providerLat, Longitude = providerLon }; var providerLocations = new List <ProviderLocation> { providerLocation }; await _distanceCalculationService.CalculateProviderLocationDistanceInMiles(new PostcodeLocation { Postcode = studentPostcode }, providerLocations.AsQueryable()); var roundedDistanceInMiles = (int)Math.Round(providerLocation.DistanceInMiles, MidpointRounding.AwayFromZero); roundedDistanceInMiles.Should().Be(expectedMileageInMilesAfterRounding); await _locationApiClient.Received(1).GetGeoLocationDataAsync(studentPostcode); }
public HttpClient Get(string requestPostcode, PostcodeLookupResultDto responseData) { var response = new PostcodeLookupResponse { Result = responseData, Status = "OK" }; return(CreateClient(response, $"https://example.com/postcodes/{requestPostcode.Replace(" ", "")}")); }
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_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 HttpClient IntializeTerminatedHttpClient(string requestPostcode, PostcodeLookupResultDto responseData) { var response = new PostcodeLookupResponse { Result = responseData, Status = 200 }; return(CreateClient(response, $"https://example.com/terminated_postcodes/{requestPostcode.Replace(" ", "")}")); }