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); }
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); }
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); }
public void SetAccuracyLevel(AccuracyLevel lvl) { this.level = lvl; }
public PathAnalyser(AccuracyLevel level) { this.level = level; }
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); }
/// <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); }
/// <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]); }