public async Task FindOneAndDelete_should_execute_the_FindOneAndDeleteOperation()
        {
            var criteria   = BsonDocument.Parse("{x: 1}");
            var projection = BsonDocument.Parse("{x: 1}");
            var sort       = BsonDocument.Parse("{a: -1}");
            var model      = new FindOneAndDeleteModel(criteria)
            {
                Projection = projection,
                Sort       = sort,
                MaxTime    = TimeSpan.FromSeconds(2)
            };

            await _subject.FindOneAndDeleteAsync <BsonDocument>(model, Timeout.InfiniteTimeSpan, CancellationToken.None);

            var call = _operationExecutor.GetWriteCall <BsonDocument>();

            call.Operation.Should().BeOfType <FindOneAndDeleteOperation <BsonDocument> >();
            var operation = (FindOneAndDeleteOperation <BsonDocument>)call.Operation;

            operation.CollectionNamespace.FullName.Should().Be("foo.bar");
            operation.Criteria.Should().Be(criteria);
            operation.Projection.Should().Be(projection);
            operation.Sort.Should().Be(sort);
            operation.MaxTime.Should().Be(model.MaxTime);
        }
예제 #2
0
        public Task <TResult> FindOneAndDeleteAsync <TResult>(FindOneAndDeleteModel model, TimeSpan?timeout, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(model, "model");

            var operation = new FindOneAndDeleteOperation <TResult>(
                _collectionNamespace,
                ConvertToBsonDocument(model.Criteria),
                _settings.SerializerRegistry.GetSerializer <TResult>(),
                _messageEncoderSettings)
            {
                MaxTime    = model.MaxTime,
                Projection = ConvertToBsonDocument(model.Projection),
                Sort       = ConvertToBsonDocument(model.Sort)
            };

            return(ExecuteWriteOperation(operation, timeout, cancellationToken));
        }