Beispiel #1
0
        /// <summary>
        /// Gets the spatial record parcel count within a specified polygon.
        /// </summary>
        /// <param name="authKey">The authentication key to access SWS.</param>
        /// <param name="polygonWkt">The polygon, in well-known text (WKT) format.</param>
        /// <param name="bundle">The bundle.</param>
        /// <param name="excludeNonSolicitationStates">
        /// Exclude parcels in states in which owner cannot be solicited.
        /// </param>
        /// <returns>The number of parcels within the specified polygon.</returns>
        public int GetSpatialRecordParcelCount(
            string authKey,
            string polygonWkt,
            SpatialRecordBundle bundle        = SpatialRecordBundle.SpatialRecordOGPremium,
            bool excludeNonSolicitationStates = false)
        {
            var polygon = this.wktReader.Read(polygonWkt);

            if (excludeNonSolicitationStates && this.nonSolicitationArea.Intersects(polygon))
            {
                return(this.GetSpatialRecordParcels(authKey, polygonWkt, bundle, true).Length);
            }
            else
            {
                var content = new SpatialRecordPolygonRequest(authKey, polygonWkt, 1, 1, bundle);

                var request = this.CreateSpatialRecordTask(HttpMethod.Post, content);
                request.Wait();

                var response = request.Result.Content.ReadAsAsync <SpatialRecordResponse>();
                response.Wait();

                return(response.Result.PageInfo.Length);
            }
        }
Beispiel #2
0
        public void GetSpatialRecordParcelsByPolygonWithNoAuthKeyCausesAuthentication()
        {
            this.AddFakeAuthenticateSuccessResponse();

            var polygonWkt = "Polygon((-77.1 38.9,-77.1 39,-77 39,-77 38.9,-77.1 38.9))";

            this.fakeResponseHandler.AddFakePostResponse(
                new Uri(this.config.Object.EndpointUrl + "parcels"),
                (requestContent) =>
            {
                var expectedRequest = new SpatialRecordPolygonRequest("NewAuthKey", polygonWkt);

                var actualRequest = JsonConvert.DeserializeObject <SpatialRecordPolygonRequest>(requestContent);

                Assert.True(
                    new GenericEqualityComparer <SpatialRecordPolygonRequest>().Equals(
                        expectedRequest,
                        actualRequest));

                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(
                        SwsSamples.SpatialRecordSuccess, Encoding.Unicode, "application/json")
                });
            });

            this.sut.GetSpatialRecordParcels(polygonWkt);
        }
Beispiel #3
0
        public void GetSpatialRecordParcelCountReturnsCount()
        {
            var polygonWkt = "Polygon((-77.1 38.9,-77.1 39,-77 39,-77 38.9,-77.1 38.9))";

            this.fakeResponseHandler.AddFakePostResponse(
                new Uri(string.Format(
                            "{0}parcels",
                            this.config.Object.EndpointUrl)),
                (requestContent) =>
            {
                var expectedRequest = new SpatialRecordPolygonRequest(AuthKey, polygonWkt, 1, 1);

                var actualRequest = JsonConvert.DeserializeObject <SpatialRecordPolygonRequest>(requestContent);

                Assert.True(
                    new GenericEqualityComparer <SpatialRecordPolygonRequest>().Equals(
                        expectedRequest,
                        actualRequest));

                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(
                        SwsSamples.SpatialRecordSuccess, Encoding.Unicode, "application/json")
                });
            });

            var count = this.sut.GetSpatialRecordParcelCount(AuthKey, polygonWkt);

            Assert.Equal(1, count);
        }
Beispiel #4
0
        public void GetSpatialRecordParcelsExcludingNonSolicitationStatesReturnsFilteredResults()
        {
            var polygonWkt   = "POLYGON((-112.04184651374817 43.49312138312793,-112.04257071018219 43.49218348707646,-112.03920185565948 43.49085639765385,-112.03851521015167 43.491767072127324,-112.04184651374817 43.49312138312793))";
            var requestCount = 0;

            this.fakeResponseHandler.AddFakePostResponse(
                new Uri(string.Format(
                            "{0}parcels",
                            this.config.Object.EndpointUrl)),
                (requestContent) =>
            {
                requestCount++;
                Assert.InRange(requestCount, 1, 2);

                var actualRequest   = JsonConvert.DeserializeObject <SpatialRecordPolygonRequest>(requestContent);
                var expectedRequest = new SpatialRecordPolygonRequest(AuthKey, polygonWkt, requestCount);

                Assert.True(
                    new GenericEqualityComparer <SpatialRecordPolygonRequest>().Equals(
                        expectedRequest,
                        actualRequest));

                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(
                        (requestCount == 1) ?
                        SwsSamples.SpatialRecordLargePage1 : SwsSamples.SpatialRecordLargePage2,
                        Encoding.Unicode,
                        "application/json")
                });
            });

            var response = this.sut.GetSpatialRecordParcels(AuthKey, polygonWkt, excludeNonSolicitationStates: true);

            Assert.Equal(30, response.Length);
        }