public async Task FindOneAndReplace_should_execute_the_FindOneAndReplaceOperation(bool isUpsert, bool returnOriginal)
        {
            var criteria    = BsonDocument.Parse("{x: 1}");
            var replacement = BsonDocument.Parse("{a: 2}");
            var projection  = BsonDocument.Parse("{x: 1}");
            var sort        = BsonDocument.Parse("{a: -1}");
            var model       = new FindOneAndReplaceModel <BsonDocument>(criteria, replacement)
            {
                IsUpsert       = isUpsert,
                Projection     = projection,
                ReturnOriginal = returnOriginal,
                Sort           = sort,
                MaxTime        = TimeSpan.FromSeconds(2)
            };

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

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

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

            operation.CollectionNamespace.FullName.Should().Be("foo.bar");
            operation.Criteria.Should().Be(criteria);
            operation.Replacement.Should().Be(replacement);
            operation.IsUpsert.Should().Be(isUpsert);
            operation.ReturnOriginal.Should().Be(returnOriginal);
            operation.Projection.Should().Be(projection);
            operation.Sort.Should().Be(sort);
            operation.MaxTime.Should().Be(model.MaxTime);
        }
Beispiel #2
0
        public Task <TResult> FindOneAndReplaceAsync <TResult>(FindOneAndReplaceModel <TDocument> model, TimeSpan?timeout, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(model, "model");

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

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