public async Task Should_Return_Default_Values_For_Lat_And_Long() { var geocoder = new GoogleGeocodeService(); var result = await geocoder.GeocodeLocation("dfgfdgfdgfdgdfgdfgdfg"); Assert.Equal(0, result.Latitude); Assert.Equal(0, result.Longitude); }
public async Task Should_Return_Lat_And_Long() { var geocoder = new GoogleGeocodeService(); var result = await geocoder.GeocodeLocation("Atlanta, GA"); Assert.NotNull(result.Latitude); Assert.NotNull(result.Longitude); }
public void TestService() { var svc = new GoogleGeocodeService(new RestSharpProxy()); var resp = svc.GetGeocode("123 fakestreet"); Assert.Equal("38.7062039", resp.Latitude); Assert.Equal("-78.5065001", resp.Longitude); Assert.Equal("OK", resp.Status); }
public async void Should_Fail_When_Geocoding_Nonexistant_Address() { var expected = GoogleApiConstants.GOOGLE_GEOCODE_ERROR_INVALID_ADDRESS; var service = new GoogleGeocodeService(); var address = new Address() { Street1 = "9999 Bvasdgdgdsgfgdsgsdgdsawe", City = "Long Basdfasfasdfeach", State = "CA", Zip = 90840 }; var result = await service.GeocodeAsync(address); result.Error.Should().Be(expected); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); IProPublicaService congressService = new ProPublicaService(Configuration["Configurations:ProPublicEndpoint"], Configuration["Configurations:ProPublicaAPIKey"]); services.AddSingleton(congressService); IGoogleGeocodeService geocodeService = new GoogleGeocodeService(Configuration["Configurations:GoogleGeocodeEndpoint"], Configuration["Configurations:GoogleApiKey"]); services.AddSingleton(geocodeService); IDarkSkyService darkSkyService = new DarkSkyService(Configuration["Configurations:DarkSkyEndpoint"], Configuration["Configurations:DarkSkySecretKey"]); services.AddSingleton(darkSkyService); }
public void Should_Pass_When_Geocoding_Csulb_Synchronously() { var service = new GoogleGeocodeService(); var address = new Address() { Street1 = "1250 Bellflower Blvd", City = "Long Beach", State = "CA", Zip = 90840 }; var expectedLat = 33.7830608; var expectedLong = -118.1148909; var result = service.Geocode(address); result?.Data.Latitude.Should().Equals(expectedLat); result?.Data.Longitude.Should().Equals(expectedLong); }
public async void Should_Fail_When_Geocoding_Csulb_Wrong_Address() { var service = new GoogleGeocodeService(); var address = new Address() { Street1 = "1250 Bellflower Blvd", City = "Long Beach", State = "CA", Zip = 90840 }; var expectedLat = 0; var expectedLong = 0; var result = await service.GeocodeAsync(address); result?.Data.Latitude.Should().NotBe(expectedLat); result?.Data.Longitude.Should().NotBe(expectedLong); }
public async Task GetCoordinatesFromAddress_ReturnsNull_WhenNotSuccessStatusCode() { var httpClient = new Mock <IHttpClient>(); httpClient.Setup(x => x.GetAsync(It.IsAny <string>())).ReturnsAsync(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest)); var options = new Mock <IOptions <MappingSettings> >(); options.Setup(x => x.Value).Returns(new MappingSettings { GoogleMapsApiKey = "123" }); var sut = new GoogleGeocodeService(httpClient.Object, options.Object); var result = await sut.GetCoordinatesFromAddress("address"); result.ShouldBeNull(); }
public async Task GetCoordinatesFromAddress_CallsHttpClientGetAsync_Once() { var httpClient = new Mock <IHttpClient>(); httpClient.Setup(x => x.GetAsync(It.IsAny <string>())).ReturnsAsync(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest)); var options = new Mock <IOptions <MappingSettings> >(); options.Setup(x => x.Value).Returns(new MappingSettings { GoogleMapsApiKey = "123" }); var sut = new GoogleGeocodeService(httpClient.Object, options.Object); await sut.GetCoordinatesFromAddress("address"); httpClient.Verify(x => x.GetAsync(It.IsAny <string>()), Times.Once); }
public async Task GetCoordinatesFromAddress_ReturnsNull_WhenExceptionThrown() { var httpClient = new Mock <IHttpClient>(); httpClient.Setup(x => x.GetAsync(It.IsAny <string>())).Throws <Exception>(); var options = new Mock <IOptions <MappingSettings> >(); options.Setup(x => x.Value).Returns(new MappingSettings { GoogleMapsApiKey = "123" }); var sut = new GoogleGeocodeService(httpClient.Object, options.Object); var result = await sut.GetCoordinatesFromAddress("address"); result.ShouldBeNull(); }
public async Task GetCoordinatesFromAddress_WithIndividualAddressParams_CallsHttpClientGetAsync_WithCorrectUrl() { var url = string.Empty; var httpClient = new Mock <IHttpClient>(); httpClient.Setup(x => x.GetAsync(It.IsAny <string>())).ReturnsAsync(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest)).Callback <string>(x => url = x); var options = new Mock <IOptions <MappingSettings> >(); options.Setup(x => x.Value).Returns(new MappingSettings { GoogleMapsApiKey = "123" }); var sut = new GoogleGeocodeService(httpClient.Object, options.Object); await sut.GetCoordinatesFromAddress("1 some street", "town", "state", "postcode", null); url.ShouldBe(string.Concat("https://maps.googleapis.com/maps/api/geocode/json?address=", "1%20some%20street,town,state,postcode", "&key=", "123")); }
public async Task GetCoordinatesFromAddress_ReturnsCorrectCoordinates_WhenValidGoogleResponse() { var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK); response.Content = new StringContent(ValidGoogleResponse); var httpClient = new Mock <IHttpClient>(); httpClient.Setup(x => x.GetAsync(It.IsAny <string>())).ReturnsAsync(response); var options = new Mock <IOptions <MappingSettings> >(); options.Setup(x => x.Value).Returns(new MappingSettings { GoogleMapsApiKey = "123" }); var sut = new GoogleGeocodeService(httpClient.Object, options.Object); var result = await sut.GetCoordinatesFromAddress("address"); result.Latitude.ShouldBe(37.4224764); result.Longitude.ShouldBe(-122.0842499); }
public TruckersController(IRepositoryWrapper repo, GoogleGeocodeService geocode, GoogleDistanceService distance) { _repo = repo; _geocode = geocode; _distance = distance; }