public async Task WebAPI_StoreRepository_UpdateStoreLocation_Should_Update_For_Each_Store() { #region Arrange IEnumerable <Store> allStores = await _storeRepository.GetStoresAsync(); ILocationService locationService = new LocationService(); #endregion #region Act // Validate stores exists if (allStores.IsNullOrEmpty()) { throw new Exception("Stores are empty"); } foreach (Store store in allStores) { // Continue when store already has location if (store.Location != null) { continue; } // Continue when city or address are empty if (string.IsNullOrWhiteSpace(store.City) || string.IsNullOrWhiteSpace(store.Address)) { continue; } // Fetch location for store ForwardGeocodingResponse locationResponse = await locationService.GetLocationByAddress(store.City, store.Address); // Continue when results are empty if (locationResponse.Results.IsNullOrEmpty()) { continue; } ForwardGeocodingResult result = locationResponse.Results.First(); var geoPointToUpdate = new GeoJsonPoint <GeoJson2DGeographicCoordinates>( new GeoJson2DGeographicCoordinates( longitude: result.Geometry.Lng, latitude: result.Geometry.Lat)); await _storeRepository.UpdateStoreLocation(store.ID, geoPointToUpdate); } #endregion // No assert }
public static ForwardGeocodingResult AsMapsApiGeocodingResult(this GoogleGeocodingResponse value) { var response = new ForwardGeocodingResult { Results = value.Results.Select( r => new Result { Boundry = r.Geometry.Bounds == null ? null : new BoundingBox { NorthEast = new Location { Latitude = r.Geometry.Bounds.NorthEast.Latitude, Longitude = r.Geometry.Bounds.NorthEast.Longitude }, SouthWest = new Location { Latitude = r.Geometry.Bounds.SouthWest.Latitude, Longitude = r.Geometry.Bounds.SouthWest.Longitude } }, Id = r.PlaceId, Location = new Location { Latitude = r.Geometry.Location.Latitude, Longitude = r.Geometry.Location.Longitude }, Address = new Address { FullAddress = r.FormattedAddress, PropertyId = GetGoogleAddressComponent(r.AddressComponents, "street_number"), Street = GetGoogleAddressComponent(r.AddressComponents, "route"), SubLocality = GetGoogleAddressComponent(r.AddressComponents, "sublocality_level_1"), Locality = GetGoogleAddressComponent(r.AddressComponents, "locality"), Town = GetGoogleAddressComponent(r.AddressComponents, "postal_town"), Region = GetGoogleAddressComponent(r.AddressComponents, "administrative_area_level_1"), County = GetGoogleAddressComponent(r.AddressComponents, "administrative_area_level_2"), Country = GetGoogleAddressComponent(r.AddressComponents, "country"), PostalCode = GetGoogleAddressComponent(r.AddressComponents, "postal_code") } }) }; return(response); }
public static ForwardGeocodingResult AsMapsApiGeocodingResult(this MapBoxGeocodingResponse value) { var response = new ForwardGeocodingResult { Results = value.Features.Select( f => new Result { Boundry = new BoundingBox { NorthEast = new Location { Latitude = f.BBox.MinX, Longitude = f.BBox.MinY }, SouthWest = new Location { Latitude = f.BBox.MaxX, Longitude = f.BBox.MaxY }, }, Id = f.Id, Location = new Location { Latitude = f.Center.Y, Longitude = f.Center.X }, Address = new Address { FullAddress = f.PlaceName, PropertyId = f.Address, Street = f.Text, SubLocality = GetMapBoxAddressComponent(f.Context, "neighborhood"), Locality = GetMapBoxAddressComponent(f.Context, "locality"), Town = GetMapBoxAddressComponent(f.Context, "place"), Region = GetMapBoxAddressComponent(f.Context, "region"), County = GetMapBoxAddressComponent(f.Context, "region"), Country = GetMapBoxAddressComponent(f.Context, "country"), PostalCode = GetMapBoxAddressComponent(f.Context, "postcode"), } } ) }; return(response); }