// methods /// <inheritdoc/> protected internal override BsonDocument CreateCommand(SemanticVersion serverVersion) { var command = base.CreateCommand(serverVersion); if (_bypassDocumentValidation.HasValue && SupportedFeatures.IsBypassDocumentValidationSupported(serverVersion)) { command["bypassDocumentValidation"] = _bypassDocumentValidation.Value; } return(command); }
public void CreateCommand_should_create_the_correct_command( [Values(null, false, true)] bool?bypassDocumentValidation, [Values(false, true)] bool isUpsert, [Values(null, 10)] int?maxTimeMS, [Values(null, "{a: 1}")] string projection, [Values(ReturnDocument.Before, ReturnDocument.After)] ReturnDocument returnDocument, [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 FindOneAndUpdateOperation <BsonDocument>(_collectionNamespace, _filter, _update, BsonDocumentSerializer.Instance, _messageEncoderSettings) { BypassDocumentValidation = bypassDocumentValidation, IsUpsert = isUpsert, MaxTime = maxTimeMS.HasValue ? TimeSpan.FromMilliseconds(maxTimeMS.Value) : (TimeSpan?)null, Projection = projectionDoc, ReturnDocument = returnDocument, Sort = sortDoc, WriteConcern = writeConcern }; var expectedResult = new BsonDocument { { "findAndModify", _collectionNamespace.CollectionName }, { "query", _filter }, { "sort", sortDoc, sortDoc != null }, { "update", _update, _update != null }, { "new", returnDocument == ReturnDocument.After }, { "fields", projectionDoc, projectionDoc != null }, { "upsert", isUpsert }, { "maxTimeMS", () => maxTimeMS.Value, maxTimeMS.HasValue }, { "writeConcern", () => writeConcern.ToBsonDocument(), writeConcern != null && SupportedFeatures.IsFindAndModifyWriteConcernSupported(serverVersion) }, { "bypassDocumentValidation", () => bypassDocumentValidation.Value, bypassDocumentValidation.HasValue&& SupportedFeatures.IsBypassDocumentValidationSupported(serverVersion) } }; var result = subject.CreateCommand(serverVersion); result.Should().Be(expectedResult); }
public void CreateCommand_should_create_the_correct_command( [Values(null, false, true)] bool?allowDiskUse, [Values(null, false, true)] bool?bypassDocumentValidation, [Values(null, 2000)] int?maxTime, [Values("3.0.0", "3.1.3")] string serverVersionString) { var subject = new AggregateToCollectionOperation(_collectionNamespace, _pipeline, _messageEncoderSettings) { AllowDiskUse = allowDiskUse, BypassDocumentValidation = bypassDocumentValidation, MaxTime = maxTime.HasValue ? TimeSpan.FromMilliseconds(maxTime.Value) : (TimeSpan?)null, }; var serverVersion = SemanticVersion.Parse(serverVersionString); var expectedResult = new BsonDocument { { "aggregate", _collectionNamespace.CollectionName }, { "pipeline", new BsonArray(subject.Pipeline) }, { "allowDiskUse", () => allowDiskUse.Value, allowDiskUse.HasValue }, { "bypassDocumentValidation", () => bypassDocumentValidation.Value, bypassDocumentValidation.HasValue&& SupportedFeatures.IsBypassDocumentValidationSupported(serverVersion) }, { "maxTimeMS", () => maxTime.Value, maxTime.HasValue } }; var result = subject.CreateCommand(serverVersion); result.Should().Be(expectedResult); }
// methods internal override BsonDocument CreateCommand(SemanticVersion serverVersion) { return(new BsonDocument { { "findAndModify", CollectionNamespace.CollectionName }, { "query", _filter }, { "sort", _sort, _sort != null }, { "update", _update }, { "new", _returnDocument == ReturnDocument.After }, { "fields", _projection, _projection != null }, { "upsert", _isUpsert }, { "maxTimeMS", () => _maxTime.Value.TotalMilliseconds, _maxTime.HasValue }, { "writeConcern", () => WriteConcern.ToBsonDocument(), WriteConcern != null && !WriteConcern.IsServerDefault && SupportedFeatures.IsFindAndModifyWriteConcernSupported(serverVersion) }, { "bypassDocumentValidation", () => _bypassDocumentValidation.Value, _bypassDocumentValidation.HasValue&& SupportedFeatures.IsBypassDocumentValidationSupported(serverVersion) } }); }
private BsonDocument CreateWriteCommand(BatchSerializer batchSerializer, BatchableSource <WriteRequest> requestSource, SemanticVersion serverVersion) { var batchWrapper = new BsonDocumentWrapper(requestSource, batchSerializer); WriteConcern effectiveWriteConcern = _writeConcern; if (!effectiveWriteConcern.IsAcknowledged && _isOrdered) { effectiveWriteConcern = WriteConcern.W1; // ignore the server's default, whatever it may be. } return(new BsonDocument { { CommandName, _collectionNamespace.CollectionName }, { "writeConcern", () => effectiveWriteConcern.ToBsonDocument(), !effectiveWriteConcern.IsServerDefault }, { "ordered", _isOrdered }, { "bypassDocumentValidation", () => _bypassDocumentValidation.Value, _bypassDocumentValidation.HasValue&& SupportedFeatures.IsBypassDocumentValidationSupported(serverVersion) }, { RequestsElementName, new BsonArray { batchWrapper } } // should be last }); }
internal BsonDocument CreateCommand(SemanticVersion serverVersion) { return(new BsonDocument { { "aggregate", _collectionNamespace.CollectionName }, { "pipeline", new BsonArray(_pipeline) }, { "allowDiskUse", () => _allowDiskUse.Value, _allowDiskUse.HasValue }, { "bypassDocumentValidation", () => _bypassDocumentValidation.Value, _bypassDocumentValidation.HasValue&& SupportedFeatures.IsBypassDocumentValidationSupported(serverVersion) }, { "maxTimeMS", () => _maxTime.Value.TotalMilliseconds, _maxTime.HasValue } }); }