public async Task Geocode_returns_null_on_Error() { var client = new Mock <HttpClient>(); var response = new HttpResponseMessage(HttpStatusCode.Forbidden) { Content = new StringContent(invalidApiResponse, Encoding.UTF8, "application/json") }; client.Setup(c => c.SendAsync(It.IsAny <HttpRequestMessage>(), It.IsAny <CancellationToken>())) .ReturnsAsync(response); var geo = new Geocodio("https://www.example.org", "foo", client.Object); var location = await geo.GeocodeAsync("foobar"); Assert.IsNull(location); }
public async Task Geocode_returns_DbGeometry_on_Success() { var client = new Mock <HttpClient>(); var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(goodApiResponse, Encoding.UTF8, "application/json") }; client.Setup(c => c.SendAsync(It.IsAny <HttpRequestMessage>(), It.IsAny <CancellationToken>())) .ReturnsAsync(response); var geo = new Geocodio("https://www.example.org", "foo", client.Object); var location = await geo.GeocodeAsync("foobar"); Assert.IsNotNull(location); Assert.AreEqual(38.886665, location.Latitude); Assert.AreEqual(-77.094733, location.Longitude); }