public void CreateCommand_should_create_the_correct_command( [Values("2.4.0", "2.6.0", "2.8.0", "3.0.0", "3.2.0")] string serverVersion, [Values(null, false, true)] bool?allowDiskUse, [Values(null, 10, 20)] int?batchSize, [Values(null, 2000)] int?maxTime, [Values(null, ReadConcernLevel.Local, ReadConcernLevel.Majority)] ReadConcernLevel?readConcernLevel, [Values(null, false, true)] bool?useCursor) { var semanticServerVersion = SemanticVersion.Parse(serverVersion); var subject = new AggregateOperation <BsonDocument>(_collectionNamespace, Enumerable.Empty <BsonDocument>(), BsonDocumentSerializer.Instance, _messageEncoderSettings) { AllowDiskUse = allowDiskUse, BatchSize = batchSize, MaxTime = maxTime.HasValue ? TimeSpan.FromMilliseconds(maxTime.Value) : (TimeSpan?)null, ReadConcern = new ReadConcern(readConcernLevel), UseCursor = useCursor }; var expectedResult = new BsonDocument { { "aggregate", _collectionNamespace.CollectionName }, { "pipeline", new BsonArray(subject.Pipeline) }, { "allowDiskUse", () => allowDiskUse.Value, allowDiskUse.HasValue }, { "maxTimeMS", () => maxTime.Value, maxTime.HasValue } }; if (!subject.ReadConcern.IsServerDefault) { expectedResult["readConcern"] = subject.ReadConcern.ToBsonDocument(); } if (SupportedFeatures.IsAggregateCursorResultSupported(semanticServerVersion) && useCursor.GetValueOrDefault(true)) { expectedResult["cursor"] = new BsonDocument { { "batchSize", () => batchSize.Value, batchSize.HasValue } }; } if (!subject.ReadConcern.IsSupported(semanticServerVersion)) { Action act = () => subject.CreateCommand(semanticServerVersion); act.ShouldThrow <MongoClientException>(); } else { var result = subject.CreateCommand(semanticServerVersion); result.Should().Be(expectedResult); } }
public void CreateCommand_should_return_the_expected_result_when_BatchSize_is_set( [Values(null, 1)] int?batchSize) { var subject = new AggregateOperation <BsonDocument>(_collectionNamespace, __pipeline, __resultSerializer, _messageEncoderSettings) { BatchSize = batchSize }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); var session = OperationTestHelper.CreateSession(); var result = subject.CreateCommand(connectionDescription, session); var cursor = new BsonDocument { { "batchSize", () => batchSize.Value, batchSize != null } }; var expectedResult = new BsonDocument { { "aggregate", _collectionNamespace.CollectionName }, { "pipeline", new BsonArray(__pipeline) }, { "cursor", cursor } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_the_expected_result_when_UseCursor_is_set( [Values(null, false, true)] bool?useCursor, [Values(false, true)] bool useServerVersionSupportingAggregateCursorResult) { var subject = new AggregateOperation <BsonDocument>(_collectionNamespace, __pipeline, __resultSerializer, _messageEncoderSettings) { UseCursor = useCursor }; var serverVersion = Feature.AggregateCursorResult.SupportedOrNotSupportedVersion(useServerVersionSupportingAggregateCursorResult); var connectionDescription = OperationTestHelper.CreateConnectionDescription(serverVersion); var session = OperationTestHelper.CreateSession(); var result = subject.CreateCommand(connectionDescription, session); var expectedResult = new BsonDocument { { "aggregate", _collectionNamespace.CollectionName }, { "pipeline", new BsonArray(__pipeline) }, { "cursor", () => new BsonDocument(), useCursor.GetValueOrDefault(true) && Feature.AggregateCursorResult.IsSupported(serverVersion) } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_the_expected_result_when_ReadConcern_is_set( [Values(null, ReadConcernLevel.Linearizable)] ReadConcernLevel?level) { var readConcern = new ReadConcern(level); var subject = new AggregateOperation <BsonDocument>(_collectionNamespace, __pipeline, __resultSerializer, _messageEncoderSettings) { ReadConcern = readConcern }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(Feature.ReadConcern.FirstSupportedVersion); var session = OperationTestHelper.CreateSession(); var result = subject.CreateCommand(connectionDescription, session); var expectedResult = new BsonDocument { { "aggregate", _collectionNamespace.CollectionName }, { "pipeline", new BsonArray(__pipeline) }, { "readConcern", () => readConcern.ToBsonDocument(), level != null }, { "cursor", new BsonDocument() } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_the_expected_result_when_using_causal_consistency( [Values(null, ReadConcernLevel.Linearizable)] ReadConcernLevel?level) { var readConcern = new ReadConcern(level); var subject = new AggregateOperation <BsonDocument>(_collectionNamespace, __pipeline, __resultSerializer, _messageEncoderSettings) { ReadConcern = readConcern }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(Feature.ReadConcern.FirstSupportedVersion, supportsSessions: true); var session = OperationTestHelper.CreateSession(true, new BsonTimestamp(100)); var result = subject.CreateCommand(connectionDescription, session); var expectedReadConcernDocument = readConcern.ToBsonDocument(); expectedReadConcernDocument["afterClusterTime"] = new BsonTimestamp(100); var expectedResult = new BsonDocument { { "aggregate", _collectionNamespace.CollectionName }, { "pipeline", new BsonArray(__pipeline) }, { "readConcern", expectedReadConcernDocument }, { "cursor", new BsonDocument() } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_the_expected_result_when_Hint_is_set( [Values(null, "{x: 1}")] string hintJson) { var hint = hintJson == null ? null : BsonDocument.Parse(hintJson); var subject = new AggregateOperation <BsonDocument>(_collectionNamespace, __pipeline, __resultSerializer, _messageEncoderSettings) { Hint = hint }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(Feature.AggregateHint.FirstSupportedVersion); var session = OperationTestHelper.CreateSession(); var result = subject.CreateCommand(connectionDescription, session); var expectedResult = new BsonDocument { { "aggregate", _collectionNamespace.CollectionName }, { "pipeline", new BsonArray(__pipeline) }, { "hint", () => hint, hint != null }, { "cursor", new BsonDocument() } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_the_expected_result_when_BatchSize_is_set( [Values(null, 1)] int?batchSize, [Values(false, true)] bool useServerVersionSupportingAggregateCursorResult) { var subject = new AggregateOperation <BsonDocument>(_collectionNamespace, __pipeline, __resultSerializer, _messageEncoderSettings) { BatchSize = batchSize }; var serverVersion = Feature.AggregateCursorResult.SupportedOrNotSupportedVersion(useServerVersionSupportingAggregateCursorResult); var connectionDescription = OperationTestHelper.CreateConnectionDescription(serverVersion); var session = OperationTestHelper.CreateSession(); var result = subject.CreateCommand(connectionDescription, session); BsonDocument cursor = null; if (Feature.AggregateCursorResult.IsSupported(serverVersion)) { cursor = new BsonDocument { { "batchSize", () => batchSize.Value, batchSize != null } }; } var expectedResult = new BsonDocument { { "aggregate", _collectionNamespace.CollectionName }, { "pipeline", new BsonArray(__pipeline) }, { "cursor", () => cursor, cursor != null } }; result.Should().Be(expectedResult); }
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 AggregateOperation <BsonDocument>(_collectionNamespace, __pipeline, __resultSerializer, _messageEncoderSettings) { Collation = collation }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(Feature.Collation.FirstSupportedVersion); var session = OperationTestHelper.CreateSession(); var result = subject.CreateCommand(connectionDescription, session); var expectedResult = new BsonDocument { { "aggregate", _collectionNamespace.CollectionName }, { "pipeline", new BsonArray(__pipeline) }, { "collation", () => new BsonDocument("locale", locale), collation != null }, { "cursor", new BsonDocument() } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_the_expected_result_when_AllowDiskUse_is_set( [Values(null, false, true)] bool?allowDiskUse) { var subject = new AggregateOperation <BsonDocument>(_collectionNamespace, __pipeline, __resultSerializer, _messageEncoderSettings) { AllowDiskUse = allowDiskUse }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); var session = OperationTestHelper.CreateSession(); var result = subject.CreateCommand(connectionDescription, session); var expectedResult = new BsonDocument { { "aggregate", _collectionNamespace.CollectionName }, { "pipeline", new BsonArray(__pipeline) }, { "allowDiskUse", () => allowDiskUse.Value, allowDiskUse != null }, { "cursor", new BsonDocument() } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_the_expected_result_when_MaxTime_is_set( [Values(null, 1)] int?milliSeconds) { var maxTime = milliSeconds == null ? (TimeSpan?)null : TimeSpan.FromMilliseconds(milliSeconds.Value); var subject = new AggregateOperation <BsonDocument>(_collectionNamespace, __pipeline, __resultSerializer, _messageEncoderSettings) { MaxTime = maxTime }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(Feature.AggregateCursorResult.FirstSupportedVersion); var session = OperationTestHelper.CreateSession(); var result = subject.CreateCommand(connectionDescription, session); var expectedResult = new BsonDocument { { "aggregate", _collectionNamespace.CollectionName }, { "pipeline", new BsonArray(__pipeline) }, { "maxTimeMS", () => maxTime.Value.TotalMilliseconds, maxTime != null }, { "cursor", new BsonDocument() } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_throw_when_ReadConcern_is_set_but_not_supported() { var subject = new AggregateOperation <BsonDocument>(_collectionNamespace, __pipeline, __resultSerializer, _messageEncoderSettings) { ReadConcern = new ReadConcern(ReadConcernLevel.Linearizable) }; var exception = Record.Exception(() => subject.CreateCommand(Feature.ReadConcern.LastNotSupportedVersion)); exception.Should().BeOfType <MongoClientException>(); }
public void CreateCommand_should_throw_when_Collation_is_set() { var subject = new AggregateOperation <BsonDocument>(_collectionNamespace, __pipeline, __resultSerializer, _messageEncoderSettings) { Collation = new Collation("en_US") }; var exception = Record.Exception(() => subject.CreateCommand(Feature.Collation.LastNotSupportedVersion)); exception.Should().BeOfType <NotSupportedException>(); }
public void CreateCommand_should_return_the_expected_result() { var subject = new AggregateOperation <BsonDocument>(_collectionNamespace, __pipeline, __resultSerializer, _messageEncoderSettings); var connectionDescription = OperationTestHelper.CreateConnectionDescription(); var session = OperationTestHelper.CreateSession(); var result = subject.CreateCommand(connectionDescription, session); var expectedResult = new BsonDocument { { "aggregate", _collectionNamespace.CollectionName }, { "pipeline", new BsonArray(__pipeline) }, { "cursor", new BsonDocument() } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_the_expected_result( [Values(false, true)] bool useServerVersionSupportingAggregateCursorResult) { var subject = new AggregateOperation <BsonDocument>(_collectionNamespace, __pipeline, __resultSerializer, _messageEncoderSettings); var serverVersion = Feature.AggregateCursorResult.SupportedOrNotSupportedVersion(useServerVersionSupportingAggregateCursorResult); var result = subject.CreateCommand(serverVersion); var expectedResult = new BsonDocument { { "aggregate", _collectionNamespace.CollectionName }, { "pipeline", new BsonArray(__pipeline) }, { "cursor", () => new BsonDocument(), Feature.AggregateCursorResult.IsSupported(serverVersion) } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(long maxTimeTicks, int expectedMaxTimeMS) { var subject = new AggregateOperation <BsonDocument>(_collectionNamespace, __pipeline, __resultSerializer, _messageEncoderSettings) { MaxTime = TimeSpan.FromTicks(maxTimeTicks) }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(Feature.AggregateCursorResult.FirstSupportedVersion); var session = OperationTestHelper.CreateSession(); var result = subject.CreateCommand(connectionDescription, session); var expectedResult = new BsonDocument { { "aggregate", _collectionNamespace.CollectionName }, { "pipeline", new BsonArray(__pipeline) }, { "maxTimeMS", expectedMaxTimeMS }, { "cursor", new BsonDocument() } }; result.Should().Be(expectedResult); result["maxTimeMS"].BsonType.Should().Be(BsonType.Int32); }
public void CreateCommand_should_create_the_correct_command( [Values("2.4.0", "2.6.0", "2.8.0")] string serverVersion, [Values(null, false, true)] bool?allowDiskUse, [Values(null, 10, 20)] int?batchSize, [Values(null, 2000)] int?maxTime, [Values(null, false, true)] bool?useCursor) { var semanticServerVersion = SemanticVersion.Parse(serverVersion); var subject = new AggregateOperation <BsonDocument>(_collectionNamespace, Enumerable.Empty <BsonDocument>(), BsonDocumentSerializer.Instance, _messageEncoderSettings) { AllowDiskUse = allowDiskUse, BatchSize = batchSize, MaxTime = maxTime.HasValue ? TimeSpan.FromMilliseconds(maxTime.Value) : (TimeSpan?)null, UseCursor = useCursor }; var expectedResult = new BsonDocument { { "aggregate", _collectionNamespace.CollectionName }, { "pipeline", new BsonArray(subject.Pipeline) }, { "allowDiskUse", () => allowDiskUse.Value, allowDiskUse.HasValue }, { "maxTimeMS", () => maxTime.Value, maxTime.HasValue } }; var defaultCursorValue = semanticServerVersion >= new SemanticVersion(2, 6, 0); if (useCursor.GetValueOrDefault(defaultCursorValue)) { expectedResult["cursor"] = new BsonDocument { { "batchSize", () => batchSize.Value, batchSize.HasValue } }; } var result = subject.CreateCommand(semanticServerVersion); result.Should().Be(expectedResult); }
public void CreateCommand_should_return_expected_result_when_Comment_is_set( [Values(null, "test")] string comment) { var subject = new AggregateOperation <BsonDocument>(_collectionNamespace, __pipeline, __resultSerializer, _messageEncoderSettings) { Comment = comment, }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); var session = OperationTestHelper.CreateSession(); var result = subject.CreateCommand(connectionDescription, session); var expectedResult = new BsonDocument { { "aggregate", _collectionNamespace.CollectionName }, { "pipeline", new BsonArray(__pipeline) }, { "comment", () => comment, comment != null }, { "cursor", new BsonDocument() } }; result.Should().Be(expectedResult); }