Example #1
0
        public async Task BothActiveServicesBingPrioritizedAccuracyInvalidChecks(AccuracyLevel bingAccuracy, AccuracyLevel googleAccuracy,
                                                                                 AccuracyLevel threshold)
        {
            var geoServices = new List <IGeoService>();

            var googleServiceMock = new Mock <IGeoService>();

            googleServiceMock.Setup(x => x.GetCoordinate("Good address")).ReturnsAsync(new GeoCoordinate {
                Accuracy = googleAccuracy, Service = ServiceType.Google
            });

            var bingServiceMock = new Mock <IGeoService>();

            bingServiceMock.Setup(x => x.GetCoordinate("Good address")).ReturnsAsync(new GeoCoordinate {
                Accuracy = bingAccuracy, Service = ServiceType.Bing
            });

            geoServices.Add(googleServiceMock.Object);
            geoServices.Add(bingServiceMock.Object);

            var translator = new AddressTranslator(geoServices);

            var coordinates = await translator.GetCoordinate("Good address", threshold);

            Assert.Null(coordinates);
        }
Example #2
0
        public async Task BothActiveServicesAllResponsesCountChecks(AccuracyLevel bingAccuracy, AccuracyLevel googleAccuracy,
                                                                    AccuracyLevel threshold, int expectedCount)
        {
            var geoServices = new List <IGeoService>();

            var googleServiceMock = new Mock <IGeoService>();

            googleServiceMock.Setup(x => x.GetCoordinate("Good address")).ReturnsAsync(new GeoCoordinate {
                Accuracy = googleAccuracy, Service = ServiceType.Google
            });

            var bingServiceMock = new Mock <IGeoService>();

            bingServiceMock.Setup(x => x.GetCoordinate("Good address")).ReturnsAsync(new GeoCoordinate {
                Accuracy = bingAccuracy, Service = ServiceType.Bing
            });

            geoServices.Add(googleServiceMock.Object);
            geoServices.Add(bingServiceMock.Object);

            var translator = new AddressTranslator(geoServices);

            var coordinates = await translator.GetAllCoordinates("Good address", threshold);

            // get no of unique(in terms of services in results) coordinates returned.
            var uniqueCount = coordinates.Select((entry) => { return(entry.Service); }).Distinct().Count();

            Assert.Equal(expectedCount, uniqueCount);
        }
Example #3
0
        public async Task HappyFlow(string jsonPath, AccuracyLevel expectedAccuracy)
        {
            var goodResponse = await File.OpenText(jsonPath).ReadToEndAsync();

            MockHttp.When(BaseUrl)
            .Respond("application/json", goodResponse);

            var service = new GoogleService("SOME_KEY", MockHttp.ToHttpClient());

            var coordinates = await service.GetCoordinate("Good address");

            var vals = Generic.ParseCoordinatesFromGoogleJson(goodResponse);

            Assert.Equal(vals.Item1, coordinates.Latitude);
            Assert.Equal(vals.Item2, coordinates.Longitude);
            Assert.Equal(expectedAccuracy, coordinates.Accuracy);
        }
Example #4
0
 public void SetAccuracyLevel(AccuracyLevel lvl)
 {
     this.level = lvl;
 }
Example #5
0
 public PathAnalyser(AccuracyLevel level)
 {
     this.level = level;
 }
Example #6
0
        private async Task <IList <GeoCoordinate> > GetCoordinateHelper(string address, AccuracyLevel threshold, bool stopAtFirst)
        {
            var result = new List <GeoCoordinate>();

            foreach (var geoService in GeoServicePriorityList)
            {
                try
                {
                    var coordinate = await geoService.GetCoordinate(address);

                    if (coordinate.Accuracy < threshold)
                    {
                        Trace.TraceWarning($"{geoService.GetType().ToString()} ignored - Threshold not met\nResponse recieved:\n" +
                                           $"{JsonConvert.SerializeObject(coordinate, Formatting.Indented)}");
                        continue;
                    }

                    result.Add(coordinate);
                    if (stopAtFirst)
                    {
                        return(result);
                    }
                }
                catch (GCException ex)
                {
                    Trace.TraceError($"{geoService.GetType().ToString()} failed with exception {ex}");
                }
            }

            return(result);
        }
Example #7
0
        /// <summary>
        /// Retrieve all valid coordinates from geoservice list for specified address string.
        /// Only coordinates satisfiying minimum threshold accuracy are included.
        /// </summary>
        /// <param name="address">Address string</param>
        /// <param name="threshold">Minimum accuracy expected</param>
        /// <returns>Empty list if no valid entries found.</returns>
        public async Task <IList <GeoCoordinate> > GetAllCoordinates(string address, AccuracyLevel threshold)
        {
            var result = await GetCoordinateHelper(address, threshold, false);

            return(result);
        }
Example #8
0
        /// <summary>
        /// Retrieve first valid coordinate from geoservice list for specified address string.
        /// Only coordinate satisfiying minimum threshold accuracy are considered.
        /// </summary>
        /// <param name="address">Address string</param>
        /// <param name="threshold">Minimum accuracy expected</param>
        /// <returns>null if no result found. </returns>
        public async Task <GeoCoordinate> GetCoordinate(string address, AccuracyLevel threshold)
        {
            var result = await GetCoordinateHelper(address, threshold, true);

            return((result.Count == 0)? null: result[0]);
        }