public void CreateCommand_should_return_expected_result_when_Comment_is_set( [Values(null, "a", "b")] string comment) { var subject = new FindCommandOperation <BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings) { Comment = comment }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); var session = OperationTestHelper.CreateSession(); var result = subject.CreateCommand(connectionDescription, session); var expectedResult = new BsonDocument { { "find", _collectionNamespace.CollectionName }, { "comment", () => comment, comment != null } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_expected_result_when_Sort_is_set( [Values(null, "{ x : 1 }", "{ y : 1 }")] string sortString) { var sort = sortString == null ? null : BsonDocument.Parse(sortString); var subject = new FindCommandOperation <BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings) { Sort = sort }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); var session = OperationTestHelper.CreateSession(); var result = subject.CreateCommand(connectionDescription, session); var expectedResult = new BsonDocument { { "find", _collectionNamespace.CollectionName }, { "sort", sort, sort != null } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_expected_result_when_ReadConcern_is_set( [Values(null, ReadConcernLevel.Linearizable, ReadConcernLevel.Local)] ReadConcernLevel?level) { var readConcern = level.HasValue ? new ReadConcern(level.Value) : ReadConcern.Default; var subject = new FindCommandOperation <BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings) { ReadConcern = readConcern }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(Feature.ReadConcern.FirstSupportedVersion); var session = OperationTestHelper.CreateSession(); var result = subject.CreateCommand(connectionDescription, session); var expectedResult = new BsonDocument { { "find", _collectionNamespace.CollectionName }, { "readConcern", () => readConcern.ToBsonDocument(), readConcern != null && !readConcern.IsServerDefault } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_expected_result_when_MaxTime_is_set( [Values(null, 1, 2)] int?seconds) { var maxTime = seconds.HasValue ? TimeSpan.FromSeconds(seconds.Value) : (TimeSpan?)null; var subject = new FindCommandOperation <BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings) { MaxTime = maxTime }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); var session = OperationTestHelper.CreateSession(); var result = subject.CreateCommand(connectionDescription, session); var expectedResult = new BsonDocument { { "find", _collectionNamespace.CollectionName }, { "maxTimeMS", () => seconds.Value * 1000, seconds.HasValue } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_expected_result_when_CursorType_is_Set( [Values(CursorType.NonTailable, CursorType.Tailable, CursorType.TailableAwait)] CursorType cursorType) { var subject = new FindCommandOperation <BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings) { CursorType = cursorType }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); var session = OperationTestHelper.CreateSession(); var result = subject.CreateCommand(connectionDescription, session); var expectedResult = new BsonDocument { { "find", _collectionNamespace.CollectionName }, { "tailable", true, cursorType == CursorType.Tailable || cursorType == CursorType.TailableAwait }, { "awaitData", true, cursorType == CursorType.TailableAwait } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_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 FindCommandOperation <BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings) { Collation = collation }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(Feature.Collation.FirstSupportedVersion); var session = OperationTestHelper.CreateSession(); var result = subject.CreateCommand(connectionDescription, session); var expectedResult = new BsonDocument { { "find", _collectionNamespace.CollectionName }, { "collation", () => collation.ToBsonDocument(), collation != null } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_expected_result_when_Limit_is_set( [Values(null, -2, -1, 0, 1, 2)] int?limit, [Values(null, false, true)] bool?singleBatch) { var subject = new FindCommandOperation <BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings) { Limit = limit, SingleBatch = singleBatch }; var result = subject.CreateCommand(null, 0); var expectedResult = new BsonDocument { { "find", _collectionNamespace.CollectionName }, { "limit", () => Math.Abs(limit.Value), limit.HasValue&& limit.Value != 0 }, { "singleBatch", () => limit < 0 || singleBatch.Value, limit < 0 || singleBatch.HasValue } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_expected_result_when_AllowPartialResults_is_set( [Values(null, false, true)] bool?allowPartialResults, [Values(ServerType.Standalone, ServerType.ShardRouter)] ServerType serverType) { var subject = new FindCommandOperation <BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings) { AllowPartialResults = allowPartialResults }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(serverType: serverType); var session = OperationTestHelper.CreateSession(); var result = subject.CreateCommand(connectionDescription, session); var expectedResult = new BsonDocument { { "find", _collectionNamespace.CollectionName }, { "allowPartialResults", () => allowPartialResults.Value, allowPartialResults.HasValue&& serverType == ServerType.ShardRouter } }; result.Should().Be(expectedResult); }