Skip to content

Commit c3ac1e4

Browse files
author
rstam
committed
CSHARP-950: Skip GeoJson integration tests when connected to older servers that don't support GeoJson.
1 parent 26f88b2 commit c3ac1e4

File tree

3 files changed

+45
-34
lines changed

3 files changed

+45
-34
lines changed

MongoDB.Driver/Communication/FeatureDetection/FeatureSetDetector.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ internal class FeatureSetDetector
3131
// added in 2.4.0
3232
new FeatureSetDependency(
3333
new ServerVersionDependency(2, 4, 0),
34+
FeatureId.GeoJson,
3435
FeatureId.TextSearchCommand),
3536

3637
// added in 2.6.0

MongoDB.Driver/FeatureId.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public enum FeatureId
4545
/// </summary>
4646
MaxTime,
4747
/// <summary>
48+
/// The GeoJson data and query feature.
49+
/// </summary>
50+
GeoJson,
51+
/// <summary>
4852
/// The parallel scan command.
4953
/// </summary>
5054
ParallelScanCommand,

MongoDB.DriverUnitTests/Builders/QueryBuilderTests.cs

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -511,45 +511,51 @@ public void TestNearWithGeoJson()
511511
[Test]
512512
public void TestNearWithGeoJsonWithMaxDistance()
513513
{
514-
var point = GeoJson.Point(GeoJson.Geographic(40, 18));
515-
var query = Query.Near("loc", point, 42);
516-
var expected = "{ 'loc' : { '$near' : { '$geometry' : { 'type' : 'Point', 'coordinates' : [40.0, 18.0] }, '$maxDistance' : 42.0 } } }".Replace("'", "\"");
517-
Assert.AreEqual(expected, query.ToJson());
518-
519-
var collection = Configuration.TestCollection;
520-
collection.Drop();
521-
collection.CreateIndex(IndexKeys.GeoSpatialSpherical("loc"));
522-
collection.Insert(new BsonDocument { { "_id", 1 }, { "loc", GeoJson.Point(GeoJson.Geographic(1, 1)).ToBsonDocument() } });
523-
collection.Insert(new BsonDocument { { "_id", 2 }, { "loc", GeoJson.Point(GeoJson.Geographic(2, 2)).ToBsonDocument() } });
524-
525-
var circumferenceOfTheEarth = 40075000; // meters at the equator, approx
526-
var metersPerDegree = circumferenceOfTheEarth / 360.0;
527-
query = Query.Near("loc", GeoJson.Point(GeoJson.Geographic(0, 0)), 2.0 * metersPerDegree);
528-
var results = collection.Find(query).ToList();
529-
Assert.AreEqual(1, results.Count);
530-
Assert.AreEqual(1, results[0]["_id"].ToInt32());
514+
if (_primary.Supports(FeatureId.GeoJson))
515+
{
516+
var point = GeoJson.Point(GeoJson.Geographic(40, 18));
517+
var query = Query.Near("loc", point, 42);
518+
var expected = "{ 'loc' : { '$near' : { '$geometry' : { 'type' : 'Point', 'coordinates' : [40.0, 18.0] }, '$maxDistance' : 42.0 } } }".Replace("'", "\"");
519+
Assert.AreEqual(expected, query.ToJson());
520+
521+
var collection = Configuration.TestCollection;
522+
collection.Drop();
523+
collection.CreateIndex(IndexKeys.GeoSpatialSpherical("loc"));
524+
collection.Insert(new BsonDocument { { "_id", 1 }, { "loc", GeoJson.Point(GeoJson.Geographic(1, 1)).ToBsonDocument() } });
525+
collection.Insert(new BsonDocument { { "_id", 2 }, { "loc", GeoJson.Point(GeoJson.Geographic(2, 2)).ToBsonDocument() } });
526+
527+
var circumferenceOfTheEarth = 40075000; // meters at the equator, approx
528+
var metersPerDegree = circumferenceOfTheEarth / 360.0;
529+
query = Query.Near("loc", GeoJson.Point(GeoJson.Geographic(0, 0)), 2.0 * metersPerDegree);
530+
var results = collection.Find(query).ToList();
531+
Assert.AreEqual(1, results.Count);
532+
Assert.AreEqual(1, results[0]["_id"].ToInt32());
533+
}
531534
}
532535

533536
[Test]
534537
public void TestNearWithGeoJsonWithSpherical()
535538
{
536-
var point = GeoJson.Point(GeoJson.Geographic(40, 18));
537-
var query = Query.Near("loc", point, 42, true);
538-
var expected = "{ 'loc' : { '$nearSphere' : { '$geometry' : { 'type' : 'Point', 'coordinates' : [40.0, 18.0] }, '$maxDistance' : 42.0 } } }".Replace("'", "\"");
539-
Assert.AreEqual(expected, query.ToJson());
540-
541-
var collection = Configuration.TestCollection;
542-
collection.Drop();
543-
collection.CreateIndex(IndexKeys.GeoSpatialSpherical("loc"));
544-
collection.Insert(new BsonDocument { { "_id", 1 }, { "loc", GeoJson.Point(GeoJson.Geographic(1, 1)).ToBsonDocument() } });
545-
collection.Insert(new BsonDocument { { "_id", 2 }, { "loc", GeoJson.Point(GeoJson.Geographic(2, 2)).ToBsonDocument() } });
546-
547-
var circumferenceOfTheEarth = 40075000; // meters at the equator, approx
548-
var metersPerDegree = circumferenceOfTheEarth / 360.0;
549-
query = Query.Near("loc", GeoJson.Point(GeoJson.Geographic(0, 0)), 2.0 * metersPerDegree, true);
550-
var results = collection.Find(query).ToList();
551-
Assert.AreEqual(1, results.Count);
552-
Assert.AreEqual(1, results[0]["_id"].ToInt32());
539+
if (_primary.Supports(FeatureId.GeoJson))
540+
{
541+
var point = GeoJson.Point(GeoJson.Geographic(40, 18));
542+
var query = Query.Near("loc", point, 42, true);
543+
var expected = "{ 'loc' : { '$nearSphere' : { '$geometry' : { 'type' : 'Point', 'coordinates' : [40.0, 18.0] }, '$maxDistance' : 42.0 } } }".Replace("'", "\"");
544+
Assert.AreEqual(expected, query.ToJson());
545+
546+
var collection = Configuration.TestCollection;
547+
collection.Drop();
548+
collection.CreateIndex(IndexKeys.GeoSpatialSpherical("loc"));
549+
collection.Insert(new BsonDocument { { "_id", 1 }, { "loc", GeoJson.Point(GeoJson.Geographic(1, 1)).ToBsonDocument() } });
550+
collection.Insert(new BsonDocument { { "_id", 2 }, { "loc", GeoJson.Point(GeoJson.Geographic(2, 2)).ToBsonDocument() } });
551+
552+
var circumferenceOfTheEarth = 40075000; // meters at the equator, approx
553+
var metersPerDegree = circumferenceOfTheEarth / 360.0;
554+
query = Query.Near("loc", GeoJson.Point(GeoJson.Geographic(0, 0)), 2.0 * metersPerDegree, true);
555+
var results = collection.Find(query).ToList();
556+
Assert.AreEqual(1, results.Count);
557+
Assert.AreEqual(1, results[0]["_id"].ToInt32());
558+
}
553559
}
554560

555561
[Test]

0 commit comments

Comments
 (0)