예제 #1
0
        public async void BasicCoordinateSearch()
        {
            var sut       = new GeocodingServiceClient(BaseUrl, SessionId, new DummyPackageInfo());
            var addresses = await sut.Search(45.5062, -73.5726);

            Assert.True(addresses.Any());
        }
예제 #2
0
        /// <summary>
        /// Creates a new instance of the <see cref="WorldGeocoder"/> class for the specified
        /// service configuration.
        /// </summary>
        /// <param name="serviceInfo">The instance of the geocoding service configuration
        /// specifying World geocoder service to create geocoder for.</param>
        /// <param name="exceptionHandler">Exception handler.</param>
        /// <returns>A new instance of the <see cref="WorldGeocoder"/> class.</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="serviceInfo"/> is a null
        /// reference.</exception>
        public static GeocoderBase CreateWorldGeocoder(GeocodingServiceInfo serviceInfo,
                                                       IServiceExceptionHandler exceptionHandler)
        {
            CodeContract.RequiresNotNull("serviceInfo", serviceInfo);

            // Create binding for the geocoder REST service.
            var webBinding             = ServiceHelper.CreateWebHttpBinding("WorldGeocoder");
            var binding                = new CustomBinding(webBinding);
            var messageEncodingElement = binding.Elements.Find <WebMessageEncodingBindingElement>();

            messageEncodingElement.ContentTypeMapper = new ArcGisWebContentTypeMapper();

            // Create endpoint for the geocoder REST service.
            var contract       = ContractDescription.GetContract(typeof(IGeocodingService));
            var serviceAddress = new EndpointAddress(serviceInfo.RestUrl);
            var endpoint       = new WebHttpEndpoint(contract, serviceAddress);

            endpoint.Binding = binding;

            // Replace default endpoint behavior with a customized one.
            endpoint.Behaviors.Remove <WebHttpBehavior>();
            endpoint.Behaviors.Add(new GeocodingServiceWebHttpBehavior());

            // Create the geocoder instance.
            var channelFactory = new WebChannelFactory <IGeocodingService>(endpoint);
            var client         = new GeocodingServiceClient(channelFactory, serviceInfo, exceptionHandler);

            return(new WorldGeocoder(serviceInfo, client));
        }
예제 #3
0
        public void BasicNameSearch()
        {
            var sut       = new GeocodingServiceClient(BaseUrl, SessionId, new DummyPackageInfo());
            var addresses = sut.Search("5250 ferrier");

            Assert.True(addresses.Count() == 1);
            Assert.True(addresses.ElementAt(0).FullAddress.Contains("5250"));
        }
예제 #4
0
        public async void DefaultLocationIsAnAddress()
        {
            var sut     = new GeocodingServiceClient(BaseUrl, SessionId, new DummyPackageInfo());
            var address = await sut.DefaultLocation();

            Assert.IsNotNull(address);
            Assert.AreEqual(45.516667, address.Latitude);
            Assert.AreEqual(-73.65, address.Longitude);
        }
예제 #5
0
        public async void SearchMiddleField()
        {
            var sut       = new GeocodingServiceClient(BaseUrl, SessionId, new DummyPackageInfo());
            var addresses = await sut.Search(45.5364, -73.6103);

            Assert.True(addresses.Any());

            Assert.False(addresses.First().StreetNumber.Contains("-"));
            Assert.False(addresses.First().FullAddress.Split(' ')[0].Contains("-"));
        }
예제 #6
0
        public void AdvancedNameSearch()
        {
            var sut       = new GeocodingServiceClient(BaseUrl, SessionId, new DummyPackageInfo());
            var addresses = sut.Search("5661 avenue chateaubriand, Montreal");

            Assert.AreEqual(1, addresses.Count());
            var address = addresses.ElementAt(0);

            Assert.AreEqual(true, address.FullAddress.Contains("Chateaubriand"));
            Assert.AreEqual("5661", address.StreetNumber);
            Assert.AreEqual("Avenue de Chateaubriand", address.Street);
            Assert.AreEqual("Montréal", address.City);
            StringAssert.Contains("H2S", address.ZipCode);
        }