private GeocodingResult ResolveDataInternal(GeocodingArg geocodingArg) { var result = new GeocodingResult(); var uri = new Uri(_mapquestGeocodingSettings.UrlFormated.Replace(LocationTemplate, geocodingArg.GetLocation())); var xDocument = XDocument.Load(_downloader.Download(uri)); const string locationNode = Constants.LocationNode; const string countyAttributeValue = Constants.CountyAttributeValue; const string typeAttributeKey = Constants.TypeAttributeKey; const string latLng = Constants.LatLng; const string latitudeNode = Constants.LatitudeNode; const string longitudeNode = Constants.LongitudeNode; var location = xDocument.Descendants(locationNode).ToArray(); var countyValue = location.Elements().FirstOrDefault(e => e.Attribute(typeAttributeKey).Get(attribute => attribute.Value) == countyAttributeValue).Get(e => e.Value); var latitudeValue = location.Elements().Where(e => e.Name == latLng).Elements(latitudeNode).FirstOrDefault().Get(e => e.Value); var longitudeValue = location.Elements().Where(e => e.Name == latLng).Elements(longitudeNode).FirstOrDefault().Get(e => e.Value); result.County = countyValue; result.Latitude = latitudeValue; result.Longitude = longitudeValue; Logger.WriteDebugInfo(String.Format("MapquestGeocodingDataService.ResolveData ZIP [{0}], State [{1}], City [{2}], Street [{3}], Location [{4}]. Result County [{5}], Latitude [{6}], Longitude [{7}]", geocodingArg.ZIP, geocodingArg.State, geocodingArg.City, geocodingArg.Street, geocodingArg.GetLocation(), result.County, result.Latitude, result.Longitude)); return result; }
public void GetLocation_should_return_all_not_empty_preperties() { //arrange var argument = new GeocodingViewModel { City = "city", State = "st" }; var target = new GeocodingArg(argument); //act var actual = target.GetLocation(); //assert Assert.AreEqual(HttpUtility.UrlEncode(string.Join(",", new[] { argument.City, argument.State })), actual); }