public async Task GetGeocodingInfo_InternalServerError_ReturnsNull() { _messageHandler.SendAsyncReturns(new HttpResponseMessage(HttpStatusCode.InternalServerError)); GeocodingInfo result = await _service.GetGeocodingInfoAsync(Factory.GetString(), Factory.GetString(), "no"); Assert.Null(result); }
public async Task GetGeocodingInfo_ServiceReturnsNull_ReturnsNull() { _messageHandler.SendAsyncReturns(null); GeocodingInfo result = await _service.GetGeocodingInfoAsync(Factory.GetString(), Factory.GetString(), "no"); Assert.Null(result); }
public async Task GetGeocodingInfo_Match_ReturnsCorrectResult() { _messageHandler.SendAsyncReturns(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(GetValidPostalCodeResult()) }); GeocodingInfo result = await _service.GetGeocodingInfoAsync(Factory.GetString(), Factory.GetString(), "no"); Assert.IsType <GeocodingInfo>(result); }
public async Task GetGeocodingInfo_Match_ReturnsCorrectAddress() { _messageHandler.SendAsyncReturns(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(GetValidPostalCodeResult()) }); GeocodingInfo result = await _service.GetGeocodingInfoAsync(Factory.GetString(), Factory.GetString(), "no"); Assert.Equal("0672 Oslo, Norge", result.FormattedAddress); }
public async Task GetGeocodingInfo_DtoStatusNotOk_ReturnsNull() { _messageHandler.SendAsyncReturns(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(GetInvaldResult()) }); GeocodingInfo result = await _service.GetGeocodingInfoAsync(Factory.GetString(), Factory.GetString(), "no"); Assert.Null(result); }
public async Task GetGeocodingInfo_ParseResultFails_ReturnsNull() { _messageHandler.SendAsyncReturns(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{ 'Some': 'random', 'un-parseable': 'json' }") }); GeocodingInfo result = await _service.GetGeocodingInfoAsync(Factory.GetString(), Factory.GetString(), "no"); Assert.Null(result); }
/// <summary> /// Constructor. /// </summary> /// <param name="geocodingServiceInfo">Geocoding service info.</param> /// <param name="geocodeServer">Geocode server.</param> /// <param name="exceptionHandler">Exception handler.</param> internal Geocoder(GeocodingServiceInfo geocodingServiceInfo, AgsServer geocodeServer, IServiceExceptionHandler exceptionHandler) { Debug.Assert(exceptionHandler != null); _exceptionHandler = exceptionHandler; // Init geocoding properties. _propMods = new PropertySet(); _propMods.PropertyArray = new PropertySetProperty[2]; _propMods.PropertyArray[0] = _CreateProp("WritePercentAlongField", "TRUE"); _propMods.PropertyArray[1] = _CreateProp("MatchIfScoresTie", "TRUE"); _geocodingServiceInfo = geocodingServiceInfo; if (_geocodingServiceInfo == null) { throw new SettingsException(Properties.Resources.DefaultGeocodingInfoIsNotSet); } _geocodingServer = geocodeServer; // Create address fields. _CreateAddressFields(); _actualGeocodingInfo = new GeocodingInfo(geocodingServiceInfo); _locatorsInfos = new ReadOnlyCollection<LocatorInfo>( _actualGeocodingInfo.Locators ?? new LocatorInfo[] { }); foreach (var locator in _locatorsInfos) { if (!_locators.ContainsKey(locator.Name)) { _locators.Add(locator.Name, locator); } } var fields = _geocodingServiceInfo.FieldMappings.FieldMapping.Select(mapping => (AddressPart)Enum.Parse( typeof(AddressPart), mapping.AddressField, true)); _defaultLocator = new LocatorInfo( string.Empty, string.Empty, true, true, SublocatorType.Streets, fields); // Geocoder should be initialized later. _inited = false; }