public void Test_RawUri()
        {
            const string expected = "http://localhost:8092/default/_design/testdoc/_spatial/testview?";
            var          query    = new SpatialViewQuery().From("testdoc", "testview");

            Assert.AreEqual(expected, query.RawUri().ToString());
        }
示例#2
0
        public Task <IViewResult <T> > SpatialViewQuery <T>(string designDocument, string viewName, SpatialViewOptions options = default)
        {
            if (options == default)
            {
                options = new SpatialViewOptions();
            }

            var uri = GetViewUri();

            // create old style query
            var query = new SpatialViewQuery(uri)
            {
                UseSsl = _configuration.UseSsl
            };

            query.Bucket(Name);
            query.From(designDocument, viewName);
            query.Stale(options.StaleState);
            query.Skip(options.Skip);
            query.Limit(options.Limit);
            query.StartRange(options.StartRange.ToList());
            query.EndRange(options.EndRange.ToList());
            query.Development(options.Development);
            query.ConnectionTimeout(options.ConnectionTimeout);

            return(_viewClientLazy.Value.ExecuteAsync <T>(query));
        }
        public void When_UseSsl_Is_True_RawUri_Returns_Https()
        {
            const string expected = "https://localhost:18092/default/_design/testdoc/_spatial/testview?";
            var          query    = new SpatialViewQuery().From("testdoc", "testview");

            query.UseSsl = true;

            Assert.AreEqual(expected, query.RawUri().ToString());
        }
        public async Task <ICollection <CrowdsourcedPlace> > GetClosePlaces(SimplePoint start, SimplePoint end)
        {
            var query = new SpatialViewQuery().From("doc", "crowdsourcedpoints")
                        .Stale(StaleState.False)
                        .StartRange(start.Longitude, start.Latitude)
                        .EndRange(end.Longitude, end.Latitude);

            var result = await _bucket.QueryAsync <CrowdsourcedPlace>(query);

            return(result.Rows.Select(x => x.Value).ToList());
        }
        public void When_QueryParams_Are_Set_RawUri_Adds_Them_To_Uri()
        {
            const string queryParams = @"/travel-sample/_design/spatial/_spatial/routes?stale=false&connection_timeout=60000&limit=10&skip=0";

            var query = new SpatialViewQuery().From("spatial", "routes")
                        .Bucket("travel-sample")
                        .Stale(StaleState.False)
                        .ConnectionTimeout(60000)
                        .Limit(10)
                        .Skip(0);
            var uri = query.RawUri();

            Assert.AreEqual(queryParams, uri.PathAndQuery);
        }
        public void When_Geometry_Is_Not_Emitted_By_Map_Function_Geometry_Is_Null()
        {
            using (var cluster = new Cluster(ClientConfigUtil.GetConfiguration()))
            {
                using (var bucket = cluster.OpenBucket("travel-sample"))
                {
                    var query = new SpatialViewQuery().From("spatial", "routes")
                                .Stale(StaleState.False)
                                .ConnectionTimeout(60000)
                                .Limit(1)
                                .Skip(0);

                    var result = bucket.Query <dynamic>(query);
                    Assert.IsNull(result.Rows.First().Geometry);
                }
            }
        }
        public void When_BoundaryBox_Is_Provided_Results_Are_Constrained_By_it()
        {
            using (var cluster = new Cluster(ClientConfigUtil.GetConfiguration()))
            {
                using (var bucket = cluster.OpenBucket("beer-sample"))
                {
                    var query = new SpatialViewQuery().From("beer_ext_spatial", "points")
                                .Stale(StaleState.False)
                                .StartRange(-10.37109375, 33.578014746143985)
                                .EndRange(43.76953125, 71.9653876991313)
                                .ConnectionTimeout(60000)
                                .Limit(1)
                                .Skip(0);

                    var result = bucket.Query <dynamic>(query);
                    Assert.AreEqual(1, result.Rows.Count());
                }
            }
        }
        public void When_StartRange_And_EndRange_Are_Set_They_Are_Added_To_Uri()
        {
            const string queryParams = @"/travel-sample/_design/spatial/_spatial/routes?stale=false&connection_timeout=60000&limit=10&skip=0&start_range=[null,null,10000.0]&end_range=[null,null,null]";

            var query = new SpatialViewQuery().From("spatial", "routes")
                        .Bucket("travel-sample")
                        .Stale(StaleState.False)
                        .ConnectionTimeout(60000)
                        .StartRange(new List <double?> {
                null, null, 10000
            })
                        .EndRange(new List <double?> {
                null, null, null
            })
                        .Limit(10)
                        .Skip(0);
            var uri = query.RawUri();

            Assert.AreEqual(queryParams, uri.PathAndQuery);
        }
        public void When_IBucket_Executes_Query_Uri_Is_Properly_Formed()
        {
            using (var cluster = new Cluster(ClientConfigUtil.GetConfiguration()))
            {
                using (var bucket = cluster.OpenBucket("travel-sample"))
                {
                    var query = new SpatialViewQuery().From("spatial", "routes")
                                .Bucket("travel-sample")
                                .Stale(StaleState.False)
                                .ConnectionTimeout(60000)
                                .Limit(10)
                                .Skip(0);

                    var result = bucket.Query <dynamic>(query);
                    var uri    = query.RawUri();

                    var expected =
                        "/travel-sample/_design/spatial/_spatial/routes?stale=false&connection_timeout=60000&limit=10&skip=0";
                    Assert.AreEqual(expected, uri.PathAndQuery);
                }
            }
        }
        public void Test_Geo_Spatial_View()
        {
            //arrange
            var uriString = ClientConfigUtil.GetConfiguration().Servers.First().ToString();

            uriString = uriString.Replace("8091", "8092").Replace("pools", "travel-sample/");

            var query = new SpatialViewQuery().From("spatial", "routes")
                        .Bucket("travel-sample")
                        .Stale(StaleState.False)
                        .Limit(10)
                        .Skip(0)
                        .BaseUri(new Uri(uriString));

            var client = GetViewClient("travel-sample");

            //act
            var results = client.Execute <dynamic>(query);

            //assert
            Assert.IsTrue(results.Success, results.Error);
        }
        public void Test_Geo_Spatial_View()
        {
            var uriString = ClientConfigUtil.GetConfiguration().Servers.First().ToString();

            uriString = uriString.Replace("8091", "8092");

            var query = new SpatialViewQuery().From("spatial", "routes")
                        .Bucket("travel-sample")
                        .Stale(StaleState.False)
                        .Limit(10)
                        .Skip(0)
                        .BaseUri(new Uri(uriString));

            var client = new ViewClient(new HttpClient(),
                                        new JsonDataMapper(ClientConfigUtil.GetConfiguration()),
                                        new BucketConfig {
                Name = "travel-sample"
            },
                                        new ClientConfiguration());

            var results = client.Execute <dynamic>(query);

            Assert.IsTrue(results.Success, results.Error);
        }