Beispiel #1
0
        public async Task Bing_is_repeatedly_used_when_google_fails_to_return_a_result()
        {
            var address = $"GOOGLE={GeocodeStatus.ZeroResults};BING={GeocodeStatus.Success}";

            Assert.Equal(GeocoderNames.Bing, (await geocodeManager.GeocodeAddressAsync(address)).GeocoderId);
            Assert.Equal(GeocoderNames.Bing, (await geocodeManager.GeocodeAddressAsync(address)).GeocoderId);
            Assert.Equal(GeocoderNames.Bing, (await geocodeManager.GeocodeAddressAsync(address)).GeocoderId);
        }
Beispiel #2
0
        public async Task Status_is_geocoded_when_google_returns_zero_but_bing_returns_data()
        {
            var address = $"GOOGLE={GeocodeStatus.ZeroResults};BING={GeocodeStatus.Success}";

            var result = await geocodeManager.GeocodeAddressAsync(address);

            Assert.Equal(AddressLookupStatus.Geocoded, result.Status);
        }
        // TODO: I don't like that this func mutates the passed parameter, create a model and return it.
        private async Task <SawmillGeocodeRequest> GeocodeLocationAsync(SawmillGeocodeRequest location)
        {
            if (location.Status == SawmillStatus.RequiresLookup)
            {
                // TODO: Test that this caches.
                logger?.LogInformation((int)LogEventIds.CheckingCache, "Looking up locations in L1/L2 caches");
                location = await locationCache.LookupAsync(location.Source);
            }

            var qualityStatus = addressQualityChecker.StatusGuessFromSourceQuality(location.Source);

            if (qualityStatus != AddressQualityStatus.OK)
            {
                location.Status = MapQualityStatus(qualityStatus);
            }

            if (location.Status == SawmillStatus.RequiresGeocoding || location.Status == SawmillStatus.TemporaryGeocodeError)
            {
                // TODO: We might need to record the last time a geocoding was attempted and how many tries if this was a temp error so we don't keep retrying.
                var result = await geocodeManager.GeocodeAddressAsync(location.Source);

                // TODO: Insert additional responses into cache here plus expiry times dependent on the status.
                if (result.Status == AddressLookupStatus.Geocoded || result.Status == AddressLookupStatus.ZeroResults)
                {
                    // TODO: Add cache inserting.
                    // locationCache.InsertAsync
                }

                // TODO: Geocoder should return a text description of the errors so we can present to the user.
                location.Status       = MapGeocoderStatus(result.Status);
                location.GeocoderUsed = result.GeocoderId;
                if (location.Status == SawmillStatus.Geocoded)
                {
                    location.Responses = result.Locations;
                }
            }

            return(location);
        }