public async Task FindOneAndUpdate_should_execute_the_FindOneAndReplaceOperation(bool isUpsert, bool returnOriginal) { var criteria = BsonDocument.Parse("{x: 1}"); var update = BsonDocument.Parse("{$set: {a: 2}}"); var projection = BsonDocument.Parse("{x: 1}"); var sort = BsonDocument.Parse("{a: -1}"); var model = new FindOneAndUpdateModel(criteria, update) { IsUpsert = isUpsert, Projection = projection, ReturnOriginal = returnOriginal, Sort = sort, MaxTime = TimeSpan.FromSeconds(2) }; await _subject.FindOneAndUpdateAsync <BsonDocument>(model, Timeout.InfiniteTimeSpan, CancellationToken.None); var call = _operationExecutor.GetWriteCall <BsonDocument>(); call.Operation.Should().BeOfType <FindOneAndUpdateOperation <BsonDocument> >(); var operation = (FindOneAndUpdateOperation <BsonDocument>)call.Operation; operation.CollectionNamespace.FullName.Should().Be("foo.bar"); operation.Criteria.Should().Be(criteria); operation.Update.Should().Be(update); 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); }
public Task <TResult> FindOneAndUpdateAsync <TResult>(FindOneAndUpdateModel model, TimeSpan?timeout, CancellationToken cancellationToken) { Ensure.IsNotNull(model, "model"); var operation = new FindOneAndUpdateOperation <TResult>( _collectionNamespace, ConvertToBsonDocument(model.Criteria), ConvertToBsonDocument(model.Update), _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)); }