public async Task Then_If_There_Is_A_Postcode_And_Include_District_Name_Is_Included_Option_Then_It_Is_Returned_As_Display_Name( GetLocationsListItem apiLocationResponse, [Frozen] Mock <ILocationApiClient <LocationApiConfiguration> > mockLocationApiClient, LocationLookupService service) { var postcode = "CV1 1AA"; var location = $"{postcode}, {apiLocationResponse.DistrictName}"; var lat = 0; var lon = 0; apiLocationResponse.Postcode = postcode; apiLocationResponse.Outcode = ""; mockLocationApiClient .Setup(client => client.Get <GetLocationsListItem>( It.Is <GetLocationByFullPostcodeRequest>(c => c.GetUrl.Contains(postcode.Split().FirstOrDefault()) && c.GetUrl.Contains(postcode.Split().LastOrDefault())))) .ReturnsAsync(apiLocationResponse); var result = await service.GetLocationInformation(postcode, lat, lon, true); result.Name.Should().Be(location); result.GeoPoint.Should().BeEquivalentTo(apiLocationResponse.Location.GeoPoint); result.Country.Should().Be(apiLocationResponse.Country); }
public async Task Then_If_There_Is_A_Partial_Location_Name_Then_This_Is_Searched_And_Matched_On_The_First_Result( string location, GetLocationsListItem apiLocationResponse, [Frozen] Mock <ILocationApiClient <LocationApiConfiguration> > mockLocationApiClient, LocationLookupService service) { apiLocationResponse.Postcode = ""; apiLocationResponse.DistrictName = ""; var lat = 0; var lon = 0; mockLocationApiClient .Setup(client => client.Get <GetLocationsListResponse>( It.Is <GetLocationsQueryRequest>(c => c.GetUrl.Contains(location)))) .ReturnsAsync(new GetLocationsListResponse { Locations = new List <GetLocationsListItem> { apiLocationResponse } }); var result = await service.GetLocationInformation(location, lat, lon); result.Name.Should().Be($"{apiLocationResponse.LocationName}, {apiLocationResponse.LocalAuthorityName}"); result.GeoPoint.Should().BeEquivalentTo(apiLocationResponse.Location.GeoPoint); result.Country.Should().Be(apiLocationResponse.Country); }
public async Task Then_If_The_Location_Lookup_Returns_Empty_And_There_Is_A_Location_It_Is_Searched_And_First_Returned( GetLocationsListItem apiLocationResponse, [Frozen] Mock <ILocationApiClient <LocationApiConfiguration> > mockLocationApiClient, LocationLookupService service) { apiLocationResponse.Postcode = ""; apiLocationResponse.DistrictName = ""; var location = "LE1"; var lat = 0; var lon = 0; mockLocationApiClient .Setup(client => client.Get <GetLocationsListItem>( It.Is <GetLocationByOutcodeRequest>(c => c.GetUrl.Contains(location)))) .ReturnsAsync(new GetLocationsListItem { Location = null }); mockLocationApiClient .Setup(client => client.Get <GetLocationsListResponse>( It.Is <GetLocationsQueryRequest>(c => c.GetUrl.Contains(location)))) .ReturnsAsync(new GetLocationsListResponse { Locations = new List <GetLocationsListItem> { apiLocationResponse } }); var result = await service.GetLocationInformation(location, lat, lon); result.Should().NotBeNull(); result.Name.Should().Be($"{apiLocationResponse.LocationName}, {apiLocationResponse.LocalAuthorityName}"); result.GeoPoint.Should().BeEquivalentTo(apiLocationResponse.Location.GeoPoint); }
public async Task <LocationItem> GetLocationInformation(string location, double lat, double lon, bool includeDistrictNameInPostcodeDisplayName = false) { if (string.IsNullOrEmpty(location)) { return(null); } if (lat != 0 && lon != 0) { return(new LocationItem(location, new [] { lat, lon }, string.Empty)); } GetLocationsListItem getLocationsListItem = null; if (Regex.IsMatch(location, PostcodeRegex)) { getLocationsListItem = await _locationApiClient.Get <GetLocationsListItem>(new GetLocationByFullPostcodeRequest(location)); getLocationsListItem.IncludeDistrictNameInPostcodeDisplayName = includeDistrictNameInPostcodeDisplayName; location = getLocationsListItem.DisplayName; } else if (Regex.IsMatch(location, OutcodeDistrictRegex)) { getLocationsListItem = await _locationApiClient.Get <GetLocationsListItem>(new GetLocationByOutcodeAndDistrictRequest(location.Split(' ').FirstOrDefault())); if (getLocationsListItem.Location != null) { location = getLocationsListItem.DisplayName; } } else if (Regex.IsMatch(location, OutcodeRegex)) { getLocationsListItem = await _locationApiClient.Get <GetLocationsListItem>(new GetLocationByOutcodeRequest(location)); } else if (location.Split(",").Length >= 2) { var locationInformation = location.Split(","); var locationName = string.Join(",", locationInformation.Take(locationInformation.Length - 1)).Trim(); var authorityName = locationInformation.Last().Trim(); getLocationsListItem = await _locationApiClient.Get <GetLocationsListItem>(new GetLocationByLocationAndAuthorityName(locationName, authorityName)); } if (location.Length >= 2 && getLocationsListItem?.Location == null) { var locations = await _locationApiClient.Get <GetLocationsListResponse>(new GetLocationsQueryRequest(location)); var locationsListItem = locations?.Locations?.FirstOrDefault(); if (locationsListItem != null) { getLocationsListItem = locationsListItem; location = getLocationsListItem.DisplayName; } } return(getLocationsListItem?.Location != null ? new LocationItem(location, getLocationsListItem.Location.GeoPoint, getLocationsListItem.Country) : null); }
public void Then_The_Fields_are_Correctly_Mapped_When_Postcode_Is_Not_Null(GetLocationsListItem source) { //Act source.DistrictName = null; var actual = (GetLocationSearchResponseItem)source; //Assert actual.Name.Should().Be(source.Postcode); actual.Location.Should().BeEquivalentTo(source.Location); }
public void Then_The_Fields_are_Correctly_Mapped_When_Postcode_Is_Empty(GetLocationsListItem source) { //Arrange source.Postcode = ""; source.DistrictName = null; //Act var actual = (GetLocationSearchResponseItem)source; //Assert actual.Name.Should().Be($"{source.LocationName}, {source.LocalAuthorityName}"); actual.Location.Should().BeEquivalentTo(source.Location); }
public async Task Then_If_There_Is_A_Location_But_It_Does_Not_Have_Location_And_Authority_Supplied_It_Is_Null( string locationName, GetLocationsListItem apiLocationResponse, [Frozen] Mock <ILocationApiClient <LocationApiConfiguration> > mockLocationApiClient, LocationLookupService service) { var location = $"{locationName} ";//no regex match var lat = 0; var lon = 0; var result = await service.GetLocationInformation(location, lat, lon); mockLocationApiClient.Verify(x => x.Get <GetLocationsListItem>(It.IsAny <GetLocationByLocationAndAuthorityName>()), Times.Never); result.Should().BeNull(); }
public async Task Then_If_There_Is_An_Outcode_And_District_Supplied_It_Is_Searched_And_Returned( GetLocationsListItem apiLocationResponse, [Frozen] Mock <ILocationApiClient <LocationApiConfiguration> > mockLocationApiClient, LocationLookupService service) { var outcode = "CV1"; var location = $"{outcode} Birmingham, West Midlands"; var lat = 0; var lon = 0; mockLocationApiClient .Setup(client => client.Get <GetLocationsListItem>( It.Is <GetLocationByOutcodeAndDistrictRequest>(c => c.GetUrl.Contains(outcode)))) .ReturnsAsync(apiLocationResponse); var result = await service.GetLocationInformation(location, lat, lon); result.Name.Should().Be($"{apiLocationResponse.Outcode} {apiLocationResponse.DistrictName}"); result.GeoPoint.Should().BeEquivalentTo(apiLocationResponse.Location.GeoPoint); }
public async Task Then_If_There_Is_A_Location_Supplied_It_Is_Searched_And_Returned( string locationName, string authorityName, GetLocationsListItem apiLocationResponse, [Frozen] Mock <ILocationApiClient <LocationApiConfiguration> > mockLocationApiClient, LocationLookupService service) { var location = $"{locationName}, {authorityName} "; var lat = 0; var lon = 0; mockLocationApiClient .Setup(client => client.Get <GetLocationsListItem>( It.Is <GetLocationByLocationAndAuthorityName>(c => c.GetUrl.Contains(locationName.Trim()) && c.GetUrl.Contains(authorityName.Trim())))) .ReturnsAsync(apiLocationResponse); var result = await service.GetLocationInformation(location, lat, lon); result.Name.Should().Be(location); result.GeoPoint.Should().BeEquivalentTo(apiLocationResponse.Location.GeoPoint); }
public async Task Then_If_There_Is_An_Postcode_Supplied_It_Is_Searched_And_Returned( GetLocationsListItem apiLocationResponse, [Frozen] Mock <ILocationApiClient <LocationApiConfiguration> > mockLocationApiClient, LocationLookupService service) { var postcode = "CV1 1AA"; var location = $"{postcode}"; var lat = 0; var lon = 0; mockLocationApiClient .Setup(client => client.Get <GetLocationsListItem>( It.Is <GetLocationByFullPostcodeRequest>(c => c.GetUrl.Contains(postcode.Split().FirstOrDefault()) && c.GetUrl.Contains(postcode.Split().LastOrDefault())))) .ReturnsAsync(apiLocationResponse); var result = await service.GetLocationInformation(location, lat, lon); result.Name.Should().Be(location); result.GeoPoint.Should().BeEquivalentTo(apiLocationResponse.Location.GeoPoint); }