public void CreateCommand_should_create_the_correct_command(
            [Values("3.0.0", "3.2.0")] string serverVersionString,
            [Values(null, ReadConcernLevel.Local, ReadConcernLevel.Majority)] ReadConcernLevel?readConcernLevel)
        {
            var serverVersion = SemanticVersion.Parse(serverVersionString);
            var filter        = new BsonDocument("x", 1);
            var limit         = 10;
            var maxDistance   = 30;
            var maxTime       = TimeSpan.FromMilliseconds(50);
            var near          = new BsonArray {
                10, 20
            };
            var readConcern = new ReadConcern(readConcernLevel);
            var subject     = new GeoSearchOperation <BsonDocument>(_collectionNamespace, near, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                Search      = filter,
                Limit       = limit,
                MaxDistance = maxDistance,
                MaxTime     = maxTime,
                ReadConcern = readConcern
            };

            var connectionDescription = OperationTestHelper.CreateConnectionDescription(serverVersion);
            var session = OperationTestHelper.CreateSession();

            if (!readConcern.IsServerDefault && !Feature.ReadConcern.IsSupported(serverVersion))
            {
                var exception = Record.Exception(() => subject.CreateCommand(connectionDescription, session));

                exception.Should().BeOfType <MongoClientException>();
            }
            else
            {
                var result = subject.CreateCommand(connectionDescription, session);

                var expectedResult = new BsonDocument
                {
                    { "geoSearch", _collectionNamespace.CollectionName },
                    { "near", near },
                    { "limit", limit },
                    { "maxDistance", maxDistance },
                    { "search", filter },
                    { "maxTimeMS", (int)maxTime.TotalMilliseconds },
                    { "readConcern", () => readConcern.ToBsonDocument(), !readConcern.IsServerDefault }
                };
                result.Should().Be(expectedResult);
                result["maxTimeMS"].BsonType.Should().Be(BsonType.Int32);
            }
        }
        public void CreateCommand_should_create_the_correct_command(
            [Values("3.0.0", "3.2.0")] string serverVersion,
            [Values(null, ReadConcernLevel.Local, ReadConcernLevel.Majority)] ReadConcernLevel?readConcernLevel)
        {
            var semanticServerVersion = SemanticVersion.Parse(serverVersion);
            var filter      = new BsonDocument("x", 1);
            var limit       = 10;
            var maxDistance = 30;
            var maxTime     = TimeSpan.FromMilliseconds(50);
            var near        = new BsonArray {
                10, 20
            };
            var subject = new GeoSearchOperation <BsonDocument>(_collectionNamespace, near, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                Search      = filter,
                Limit       = limit,
                MaxDistance = maxDistance,
                MaxTime     = maxTime,
                ReadConcern = new ReadConcern(readConcernLevel)
            };
            var expectedResult = new BsonDocument
            {
                { "geoSearch", _collectionNamespace.CollectionName },
                { "near", near },
                { "limit", limit },
                { "maxDistance", maxDistance },
                { "search", filter },
                { "maxTimeMS", maxTime.TotalMilliseconds }
            };

            if (!subject.ReadConcern.IsServerDefault)
            {
                expectedResult["readConcern"] = subject.ReadConcern.ToBsonDocument();
            }

            if (!subject.ReadConcern.IsSupported(semanticServerVersion))
            {
                Action act = () => subject.CreateCommand(semanticServerVersion);
                act.ShouldThrow <MongoClientException>();
            }
            else
            {
                var result = subject.CreateCommand(semanticServerVersion);
                result.Should().Be(expectedResult);
            }
        }
        public void CreateCommand_should_create_the_correct_command(
            [Values(WireVersion.Server30, WireVersion.Server32)] int maxWireVersion,
            [Values(null, ReadConcernLevel.Local, ReadConcernLevel.Majority)] ReadConcernLevel?readConcernLevel)
        {
            var filter      = new BsonDocument("x", 1);
            var limit       = 10;
            var maxDistance = 30;
            var maxTime     = TimeSpan.FromMilliseconds(50);
            var near        = new BsonArray {
                10, 20
            };
            var readConcern = new ReadConcern(readConcernLevel);
            var subject     = new GeoSearchOperation <BsonDocument>(_collectionNamespace, near, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                Search      = filter,
                Limit       = limit,
                MaxDistance = maxDistance,
                MaxTime     = maxTime,
                ReadConcern = readConcern
            };

            var connectionDescription = OperationTestHelper.CreateConnectionDescription(maxWireVersion);
            var session = OperationTestHelper.CreateSession();

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

            var expectedResult = new BsonDocument
            {
                { "geoSearch", _collectionNamespace.CollectionName },
                { "near", near },
                { "limit", limit },
                { "maxDistance", maxDistance },
                { "search", filter },
                { "maxTimeMS", (int)maxTime.TotalMilliseconds },
                { "readConcern", () => readConcern.ToBsonDocument(), !readConcern.IsServerDefault }
            };

            result.Should().Be(expectedResult);
            result["maxTimeMS"].BsonType.Should().Be(BsonType.Int32);
        }
Esempio n. 4
0
        public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(long maxTimeTicks, int expectedMaxTimeMS)
        {
            var near    = 5;
            var subject = new GeoSearchOperation <BsonDocument>(_collectionNamespace, near, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                MaxTime = TimeSpan.FromTicks(maxTimeTicks)
            };
            var connectionDescription = OperationTestHelper.CreateConnectionDescription();
            var session = OperationTestHelper.CreateSession();

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

            var expectedResult = new BsonDocument
            {
                { "geoSearch", _collectionNamespace.CollectionName },
                { "near", near },
                { "maxTimeMS", expectedMaxTimeMS }
            };

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