static async Task Main(string[] args) { string sampleAddress = "<address>"; string googleKey = "<insert_key>"; string bingKey = "<insert_key>"; var gcClient = new HttpClient(new GeoCoding.Utils.Http.GeoHandler(3)); var geoServices = new List <IGeoService>(); geoServices.Add(GeoServiceFactory.CreateBingService(gcClient, bingKey)); geoServices.Add(GeoServiceFactory.CreateGoogleService(gcClient, googleKey)); try { var translator = new AddressTranslator(geoServices); var allResult = await translator.GetAllCoordinates(sampleAddress, GeoCoding.Data.AccuracyLevel.Lowest); Console.WriteLine($"GetCoordinate(All) - Address: {sampleAddress}: Coordinates:\n{JsonConvert.SerializeObject(allResult, Formatting.Indented)}"); var singleResult = await translator.GetCoordinate(sampleAddress, GeoCoding.Data.AccuracyLevel.Lowest); Console.WriteLine($"GetCoordinate(first) - Address: {sampleAddress}: Coordinates:\n{JsonConvert.SerializeObject(singleResult, Formatting.Indented)}"); } catch (Exception ex) { Console.WriteLine(ex); } }
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); }