Ejemplo n.º 1
0
        public void VerifyCorrectLocationTypesAttachedToGasStationResult()
        {
            String json = Assembly.GetExecutingAssembly().ReadEmbeddedResourceTextFile("Geocoding.Google.GoogleResponse.GasStation-KwikTrip.json");
            Mock <IRestResponse> restResponse = new Mock <IRestResponse>();

            restResponse.Setup(r => r.ResponseStatus).Returns(ResponseStatus.Completed);
            restResponse.Setup(r => r.StatusCode).Returns(System.Net.HttpStatusCode.OK);
            restResponse.Setup(r => r.Content).Returns(json);

            Mock <IRestClient> mockRestClient = new Mock <IRestClient>();

            mockRestClient.Setup(c => c.Execute(It.IsAny <RestRequest>()))
            .Returns(restResponse.Object);

            GoogleGeocodingService service = new GoogleGeocodingService("test", mockRestClient.Object);
            var result = service.GeocodeAddress(It.IsAny <string>());

            // Assert
            result.Value.Count.Should().Be(1);

            // This is a convenience store, so all three of these should light up
            result.Value[0].LocationType.Should().HaveFlag(LocationType.BUSINESS);
            result.Value[0].LocationType.Should().HaveFlag(LocationType.GAS_STATION);
            result.Value[0].LocationType.Should().HaveFlag(LocationType.STORE);
            result.Value[0].LocationType.Should().NotHaveFlag(LocationType.POINT_OF_INTEREST);  // POI is assinged ot everything in Google, so it should screen out
        }
Ejemplo n.º 2
0
        public void VerifyFullCallResponseWhenGoogleReturnsSingleAddress()
        {
            String json = Assembly.GetExecutingAssembly().ReadEmbeddedResourceTextFile("Geocoding.Google.GoogleResponse.GoogleHeadquarters.json");
            Mock <IRestResponse> restResponse = new Mock <IRestResponse>();

            restResponse.Setup(r => r.ResponseStatus).Returns(ResponseStatus.Completed);
            restResponse.Setup(r => r.StatusCode).Returns(System.Net.HttpStatusCode.OK);
            restResponse.Setup(r => r.Content).Returns(json);

            Mock <IRestClient> mockRestClient = new Mock <IRestClient>();

            mockRestClient.Setup(c => c.Execute(It.IsAny <RestRequest>()))
            .Returns(restResponse.Object);

            GoogleGeocodingService service = new GoogleGeocodingService("test", mockRestClient.Object);
            var result = service.GeocodeAddress(It.IsAny <string>());

            result.IsSuccess.Should().BeTrue();
            result.Value.Should().NotBeNull();
            result.Value.Count.Should().Be(1);

            result.Value[0].FormattedAddress.Should().Be("1600 Amphitheatre Parkway, Mountain View, CA 94043, USA");
            result.Value[0].Location.Latitude.Value.Should().BeApproximately(37.422476, 0.00001);
            result.Value[0].Location.Longitude.Value.Should().BeApproximately(-122.0842499, 0.00001);
        }
Ejemplo n.º 3
0
        public void VerifyUsZipCodeSearchDecodesCorrectly()
        {
            String json = Assembly.GetExecutingAssembly().ReadEmbeddedResourceTextFile("Geocoding.Google.GoogleResponse.UsZipCode-83702.json");
            Mock <IRestResponse> restResponse = new Mock <IRestResponse>();

            restResponse.Setup(r => r.ResponseStatus).Returns(ResponseStatus.Completed);
            restResponse.Setup(r => r.StatusCode).Returns(System.Net.HttpStatusCode.OK);
            restResponse.Setup(r => r.Content).Returns(json);

            Mock <IRestClient> mockRestClient = new Mock <IRestClient>();

            mockRestClient.Setup(c => c.Execute(It.IsAny <RestRequest>()))
            .Returns(restResponse.Object);

            GoogleGeocodingService service = new GoogleGeocodingService("test", mockRestClient.Object);
            var result = service.GeocodeAddress(It.IsAny <string>());

            result.IsSuccess.Should().BeTrue();
            result.Value.Should().NotBeNull();
            result.Value.Count.Should().Be(1);

            result.Value[0].FormattedAddress.Should().Be("Boise, ID 83702, USA");
            result.Value[0].Location.Latitude.Value.Should().BeApproximately(43.6624385, 0.00001);
            result.Value[0].Location.Longitude.Value.Should().BeApproximately(-116.1630431, 0.00001);

            result.Value[0].LocationType.Should().Be(LocationType.POSTAL_CODE);

            result.Value[0].Viewport.PointOne.Latitude.Value.Should().BeApproximately(43.7000229, 0.00001);
            result.Value[0].Viewport.PointOne.Longitude.Value.Should().BeApproximately(-116.0941219, 0.00001);

            result.Value[0].Viewport.PointTwo.Latitude.Value.Should().BeApproximately(43.6033878, 0.00001);
            result.Value[0].Viewport.PointTwo.Longitude.Value.Should().BeApproximately(-116.2351669, 0.00001);
        }
Ejemplo n.º 4
0
        public void VerifySingleCitySearchDecodesCorrectly()
        {
            String json = Assembly.GetExecutingAssembly().ReadEmbeddedResourceTextFile("Geocoding.Google.GoogleResponse.City-BoiseId.json");
            Mock <IRestResponse> restResponse = new Mock <IRestResponse>();

            restResponse.Setup(r => r.ResponseStatus).Returns(ResponseStatus.Completed);
            restResponse.Setup(r => r.StatusCode).Returns(System.Net.HttpStatusCode.OK);
            restResponse.Setup(r => r.Content).Returns(json);

            Mock <IRestClient> mockRestClient = new Mock <IRestClient>();

            mockRestClient.Setup(c => c.Execute(It.IsAny <RestRequest>()))
            .Returns(restResponse.Object);

            GoogleGeocodingService service = new GoogleGeocodingService("test", mockRestClient.Object);
            var result = service.GeocodeAddress(It.IsAny <string>());

            result.IsSuccess.Should().BeTrue();
            result.Value.Should().NotBeNull();
            result.Value.Count.Should().Be(1);

            result.Value[0].FormattedAddress.Should().Be("Boise, ID, USA");
            result.Value[0].Location.Latitude.Value.Should().BeApproximately(43.6150186, 0.00001);
            result.Value[0].Location.Longitude.Value.Should().BeApproximately(-116.2023137, 0.00001);

            result.Value[0].LocationType.Should().Be(LocationType.CITY);

            result.Value[0].Viewport.PointOne.Latitude.Value.Should().BeApproximately(43.6898951, 0.00001);
            result.Value[0].Viewport.PointOne.Longitude.Value.Should().BeApproximately(-116.1019091, 0.00001);

            result.Value[0].Viewport.PointTwo.Latitude.Value.Should().BeApproximately(43.511717, 0.00001);
            result.Value[0].Viewport.PointTwo.Longitude.Value.Should().BeApproximately(-116.3658869, 0.00001);
        }
        public void TestGoogleGeoService()
        {
            var query   = "Level 3, 26 Marine Parade Southport QLD 4216";
            var service = new GoogleGeocodingService(String.Empty);
            var result  = service.GetLocationsByQueryAsync(query).Result;

            System.Diagnostics.Process.Start(service.GetLocationMapImageUrl(result.Locations.ElementAt(0)));
        }
Ejemplo n.º 6
0
        public void VerifyFormattedLocationStringIsMappedToGeocodingResponseObject()
        {
            String json = Assembly.GetExecutingAssembly().ReadEmbeddedResourceTextFile("Geocoding.Google.GoogleResponse.GoogleHeadquarters.json");
            Mock <IRestResponse> restResponse = new Mock <IRestResponse>();

            restResponse.Setup(r => r.ResponseStatus).Returns(ResponseStatus.Completed);
            restResponse.Setup(r => r.StatusCode).Returns(System.Net.HttpStatusCode.OK);
            restResponse.Setup(r => r.Content).Returns(json);

            Mock <IRestClient> mockRestClient = new Mock <IRestClient>();

            mockRestClient.Setup(c => c.Execute(It.IsAny <RestRequest>()))
            .Returns(restResponse.Object);

            GoogleGeocodingService service = new GoogleGeocodingService("test", mockRestClient.Object);
            var result = service.GeocodeAddress(It.IsAny <string>());

            result.Value[0].FormattedAddress.Should().Be("1600 Amphitheatre Parkway, Mountain View, CA 94043, USA");
        }
Ejemplo n.º 7
0
        public void VerifyLocationLatitudeLongitudeMappedCorrectlyInReturnObject()
        {
            String json = Assembly.GetExecutingAssembly().ReadEmbeddedResourceTextFile("Geocoding.Google.GoogleResponse.GoogleHeadquarters.json");
            Mock <IRestResponse> restResponse = new Mock <IRestResponse>();

            restResponse.Setup(r => r.ResponseStatus).Returns(ResponseStatus.Completed);
            restResponse.Setup(r => r.StatusCode).Returns(System.Net.HttpStatusCode.OK);
            restResponse.Setup(r => r.Content).Returns(json);

            Mock <IRestClient> mockRestClient = new Mock <IRestClient>();

            mockRestClient.Setup(c => c.Execute(It.IsAny <RestRequest>()))
            .Returns(restResponse.Object);

            GoogleGeocodingService service = new GoogleGeocodingService("test", mockRestClient.Object);
            var result = service.GeocodeAddress(It.IsAny <string>());

            result.Value[0].Location.Latitude.Value.Should().BeApproximately(37.422476, 0.00001);
            result.Value[0].Location.Longitude.Value.Should().BeApproximately(-122.0842499, 0.00001);
        }
Ejemplo n.º 8
0
        public void VerifyCorrectAirportLocationTypeAttachedToAirport()
        {
            String json = Assembly.GetExecutingAssembly().ReadEmbeddedResourceTextFile("Geocoding.Google.GoogleResponse.Airport-OHare.json");
            Mock <IRestResponse> restResponse = new Mock <IRestResponse>();

            restResponse.Setup(r => r.ResponseStatus).Returns(ResponseStatus.Completed);
            restResponse.Setup(r => r.StatusCode).Returns(System.Net.HttpStatusCode.OK);
            restResponse.Setup(r => r.Content).Returns(json);

            Mock <IRestClient> mockRestClient = new Mock <IRestClient>();

            mockRestClient.Setup(c => c.Execute(It.IsAny <RestRequest>()))
            .Returns(restResponse.Object);

            GoogleGeocodingService service = new GoogleGeocodingService("test", mockRestClient.Object);
            var result = service.GeocodeAddress(It.IsAny <string>());

            // Assert
            result.Value.Count.Should().Be(1);
            result.Value[0].LocationType.Should().HaveFlag(LocationType.AIRPORT);
        }
Ejemplo n.º 9
0
        public void VerifyFailureResultReturnedWhenGoogleReturnsError()
        {
            String json = Assembly.GetExecutingAssembly().ReadEmbeddedResourceTextFile("Geocoding.Google.GoogleResponse.BillingDisabled.json");
            Mock <IRestResponse> restResponse = new Mock <IRestResponse>();

            restResponse.Setup(r => r.ResponseStatus).Returns(ResponseStatus.Completed);
            restResponse.Setup(r => r.StatusCode).Returns(System.Net.HttpStatusCode.OK);
            restResponse.Setup(r => r.Content).Returns(json);

            Mock <IRestClient> mockRestClient = new Mock <IRestClient>();

            mockRestClient.Setup(c => c.Execute(It.IsAny <RestRequest>()))
            .Returns(restResponse.Object);

            GoogleGeocodingService service = new GoogleGeocodingService("test", mockRestClient.Object);
            var result = service.GeocodeAddress(It.IsAny <string>());

            result.IsSuccess.Should().BeFalse();
            result.Error.Message.Should().Be("Call to Google geocoding service failed");
            result.Value.Should().BeNull();
        }
Ejemplo n.º 10
0
        public void VerifyCitySearchWithMultipleResultsDecodesCorrectly()
        {
            String json = Assembly.GetExecutingAssembly().ReadEmbeddedResourceTextFile("Geocoding.Google.GoogleResponse.MultipleCity-Springfield.json");
            Mock <IRestResponse> restResponse = new Mock <IRestResponse>();

            restResponse.Setup(r => r.ResponseStatus).Returns(ResponseStatus.Completed);
            restResponse.Setup(r => r.StatusCode).Returns(System.Net.HttpStatusCode.OK);
            restResponse.Setup(r => r.Content).Returns(json);

            Mock <IRestClient> mockRestClient = new Mock <IRestClient>();

            mockRestClient.Setup(c => c.Execute(It.IsAny <RestRequest>()))
            .Returns(restResponse.Object);

            GoogleGeocodingService service = new GoogleGeocodingService("test", mockRestClient.Object);
            var result = service.GeocodeAddress(It.IsAny <string>());

            result.IsSuccess.Should().BeTrue();
            result.Value.Should().NotBeNull();
            result.Value.Count.Should().Be(3);

            // Springfield, MO
            result.Value[0].FormattedAddress.Should().Be("Springfield, MO, USA");
            result.Value[0].Location.Latitude.Value.Should().BeApproximately(37.2089572, 0.00001);
            result.Value[0].Location.Longitude.Value.Should().BeApproximately(-93.29229889999999, 0.00001);
            result.Value[0].LocationType.Should().HaveFlag(LocationType.CITY);

            // Springfield, IL
            result.Value[1].FormattedAddress.Should().Be("Springfield, IL, USA");
            result.Value[1].Location.Latitude.Value.Should().BeApproximately(39.781721300, 0.00001);
            result.Value[1].Location.Longitude.Value.Should().BeApproximately(-89.6501481, 0.00001);
            result.Value[1].LocationType.Should().HaveFlag(LocationType.CITY);

            // Springfield, OH
            result.Value[2].FormattedAddress.Should().Be("Springfield, OH, USA");
            result.Value[2].Location.Latitude.Value.Should().BeApproximately(39.9242266, 0.00001);
            result.Value[2].Location.Longitude.Value.Should().BeApproximately(-83.80881711, 0.00001);
            result.Value[2].LocationType.Should().HaveFlag(LocationType.CITY);
        }
Ejemplo n.º 11
0
        public ActionResult Create(NewEstablishmentViewModel viewModel)
        {
            viewModel.Establishment.CreatedDateTime = DateTime.Now;

            // Geocodes the address.
            try
            {
                var geocoder = new GoogleGeocodingService();
                var coords   = geocoder.GetCoordinate(viewModel.Establishment.Address);
                viewModel.Establishment.Latitude  = coords.Latitude;
                viewModel.Establishment.Longitude = coords.Longitude;
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Não foi possível localizar o endereço. Detalhes: " + ex.Message);
            }

            if (ModelState.IsValid)
            {
                if (ExistsEstablishment(viewModel.Establishment.Name))
                {
                    ModelState.AddModelError("", string.Format("O Estabelecimento \"{0}\" já está cadastrado", viewModel.Establishment.Name));
                    return(View(viewModel));
                }

                db.Establishments.Add(viewModel.Establishment);
                db.SaveChanges();

                viewModel.Review.EstablishmentId = viewModel.Establishment.Id;
                viewModel.Review.CreatedDateTime = DateTime.Now;

                db.Reviews.Add(viewModel.Review);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(viewModel));
        }
Ejemplo n.º 12
0
        public ActionResult Edit(Establishment establishment)
        {
            // Geocodes the address.
            try
            {
                var geocoder = new GoogleGeocodingService();
                var coords   = geocoder.GetCoordinate(establishment.Address);
                establishment.Latitude  = coords.Latitude;
                establishment.Longitude = coords.Longitude;
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Não foi possível localizar o endereço. Detalhes: " + ex.Message);
            }

            if (ModelState.IsValid)
            {
                db.Entry(establishment).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(establishment));
        }
Ejemplo n.º 13
0
        public void VerifyCorrectLocationTypesAttachedToMuseumResult()
        {
            String json = Assembly.GetExecutingAssembly().ReadEmbeddedResourceTextFile("Geocoding.Google.GoogleResponse.Museum-FieldMuseum.json");
            Mock <IRestResponse> restResponse = new Mock <IRestResponse>();

            restResponse.Setup(r => r.ResponseStatus).Returns(ResponseStatus.Completed);
            restResponse.Setup(r => r.StatusCode).Returns(System.Net.HttpStatusCode.OK);
            restResponse.Setup(r => r.Content).Returns(json);

            Mock <IRestClient> mockRestClient = new Mock <IRestClient>();

            mockRestClient.Setup(c => c.Execute(It.IsAny <RestRequest>()))
            .Returns(restResponse.Object);

            GoogleGeocodingService service = new GoogleGeocodingService("test", mockRestClient.Object);
            var result = service.GeocodeAddress(It.IsAny <string>());

            // Assert
            result.Value.Count.Should().Be(1);

            result.Value[0].LocationType.Should().HaveFlag(LocationType.BUSINESS);
            result.Value[0].LocationType.Should().HaveFlag(LocationType.MUSEUM);
            result.Value[0].LocationType.Should().HaveFlag(LocationType.POINT_OF_INTEREST);  // Based on the Tourist Attraction flag in Google
        }
Ejemplo n.º 14
0
 public EditModel(ILocationData locationData, GoogleGeocodingService googleGeocodingService)
 {
     this.locationData           = locationData;
     this.googleGeocodingService = googleGeocodingService;
 }