Пример #1
0
        public async Task GetSiteAddressesAsync_Format_Success()
        {
            // Arrange
            var helper  = new TestHelper();
            var options = Options.Create(new GeocoderOptions()
            {
                Key = "test"
            });
            var mockRequestClient = new Mock <IHttpRequestClient>();
            var features          = new FeatureCollectionModel()
            {
                Type = "Feature"
            };
            var response      = new HttpResponseMessage(HttpStatusCode.OK);
            var clientFactory = helper.CreateHttpClientFactory(response);

            mockRequestClient.Setup(m => m.Client).Returns(clientFactory.CreateClient());
            mockRequestClient.Setup(m => m.GetAsync <FeatureCollectionModel>(It.IsAny <string>())).ReturnsAsync(features);
            var service    = helper.Create <GeocoderService>(options, mockRequestClient.Object);
            var parameters = new AddressesParameters()
            {
                AddressString = "address with encoding"
            };

            // Act
            var result = await service.GetSiteAddressesAsync(parameters, "xml");

            // Assert
            var url = "https://geocoder.api.gov.bc.ca/addresses.xml?ver=1.2&addressString=address%20with%20encoding&maxResults=5&interpolation=adaptive&echo=false&autoComplete=false&minScore=0&maxDistance=0&extrapolate=false&outputSRS=4326&locationDescriptor=any&setBack=0&brief=false";

            result.Should().NotBeNull();
            mockRequestClient.Verify(m => m.GetAsync <FeatureCollectionModel>(url), Times.Once());
            result.Should().Be(features);
        }
Пример #2
0
        /// <summary>
        /// Sends an HTTP request to Geocoder for addresses that match the specified 'parameters'.
        /// </summary>
        /// <param name="parameters">The address search paramenters</param>
        /// <param name="outputFormat">The output format. Defaults to "json"</param>
        /// <returns></returns>
        public async Task <FeatureCollectionModel> GetSiteAddressesAsync(AddressesParameters parameters, string outputFormat = "json")
        {
            var uri = new Uri(GenerateUrl(this.Options.Sites.AddressesUrl, outputFormat));
            var url = QueryHelpers.AddQueryString(uri.AbsoluteUri, parameters.ToQueryStringDictionary());

            return(await this.Client.GetAsync <FeatureCollectionModel>(url));
        }
Пример #3
0
        /// <summary>
        /// Sends an HTTP request to Geocoder for addresses that match the specified 'address'.
        /// </summary>
        /// <param name="address">The address to geocode</param>
        /// <param name="outputFormat">The output format. Defaults to "json"</param>
        /// <returns></returns>
        public async Task <FeatureCollectionModel> GetSiteAddressesAsync(string address, string outputFormat = "json")
        {
            var parameters = new AddressesParameters()
            {
                AddressString = WebUtility.UrlEncode(address)
            };

            return(await GetSiteAddressesAsync(parameters, outputFormat));
        }
Пример #4
0
        public void ToQueryStringDictionary_Success(AddressesParameters address)
        {
            // Arrange
            // Act
            var result = address.ToQueryStringDictionary();

            // Assert
            result.Should().NotBeNull();
            result[nameof(address.MaxResults).LowercaseFirstCharacter()].Should().Be($"{address.MaxResults}");
            result[nameof(address.Echo).LowercaseFirstCharacter()].Should().Be($"{address.Echo}".ToLower());
            result[nameof(address.Brief).LowercaseFirstCharacter()].Should().Be($"{address.Brief}".ToLower());
            result[nameof(address.AutoComplete).LowercaseFirstCharacter()].Should().Be($"{address.AutoComplete}".ToLower());
            result[nameof(address.SetBack).LowercaseFirstCharacter()].Should().Be($"{address.SetBack}");
            result[nameof(address.OutputSRS).LowercaseFirstCharacter()].Should().Be($"{address.OutputSRS}");
            result[nameof(address.MinScore).LowercaseFirstCharacter()].Should().Be($"{address.MinScore}");
            result[nameof(address.MaxDistance).LowercaseFirstCharacter()].Should().Be($"{address.MaxDistance}");
            result[nameof(address.Extrapolate).LowercaseFirstCharacter()].Should().Be($"{address.Extrapolate}".ToLower());
            if (!String.IsNullOrWhiteSpace(address.Interpolation))
            {
                result[nameof(address.Interpolation).LowercaseFirstCharacter()].Should().Be(address.Interpolation);
            }
            if (!String.IsNullOrWhiteSpace(address.Ver))
            {
                result[nameof(address.Ver).LowercaseFirstCharacter()].Should().Be(address.Ver);
            }
            if (!String.IsNullOrWhiteSpace(address.AddressString))
            {
                result[nameof(address.AddressString).LowercaseFirstCharacter()].Should().Be(address.AddressString);
            }
            if (!String.IsNullOrWhiteSpace(address.LocationDescriptor))
            {
                result[nameof(address.LocationDescriptor).LowercaseFirstCharacter()].Should().Be(address.LocationDescriptor);
            }
            if (!String.IsNullOrWhiteSpace(address.MatchPrecision))
            {
                result[nameof(address.MatchPrecision).LowercaseFirstCharacter()].Should().Be(address.MatchPrecision);
            }
            if (!String.IsNullOrWhiteSpace(address.MatchPrecisionNot))
            {
                result[nameof(address.MatchPrecisionNot).LowercaseFirstCharacter()].Should().Be(address.MatchPrecisionNot);
            }
            if (!String.IsNullOrWhiteSpace(address.SiteName))
            {
                result[nameof(address.SiteName).LowercaseFirstCharacter()].Should().Be(address.SiteName);
            }
            if (!String.IsNullOrWhiteSpace(address.UnitDesignator))
            {
                result[nameof(address.UnitDesignator).LowercaseFirstCharacter()].Should().Be(address.UnitDesignator);
            }
            if (!String.IsNullOrWhiteSpace(address.UnitNumber))
            {
                result[nameof(address.UnitNumber).LowercaseFirstCharacter()].Should().Be(address.UnitNumber);
            }
            if (!String.IsNullOrWhiteSpace(address.UnitNumberSuffix))
            {
                result[nameof(address.UnitNumberSuffix).LowercaseFirstCharacter()].Should().Be(address.UnitNumberSuffix);
            }
            if (!String.IsNullOrWhiteSpace(address.CivicNumber))
            {
                result[nameof(address.CivicNumber).LowercaseFirstCharacter()].Should().Be(address.CivicNumber);
            }
            if (!String.IsNullOrWhiteSpace(address.CivicNumberSuffix))
            {
                result[nameof(address.CivicNumberSuffix).LowercaseFirstCharacter()].Should().Be(address.CivicNumberSuffix);
            }
            if (!String.IsNullOrWhiteSpace(address.StreetName))
            {
                result[nameof(address.StreetName).LowercaseFirstCharacter()].Should().Be(address.StreetName);
            }
            if (!String.IsNullOrWhiteSpace(address.StreetType))
            {
                result[nameof(address.StreetType).LowercaseFirstCharacter()].Should().Be(address.StreetType);
            }
            if (!String.IsNullOrWhiteSpace(address.StreetDirection))
            {
                result[nameof(address.StreetDirection).LowercaseFirstCharacter()].Should().Be(address.StreetDirection);
            }
            if (!String.IsNullOrWhiteSpace(address.StreetQualifier))
            {
                result[nameof(address.StreetQualifier).LowercaseFirstCharacter()].Should().Be(address.StreetQualifier);
            }
            if (!String.IsNullOrWhiteSpace(address.LocalityName))
            {
                result[nameof(address.LocalityName).LowercaseFirstCharacter()].Should().Be(address.LocalityName);
            }
            if (!String.IsNullOrWhiteSpace(address.ProvinceCode))
            {
                result[nameof(address.ProvinceCode).LowercaseFirstCharacter()].Should().Be(address.ProvinceCode);
            }
            if (!String.IsNullOrWhiteSpace(address.Bbox))
            {
                result[nameof(address.Bbox).LowercaseFirstCharacter()].Should().Be(address.Bbox);
            }
            if (!String.IsNullOrWhiteSpace(address.Localities))
            {
                result[nameof(address.Localities).LowercaseFirstCharacter()].Should().Be(address.Localities);
            }
            if (!String.IsNullOrWhiteSpace(address.NotLocalities))
            {
                result[nameof(address.NotLocalities).LowercaseFirstCharacter()].Should().Be(address.NotLocalities);
            }
            if (!String.IsNullOrWhiteSpace(address.Center))
            {
                result[nameof(address.Center).LowercaseFirstCharacter()].Should().Be(address.Center);
            }
            if (!String.IsNullOrWhiteSpace(address.ParcelPoint))
            {
                result[nameof(address.ParcelPoint).LowercaseFirstCharacter()].Should().Be(address.ParcelPoint);
            }
        }