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);
		}
Esempio n. 2
0
		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;
		}
Esempio n. 3
0
		public void ctor_should_initialize_default_value_for_null_reference()
		{
			//arrange
			//act
			var target = new GeocodingArg(default(GeocodingViewModel));
			//assert
			Assert.IsTrue(string.IsNullOrWhiteSpace(target.Street) && string.IsNullOrWhiteSpace(target.City) && string.IsNullOrWhiteSpace(target.State) && string.IsNullOrWhiteSpace(target.ZIP));
		}
Esempio n. 4
0
		public void ResolveData(GeocodingArg geocodingArg, Action<GeocodingResult, bool> asyncCompleted)
		{
			var result = _cacheService.Get<GeocodingResult>(GetCacheKey(geocodingArg), () =>
			{
				return ResolveDataInternal(geocodingArg);
			});

			asyncCompleted(result, true);
		}
Esempio n. 5
0
		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);
		}
Esempio n. 6
0
		public void ctor_should_intialize_properties()
		{
			//arrange
			var expected = new GeocodingViewModel { City = "city", State = "state", Address = "street", ZIP = "zip" };
			//act
			var target = new GeocodingArg(expected);
			//assert
			Assert.AreEqual(expected.City, target.City);
			Assert.AreEqual(expected.State, target.State);
			Assert.AreEqual(expected.Address, target.Street);
			Assert.AreEqual(expected.ZIP, target.ZIP);
		}
Esempio n. 7
0
		public Order SaveGeneralInfo(OrderGeneralInfoViewModel viewModel)
		{
			var companyId = string.IsNullOrWhiteSpace(viewModel.DefaultLenderCompanyId) ? default(int?) : int.Parse(viewModel.DefaultLenderCompanyId);
			var branchId = string.IsNullOrWhiteSpace(viewModel.DefaultLenderBranchId) ? default(int?) : int.Parse(viewModel.DefaultLenderBranchId);

			var order = viewModel.IsNew ? _orderManager.CreateNewOrder(_securityContext.CurrentUser.Id, companyId, branchId) : _orderManager.GetOrderById(viewModel.OrderId);
			CheckOrderAccessForClients(order);

			order.ClientCompanyId = companyId;
			order.ClientCompanyBrancheId = branchId;

			var orderGeneralInfo = order.GeneralInfo == null ? new OrderGeneralInfo() : order.GeneralInfo;
			order.GeneralInfo = orderGeneralInfo;

			orderGeneralInfo.BorrowerFirstName = viewModel.BorrowerFirstName;
			orderGeneralInfo.BorrowerLastName = viewModel.BorrowerLastName;
			orderGeneralInfo.LoanNumber = viewModel.LoanNumber;

			if (orderGeneralInfo.PropertyAddress == null)
				orderGeneralInfo.PropertyAddress = new Address();

			_addressManager.FillAddressWithCounty(orderGeneralInfo.PropertyAddress, viewModel.Address);

			var geocodingAddress = new GeocodingArg(viewModel.Address.Street, viewModel.Address.City, viewModel.Address.State, viewModel.Address.ZIP);
			_geocodingDataService.ResolveData(geocodingAddress, (location, containResult) =>
			{
				double latitube;
				double longitude;
				Double.TryParse(location.Latitude, out latitube);
				Double.TryParse(location.Longitude, out longitude);
				order.Latitude = latitube;
				order.Longitude = longitude;
				order.GeocodingCounty = location.County;
			});

			return order;
		}
Esempio n. 8
0
		private string GetCacheKey(GeocodingArg geocodingArg)
		{
			return String.Format("{0}{1}{2}{3}", geocodingArg.City, geocodingArg.State, geocodingArg.Street, geocodingArg.ZIP);
		}
Esempio n. 9
0
		private bool ResolveGeocoding(AppraiserFilter appraiserFilter, string street, string city, string state, string zip)
		{
			var geocodingAddress = new GeocodingArg(
				street,
				city,
				state,
				zip);

			var geocodingIsResolved = false;
			_geocodingDataService.ResolveData(geocodingAddress, (location, containResult) =>
			{
				if (containResult && !string.IsNullOrEmpty(location.County))
					geocodingIsResolved = true;

				var filter = appraiserFilter;
				var appraisers = _appraisalCompanyAdminManagement.GetAppraiserUsersListByFilter(filter);
				foreach (var appraiser in appraisers)
				{
					float longitude;
					if (float.TryParse(location.Longitude, out longitude))
					{
						appraiser.ServiceArea.Longitude = longitude;
					}
					float latitude;
					if (float.TryParse(location.Latitude, out latitude))
					{
						appraiser.ServiceArea.Latitude = latitude;
					}
					_appraisalCompanyAdminManagement.Update(appraiser);
				}
			}
			);
			return geocodingIsResolved;
		}