Ejemplo n.º 1
0
        public void Filter_get_and_set_should_work(
            [Values(null, "{ x : 1 }", "{ x : 2 }")]
            string valueString)
        {
            var subject = new GeoNearOperation <BsonDocument>(_collectionNamespace, _near, _resultSerializer, _messageEncoderSettings);
            var value   = valueString == null ? null : BsonDocument.Parse(valueString);

            subject.Filter = value;
            var result = subject.Filter;

            result.Should().BeSameAs(value);
        }
Ejemplo n.º 2
0
        public void MaxTime_set_should_throw_when_value_is_invalid(
            [Values(-10001, -9999, -1)] long maxTimeTicks)
        {
            var subject = new GeoNearOperation <BsonDocument>(_collectionNamespace, _near, _resultSerializer, _messageEncoderSettings);
            var value   = TimeSpan.FromTicks(maxTimeTicks);

            var exception = Record.Exception(() => subject.MaxTime = value);

            var e = exception.Should().BeOfType <ArgumentOutOfRangeException>().Subject;

            e.ParamName.Should().Be("value");
        }
        public void Collation_get_and_set_should_work(
            [Values(null, "en_US", "fr_CA")]
            string locale)
        {
            var subject = new GeoNearOperation <BsonDocument>(_collectionNamespace, _near, _resultSerializer, _messageEncoderSettings);
            var value   = locale == null ? null : new Collation(locale);

            subject.Collation = value;
            var result = subject.Collation;

            result.Should().BeSameAs(value);
        }
Ejemplo n.º 4
0
        public void ReadConcern_get_and_set_should_work(
            [Values(ReadConcernLevel.Linearizable, ReadConcernLevel.Local)]
            ReadConcernLevel level)
        {
            var subject = new GeoNearOperation <BsonDocument>(_collectionNamespace, _near, _resultSerializer, _messageEncoderSettings);
            var value   = new ReadConcern(level);

            subject.ReadConcern = value;
            var result = subject.ReadConcern;

            result.Should().Be(value);
        }
Ejemplo n.º 5
0
        public void MaxTime_get_and_set_should_work(
            [Values(null, 1, 2)]
            int?seconds)
        {
            var subject = new GeoNearOperation <BsonDocument>(_collectionNamespace, _near, _resultSerializer, _messageEncoderSettings);
            var value   = seconds.HasValue ? TimeSpan.FromSeconds(seconds.Value) : (TimeSpan?)null;

            subject.MaxTime = value;
            var result = subject.MaxTime;

            result.Should().Be(value);
        }
Ejemplo n.º 6
0
        public void Execute_should_return_expected_result(
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check();
            EnsureTestData();
            var subject = new GeoNearOperation <BsonDocument>(_collectionNamespace, _near, _resultSerializer, _messageEncoderSettings);

            var result = ExecuteOperation(subject, async);

            result["results"].AsBsonArray.Count.Should().Be(5);
            result["results"].AsBsonArray.Select(i => i["dis"].ToDouble()).Should().BeInAscendingOrder();
        }
Ejemplo n.º 7
0
        public void CreateCommand_should_throw_when_ReadConcern_is_set_but_not_supported()
        {
            var subject = new GeoNearOperation <BsonDocument>(_collectionNamespace, _near, _resultSerializer, _messageEncoderSettings)
            {
                ReadConcern = new ReadConcern(ReadConcernLevel.Local)
            };

            var connectionDescription = OperationTestHelper.CreateConnectionDescription(Feature.ReadConcern.LastNotSupportedVersion);
            var session = OperationTestHelper.CreateSession();

            var exception = Record.Exception(() => subject.CreateCommand(connectionDescription, session));

            exception.Should().BeOfType <MongoClientException>();
        }
Ejemplo n.º 8
0
        public void Execute_should_throw_when_maxTime_is_exceeded(
            [Values(false, true)] bool async)
        {
            RequireServer.Check().Supports(Feature.FailPoints).ClusterTypes(ClusterType.Standalone, ClusterType.ReplicaSet);
            var subject = new GeoNearOperation <BsonDocument>(_collectionNamespace, _near, _resultSerializer, _messageEncoderSettings);

            subject.MaxTime = TimeSpan.FromSeconds(9001);

            using (var failPoint = FailPoint.ConfigureAlwaysOn(CoreTestConfiguration.Cluster, _session, FailPointName.MaxTimeAlwaysTimeout))
            {
                var exception = Record.Exception(() => ExecuteOperation(subject, failPoint.Binding, async));

                exception.Should().BeOfType <MongoExecutionTimeoutException>();
            }
        }
Ejemplo n.º 9
0
        public void CreateCommand_should_return_expected_result()
        {
            var subject = new GeoNearOperation <BsonDocument>(_collectionNamespace, _near, _resultSerializer, _messageEncoderSettings);

            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "geoNear", _collectionNamespace.CollectionName },
                { "near", new BsonArray {
                      1, 2
                  } }
            };

            result.Should().Be(expectedResult);
        }
        public void Execute_should_return_expected_result(
            [Values(false, true)]
            bool async)
        {
            var subject = new GeoNearOperation <BsonDocument>(
                _collectionNamespace,
                new BsonArray {
                1, 2
            },
                BsonDocumentSerializer.Instance,
                _messageEncoderSettings);

            var result = ExecuteOperation(subject, async);

            result["results"].Should().NotBeNull();
        }
Ejemplo n.º 11
0
        public void constructor_should_initialize_instance()
        {
            var subject = new GeoNearOperation <BsonDocument>(_collectionNamespace, _near, _resultSerializer, _messageEncoderSettings);

            subject.CollectionNamespace.Should().BeSameAs(_collectionNamespace);
            subject.Near.Should().BeSameAs(_near);
            subject.ResultSerializer.Should().BeSameAs(_resultSerializer);
            subject.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings);

            subject.Collation.Should().BeNull();
            subject.DistanceMultiplier.Should().NotHaveValue();
            subject.Filter.Should().BeNull();
            subject.IncludeLocs.Should().NotHaveValue();
            subject.Limit.Should().NotHaveValue();
            subject.MaxDistance.Should().NotHaveValue();
            subject.MaxTime.Should().NotHaveValue();
            subject.ReadConcern.Should().BeSameAs(ReadConcern.Default);
            subject.Spherical.Should().NotHaveValue();
            subject.UniqueDocs.Should().NotHaveValue();
        }
Ejemplo n.º 12
0
        public void Execute_should_return_expected_result_when_Collation_is_set(
            [Values(false, true)]
            bool caseSensitive,
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check().Supports(Feature.Collation);
            EnsureTestData();
            var collation = new Collation("en_US", caseLevel: caseSensitive, strength: CollationStrength.Primary);
            var filter    = BsonDocument.Parse("{ x : 'x' }");
            var subject   = new GeoNearOperation <BsonDocument>(_collectionNamespace, _near, _resultSerializer, _messageEncoderSettings)
            {
                Collation = collation,
                Filter    = filter
            };

            var result = ExecuteOperation(subject, async);

            result["results"].AsBsonArray.Count.Should().Be(caseSensitive ? 2 : 5);
            result["results"].AsBsonArray.Select(i => i["dis"].ToDouble()).Should().BeInAscendingOrder();
        }
Ejemplo n.º 13
0
        public void CreateCommand_should_return_expected_result_when_Limit_is_set(
            [Values(null, 1, 2)]
            int?limit)
        {
            var subject = new GeoNearOperation <BsonDocument>(_collectionNamespace, _near, _resultSerializer, _messageEncoderSettings)
            {
                Limit = limit
            };

            var result = subject.CreateCommand(Feature.Collation.FirstSupportedVersion);

            var expectedResult = new BsonDocument
            {
                { "geoNear", _collectionNamespace.CollectionName },
                { "near", new BsonArray {
                      1, 2
                  } },
                { "limit", () => limit.Value, limit.HasValue }
            };

            result.Should().Be(expectedResult);
        }
Ejemplo n.º 14
0
        public void CreateCommand_should_return_expected_result_when_MaxDistance_is_set(
            [Values(null, 1.0, 2.0)]
            double?maxDistance)
        {
            var subject = new GeoNearOperation <BsonDocument>(_collectionNamespace, _near, _resultSerializer, _messageEncoderSettings)
            {
                MaxDistance = maxDistance
            };

            var result = subject.CreateCommand(Feature.Collation.FirstSupportedVersion);

            var expectedResult = new BsonDocument
            {
                { "geoNear", _collectionNamespace.CollectionName },
                { "near", new BsonArray {
                      1, 2
                  } },
                { "maxDistance", () => maxDistance.Value, maxDistance.HasValue }
            };

            result.Should().Be(expectedResult);
        }
Ejemplo n.º 15
0
        public void CreateCommand_should_return_expected_result_when_UniqueDocs_is_set(
            [Values(null, false, true)]
            bool?uniqueDocs)
        {
            var subject = new GeoNearOperation <BsonDocument>(_collectionNamespace, _near, _resultSerializer, _messageEncoderSettings)
            {
                UniqueDocs = uniqueDocs
            };

            var result = subject.CreateCommand(Feature.Collation.FirstSupportedVersion);

            var expectedResult = new BsonDocument
            {
                { "geoNear", _collectionNamespace.CollectionName },
                { "near", new BsonArray {
                      1, 2
                  } },
                { "uniqueDocs", () => uniqueDocs.Value, uniqueDocs.HasValue }
            };

            result.Should().Be(expectedResult);
        }
Ejemplo n.º 16
0
        public void CreateCommand_should_return_expected_result_when_Collation_is_set(
            [Values(null, "en_US", "fr_CA")]
            string locale)
        {
            var collation = locale == null ? null : new Collation(locale);
            var subject   = new GeoNearOperation <BsonDocument>(_collectionNamespace, _near, _resultSerializer, _messageEncoderSettings)
            {
                Collation = collation
            };

            var result = subject.CreateCommand(Feature.Collation.FirstSupportedVersion);

            var expectedResult = new BsonDocument
            {
                { "geoNear", _collectionNamespace.CollectionName },
                { "near", new BsonArray {
                      1, 2
                  } },
                { "collation", () => collation.ToBsonDocument(), collation != null }
            };

            result.Should().Be(expectedResult);
        }
Ejemplo n.º 17
0
        public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(
            [Values(null, 1, 2)]
            int?seconds)
        {
            var maxTime = seconds.HasValue ? TimeSpan.FromSeconds(seconds.Value) : (TimeSpan?)null;
            var subject = new GeoNearOperation <BsonDocument>(_collectionNamespace, _near, _resultSerializer, _messageEncoderSettings)
            {
                MaxTime = maxTime
            };

            var result = subject.CreateCommand(Feature.Collation.FirstSupportedVersion);

            var expectedResult = new BsonDocument
            {
                { "geoNear", _collectionNamespace.CollectionName },
                { "near", new BsonArray {
                      1, 2
                  } },
                { "maxTimeMS", () => seconds.Value * 1000, seconds.HasValue }
            };

            result.Should().Be(expectedResult);
        }
Ejemplo n.º 18
0
        public void CreateCommand_should_return_expected_result_when_ReadConcern_is_set(
            [Values(null, ReadConcernLevel.Linearizable, ReadConcernLevel.Local)]
            ReadConcernLevel?level)
        {
            var readConcern = new ReadConcern(level);
            var subject     = new GeoNearOperation <BsonDocument>(_collectionNamespace, _near, _resultSerializer, _messageEncoderSettings)
            {
                ReadConcern = readConcern
            };

            var result = subject.CreateCommand(Feature.ReadConcern.FirstSupportedVersion);

            var expectedResult = new BsonDocument
            {
                { "geoNear", _collectionNamespace.CollectionName },
                { "near", new BsonArray {
                      1, 2
                  } },
                { "readConcern", () => readConcern.ToBsonDocument(), !readConcern.IsServerDefault }
            };

            result.Should().Be(expectedResult);
        }
Ejemplo n.º 19
0
        public void CreateCommand_should_return_expected_result_when_Filter_is_set(
            [Values(null, "{ x : 1 }", "{ x : 2 }")]
            string filterString)
        {
            var filter  = filterString == null ? null : BsonDocument.Parse(filterString);
            var subject = new GeoNearOperation <BsonDocument>(_collectionNamespace, _near, _resultSerializer, _messageEncoderSettings)
            {
                Filter = filter
            };

            var result = subject.CreateCommand(Feature.Collation.FirstSupportedVersion);

            var expectedResult = new BsonDocument
            {
                { "geoNear", _collectionNamespace.CollectionName },
                { "near", new BsonArray {
                      1, 2
                  } },
                { "query", () => filter, filter != null }
            };

            result.Should().Be(expectedResult);
        }
Ejemplo n.º 20
0
        public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(long maxTimeTicks, int expectedMaxTimeMS)
        {
            var subject = new GeoNearOperation <BsonDocument>(_collectionNamespace, _near, _resultSerializer, _messageEncoderSettings)
            {
                MaxTime = TimeSpan.FromTicks(maxTimeTicks)
            };

            var connectionDescription = OperationTestHelper.CreateConnectionDescription(Feature.Collation.FirstSupportedVersion);
            var session = OperationTestHelper.CreateSession();

            var result = subject.CreateCommand(connectionDescription, session);

            var expectedResult = new BsonDocument
            {
                { "geoNear", _collectionNamespace.CollectionName },
                { "near", new BsonArray {
                      1, 2
                  } },
                { "maxTimeMS", expectedMaxTimeMS }
            };

            result.Should().Be(expectedResult);
            result["maxTimeMS"].BsonType.Should().Be(BsonType.Int32);
        }