public void GetLatLongForCityAsync__CallsWithGet() { var handlerMock = SetupBackend(x => x.Method == HttpMethod.Get); var client = new HttpClient(handlerMock.Object); var geo = new OpenCageGeo(client, apiKey); Func <Task> act = async() => await geo.GetLatLongForCityAsync("Foobar"); act.Should().NotThrow(); }
public void GetLatLongForCityAsync__CallsToOpenCage() { var handlerMock = SetupBackend(x => x.RequestUri.AbsoluteUri.StartsWith("https://api.opencagedata.com/geocode/v1/json?")); var client = new HttpClient(handlerMock.Object); var geo = new OpenCageGeo(client, apiKey); Func <Task> act = async() => await geo.GetLatLongForCityAsync("Foobar"); act.Should().NotThrow(); }
public void GetLatLongFromCityAsync__ThrowsExceptionWhenNoLocationFound() { var handlerMock = SetupBackend(response: NoResultsFoundResponse); var client = new HttpClient(handlerMock.Object); var geo = new OpenCageGeo(client, apiKey); Func <Task> act = async() => await geo.GetLatLongForCityAsync("Des Moines"); act.Should().Throw <ApiException>().WithMessage($"*Location not found"); }
public void GetLatLongFromCityAsync__AddsTheLocationToTheQueryString() { var city = "Des Moines"; var handlerMock = SetupBackend(x => x.RequestUri.Query.Contains($"q={WebUtility.UrlEncode(city)}")); var client = new HttpClient(handlerMock.Object); var geo = new OpenCageGeo(client, apiKey); Func <Task> act = async() => await geo.GetLatLongForCityAsync(city); act.Should().NotThrow(); }
public void GetLatLongFromCityAsync__AddsTheApiKey() { var apiKey = "Foobar"; var handlerMock = SetupBackend(x => x.RequestUri.Query.Contains($"key={apiKey}")); var client = new HttpClient(handlerMock.Object); var geo = new OpenCageGeo(client, apiKey); Func <Task> act = async() => await geo.GetLatLongForCityAsync("Des Moines"); act.Should().NotThrow(); }
public async Task GetLatLongFromCityAsync__ReturnsTheCoordsForTheRequested() { var handlerMock = SetupBackend(); var client = new HttpClient(handlerMock.Object); var geo = new OpenCageGeo(client, apiKey); var coords = await geo.GetLatLongForCityAsync("Des Moines"); coords.Lat.Should().BeApproximately(lat, 2d); coords.Lng.Should().BeApproximately(lng, 2d); coords.ToString().Should().BeEquivalentTo(location); }