Esempio n. 1
0
        public void CreateCommand_should_create_the_correct_command(
            [Values(null, 10)] int?maxTimeMS,
            [Values(null, "{a: 1}")] string projection,
            [Values(null, "{b: 1}")] string sort,
            [Values(null, "{ w : 2 }")] string writeConcernString,
            [Values("3.0.0", "3.1.1")] string serverVersionString)
        {
            var projectionDoc = projection == null ? (BsonDocument)null : BsonDocument.Parse(projection);
            var sortDoc       = sort == null ? (BsonDocument)null : BsonDocument.Parse(sort);
            var writeConcern  = writeConcernString == null ? null : WriteConcern.FromBsonDocument(BsonDocument.Parse(writeConcernString));
            var serverVersion = SemanticVersion.Parse(serverVersionString);
            var subject       = new FindOneAndDeleteOperation <BsonDocument>(_collectionNamespace, _filter, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                MaxTime      = maxTimeMS.HasValue ? TimeSpan.FromMilliseconds(maxTimeMS.Value) : (TimeSpan?)null,
                Projection   = projectionDoc,
                Sort         = sortDoc,
                WriteConcern = writeConcern
            };

            var expectedResult = new BsonDocument
            {
                { "findAndModify", _collectionNamespace.CollectionName },
                { "query", _filter },
                { "sort", sortDoc, sortDoc != null },
                { "remove", true },
                { "fields", projectionDoc, projectionDoc != null },
                { "maxTimeMS", () => maxTimeMS.Value, maxTimeMS.HasValue },
                { "writeConcern", () => writeConcern.ToBsonDocument(), writeConcern != null && SupportedFeatures.IsFindAndModifyWriteConcernSupported(serverVersion) }
            };

            var result = subject.CreateCommand(serverVersion);

            result.Should().Be(expectedResult);
        }
Esempio n. 2
0
        public void CreateCommand_should_create_the_correct_command(
            [Values(null, 10)] int?maxTimeMS,
            [Values(null, "{a: 1}")] string projection,
            [Values(null, "{b: 1}")] string sort)
        {
            var projectionDoc = projection == null ? (BsonDocument)null : BsonDocument.Parse(projection);
            var sortDoc       = sort == null ? (BsonDocument)null : BsonDocument.Parse(sort);
            var subject       = new FindOneAndDeleteOperation <BsonDocument>(_collectionNamespace, _filter, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                MaxTime    = maxTimeMS.HasValue ? TimeSpan.FromMilliseconds(maxTimeMS.Value) : (TimeSpan?)null,
                Projection = projectionDoc,
                Sort       = sortDoc
            };

            var expectedResult = new BsonDocument
            {
                { "findAndModify", _collectionNamespace.CollectionName },
                { "query", _filter },
                { "sort", sortDoc, sortDoc != null },
                { "remove", true },
                { "fields", projectionDoc, projectionDoc != null },
                { "maxTimeMS", () => maxTimeMS.Value, maxTimeMS.HasValue }
            };

            var result = subject.CreateCommand();

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_the_expected_result(
            [Values(null, "{ name : 'name' }")] string let,
            [Values(null, 10L)] long?transactionNumber)
        {
            var letDocument = let != null?BsonDocument.Parse(let) : null;

            var subject = new FindOneAndDeleteOperation <BsonDocument>(_collectionNamespace, _filter, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                Let = letDocument
            };
            var session = OperationTestHelper.CreateSession();
            var connectionDescription = OperationTestHelper.CreateConnectionDescription();

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

            var expectedResult = new BsonDocument
            {
                { "findAndModify", _collectionNamespace.CollectionName },
                { "query", _filter },
                { "remove", true },
                { "txnNumber", () => transactionNumber, transactionNumber != null },
                { "let", letDocument, letDocument != null }
            };

            result.Should().Be(expectedResult);
        }
Esempio n. 4
0
        public void CreateCommand_should_throw_when_Collation_is_set_and_not_supported()
        {
            var subject = new FindOneAndDeleteOperation <BsonDocument>(_collectionNamespace, _filter, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                Collation = new Collation("en_US")
            };

            var exception = Record.Exception(() => subject.CreateCommand(Feature.Collation.LastNotSupportedVersion, null));

            exception.Should().BeOfType <NotSupportedException>();
        }
Esempio n. 5
0
        public void CreateCommand_should_return_the_expected_result()
        {
            var subject = new FindOneAndDeleteOperation <BsonDocument>(_collectionNamespace, _filter, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "findAndModify", _collectionNamespace.CollectionName },
                { "query", _filter },
                { "remove", true }
            };

            result.Should().Be(expectedResult);
        }
Esempio n. 6
0
        public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(long maxTimeTicks, int expectedMaxTimeMS)
        {
            var subject = new FindOneAndDeleteOperation <BsonDocument>(_collectionNamespace, _filter, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                MaxTime = TimeSpan.FromTicks(maxTimeTicks)
            };

            var result = subject.CreateCommand(null, null);

            var expectedResult = new BsonDocument
            {
                { "findAndModify", _collectionNamespace.CollectionName },
                { "query", _filter },
                { "remove", true },
                { "maxTimeMS", expectedMaxTimeMS }
            };

            result.Should().Be(expectedResult);
            result["maxTimeMS"].BsonType.Should().Be(BsonType.Int32);
        }
Esempio n. 7
0
        public void CreateCommand_should_return_the_expected_result_when_WriteConcern_is_set(
            [Values(null, 1, 2)]
            int?w)
        {
            var writeConcern = w.HasValue ? new WriteConcern(w.Value) : null;
            var subject      = new FindOneAndDeleteOperation <BsonDocument>(_collectionNamespace, _filter, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                WriteConcern = writeConcern
            };

            var result = subject.CreateCommand(Feature.FindAndModifyWriteConcern.FirstSupportedVersion, null);

            var expectedResult = new BsonDocument
            {
                { "findAndModify", _collectionNamespace.CollectionName },
                { "query", _filter },
                { "remove", true },
                { "writeConcern", () => writeConcern.ToBsonDocument(), writeConcern != null }
            };

            result.Should().Be(expectedResult);
        }
Esempio n. 8
0
        public void CreateCommand_should_return_the_expected_result_when_Sort_is_set(
            [Values(null, "{ x : 1 }", "{ y : 1 }")]
            string sortString)
        {
            var sort    = sortString == null ? null : BsonDocument.Parse(sortString);
            var subject = new FindOneAndDeleteOperation <BsonDocument>(_collectionNamespace, _filter, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                Sort = sort
            };

            var result = subject.CreateCommand(null, null);

            var expectedResult = new BsonDocument
            {
                { "findAndModify", _collectionNamespace.CollectionName },
                { "query", _filter },
                { "remove", true },
                { "sort", sort, sort != null }
            };

            result.Should().Be(expectedResult);
        }
Esempio n. 9
0
        public void CreateCommand_should_return_the_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 FindOneAndDeleteOperation <BsonDocument>(_collectionNamespace, _filter, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                MaxTime = maxTime
            };

            var result = subject.CreateCommand(null, null);

            var expectedResult = new BsonDocument
            {
                { "findAndModify", _collectionNamespace.CollectionName },
                { "query", _filter },
                { "remove", true },
                { "maxTimeMS", () => seconds.Value * 1000, seconds.HasValue }
            };

            result.Should().Be(expectedResult);
        }
Esempio n. 10
0
        public void CreateCommand_should_return_the_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 FindOneAndDeleteOperation <BsonDocument>(_collectionNamespace, _filter, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                Collation = collation
            };

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

            var expectedResult = new BsonDocument
            {
                { "findAndModify", _collectionNamespace.CollectionName },
                { "query", _filter },
                { "remove", true },
                { "collation", () => collation.ToBsonDocument(), collation != null }
            };

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_expected_result_when_Hint_is_set(
            [Values(null, "_id_")] string hintString)
        {
            var hint    = (BsonValue)hintString;
            var subject = new FindOneAndDeleteOperation <BsonDocument>(_collectionNamespace, _filter, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                Hint = hint
            };
            var session = OperationTestHelper.CreateSession();
            var connectionDescription = OperationTestHelper.CreateConnectionDescription(serverVersion: Feature.HintForFindAndModifyFeature.FirstSupportedVersion);

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

            var expectedResult = new BsonDocument
            {
                { "findAndModify", _collectionNamespace.CollectionName },
                { "query", _filter },
                { "remove", true },
                { "hint", () => hint, hint != null }
            };

            result.Should().Be(expectedResult);
        }
        public void CreateCommand_should_return_the_expected_result_when_Projection_is_set(
            [Values(null, "{ x : 1 }", "{ y : 1 }")]
            string projectionString)
        {
            var projection = projectionString == null ? null : BsonDocument.Parse(projectionString);
            var subject    = new FindOneAndDeleteOperation <BsonDocument>(_collectionNamespace, _filter, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                Projection = projection
            };
            var session = OperationTestHelper.CreateSession();
            var connectionDescription = OperationTestHelper.CreateConnectionDescription();

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

            var expectedResult = new BsonDocument
            {
                { "findAndModify", _collectionNamespace.CollectionName },
                { "query", _filter },
                { "remove", true },
                { "fields", projection, projection != null }
            };

            result.Should().Be(expectedResult);
        }