public void ResolveData_should_parse_data() { //arrange const string urlFormated = "http://someurl/{location}"; const string street = "some street"; Settings.UrlFormated.Returns(urlFormated); var argument = new GeocodingArg(new GeocodingViewModel { Address = street }); var actualRespone = GetResourceString(TestCase1); const string expectedCounty = "some county"; const string expectedLantitude = "lantitude"; const string expectedLongitude = "longitude"; actualRespone = actualRespone.Replace(Constants.Country, expectedCounty); actualRespone = actualRespone.Replace(Constants.Lantitude, expectedLantitude); actualRespone = actualRespone.Replace(Constants.Longitude, expectedLongitude); var resultStream = new MemoryStream(Encoding.UTF8.GetBytes(actualRespone)); Downloader.Download(Arg.Any<Uri>()).ReturnsForAnyArgs(resultStream); //act var actual = new GeocodingResult(); Target.ResolveData(argument, (result, containValue) => actual = result); //assert Assert.AreEqual(expectedCounty, actual.County); Assert.AreEqual(expectedLantitude, actual.Latitude); Assert.AreEqual(expectedLongitude, actual.Longitude); }
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 JsonResult ResolveRequestCompleted(GeocodingResult result, bool containResult, int? editUserId) { float latitude; float longitude; float.TryParse(result.Latitude, out latitude); float.TryParse(result.Longitude, out longitude); return Json(new { resolverRequest = containResult, county = result.County, latitude, longitude }, JsonRequestBehavior.AllowGet); }