MongoDB.DriverUnitTests.MongoCollectionTests.TestFindNearSphericalTrue C# (CSharp) Метод

TestFindNearSphericalTrue() приватный Метод

private TestFindNearSphericalTrue ( ) : void
Результат void
        public void TestFindNearSphericalTrue()
        {
            if (_server.BuildInfo.Version >= new Version(1, 7, 0, 0))
            {
                if (_collection.Exists()) { _collection.Drop(); }
                _collection.Insert(new Place { Location = new[] { -74.0, 40.74 }, Name = "10gen", Type = "Office" });
                _collection.Insert(new Place { Location = new[] { -75.0, 40.74 }, Name = "Two", Type = "Coffee" });
                _collection.Insert(new Place { Location = new[] { -74.0, 41.73 }, Name = "Three", Type = "Coffee" });
                _collection.CreateIndex(IndexKeys.GeoSpatial("Location"));

                var query = Query.Near("Location", -74.0, 40.74, double.MaxValue, true); // spherical
                var hits = _collection.Find(query).ToArray();
                Assert.AreEqual(3, hits.Length);

                var hit0 = hits[0];
                Assert.AreEqual(-74.0, hit0["Location"][0].AsDouble);
                Assert.AreEqual(40.74, hit0["Location"][1].AsDouble);
                Assert.AreEqual("10gen", hit0["Name"].AsString);
                Assert.AreEqual("Office", hit0["Type"].AsString);

                // with spherical true "Two" is considerably closer than "Three"
                var hit1 = hits[1];
                Assert.AreEqual(-75.0, hit1["Location"][0].AsDouble);
                Assert.AreEqual(40.74, hit1["Location"][1].AsDouble);
                Assert.AreEqual("Two", hit1["Name"].AsString);
                Assert.AreEqual("Coffee", hit1["Type"].AsString);

                var hit2 = hits[2];
                Assert.AreEqual(-74.0, hit2["Location"][0].AsDouble);
                Assert.AreEqual(41.73, hit2["Location"][1].AsDouble);
                Assert.AreEqual("Three", hit2["Name"].AsString);
                Assert.AreEqual("Coffee", hit2["Type"].AsString);

                query = Query.Near("Location", -74.0, 40.74, 0.5); // with maxDistance
                hits = _collection.Find(query).ToArray();
                Assert.AreEqual(1, hits.Length);

                hit0 = hits[0];
                Assert.AreEqual(-74.0, hit0["Location"][0].AsDouble);
                Assert.AreEqual(40.74, hit0["Location"][1].AsDouble);
                Assert.AreEqual("10gen", hit0["Name"].AsString);
                Assert.AreEqual("Office", hit0["Type"].AsString);

                query = Query.Near("Location", -174.0, 40.74, 0.5); // with no hits
                hits = _collection.Find(query).ToArray();
                Assert.AreEqual(0, hits.Length);
            }
        }