public void CreateCommand_should_return_the_expected_result_when_using_causal_consistency( [Values(null, ReadConcernLevel.Linearizable, ReadConcernLevel.Local)] ReadConcernLevel?level) { var readConcern = level.HasValue ? new ReadConcern(level.Value) : ReadConcern.Default; var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _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 { { "distinct", _collectionNamespace.CollectionName }, { "key", _fieldName }, { "readConcern", expectedReadConcernDocument } }; result.Should().Be(expectedResult); }
// constructors public Builder(DistinctOperation <TValue> other) { _collectionName = other._collectionName; _databaseName = other._databaseName; _key = other._key; _query = other._query; _valueSerializer = other._valueSerializer; }
public void Execute_should_send_session_id_when_supported( [Values(false, true)] bool async) { RequireServer.Check(); EnsureTestData(); var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings); VerifySessionIdWasSentWhenSupported(subject, "distinct", async); }
public void MaxTime_get_and_set_should_work( [Values(-10000, 0, 1, 10000, 99999)] long maxTimeTicks) { var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings); var value = TimeSpan.FromTicks(maxTimeTicks); subject.MaxTime = value; var result = subject.MaxTime; result.Should().Be(value); }
public void CreateCommand_should_throw_when_ReadConcern_is_set_and_not_supported() { var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings) { ReadConcern = new ReadConcern(ReadConcernLevel.Local) }; var exception = Record.Exception(() => subject.CreateCommand(Feature.ReadConcern.LastNotSupportedVersion)); exception.Should().BeOfType <MongoClientException>(); }
public void CreateCommand_should_throw_when_Collation_is_set_and_not_supported() { var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings) { Collation = new Collation("en_US") }; var exception = Record.Exception(() => subject.CreateCommand(Feature.Collation.LastNotSupportedVersion)); exception.Should().BeOfType <NotSupportedException>(); }
public void RetryRequested_get_and_set_should_work( [Values(false, true)] bool value) { var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings); subject.RetryRequested = value; var result = subject.RetryRequested; result.Should().Be(value); }
public void MaxTime_set_should_throw_when_value_is_invalid( [Values(-10001, -9999, -1)] long maxTimeTicks) { var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings); var value = TimeSpan.FromTicks(maxTimeTicks); var exception = Record.Exception(() => subject.MaxTime = value); var e = exception.Should().BeOfType <ArgumentOutOfRangeException>().Subject; e.ParamName.Should().Be("value"); }
public void MaxTime_get_and_set_should_work( [Values(null, 1, 2)] int?seconds) { var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings); var value = seconds.HasValue ? TimeSpan.FromSeconds(seconds.Value) : (TimeSpan?)null; subject.MaxTime = value; var result = subject.MaxTime; result.Should().Be(value); }
public void ReadConcern_get_and_set_should_work( [Values(null, ReadConcernLevel.Local, ReadConcernLevel.Local)] ReadConcernLevel?level) { var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings); var value = level.HasValue ? new ReadConcern(level) : ReadConcern.Default; subject.ReadConcern = value; var result = subject.ReadConcern; result.Should().BeSameAs(value); }
public void CreateCommand_should_create_the_correct_command() { var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings) { Criteria = new BsonDocument("x", 1), MaxTime = TimeSpan.FromSeconds(20), }; var cmd = subject.CreateCommand(); cmd.Should().Be("{ distinct: \"bar\", key: \"a.b\", query: {x: 1}, maxTimeMS: 20000 }"); }
public void Filter_get_and_set_should_work( [Values(null, "{ x : 1}", "{ x : 2 }")] string filterString) { var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings); var value = filterString == null ? null : BsonDocument.Parse(filterString); subject.Filter = value; var result = subject.Filter; result.Should().BeSameAs(value); }
public void Collation_get_and_set_should_work( [Values(null, "en_US", "fr_CA")] string locale) { var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings); var value = locale == null ? null : new Collation(locale); subject.Collation = value; var result = subject.Collation; result.Should().BeSameAs(value); }
public void constructor_should_initialize_instance() { var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings); subject.CollectionNamespace.Should().BeSameAs(_collectionNamespace); subject.ValueSerializer.Should().BeSameAs(_valueSerializer); subject.FieldName.Should().BeSameAs(_fieldName); subject.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings); subject.Collation.Should().BeNull(); subject.Filter.Should().BeNull(); subject.MaxTime.Should().NotHaveValue(); subject.ReadConcern.Should().BeSameAs(ReadConcern.Default); }
public void CreateCommand_should_return_expected_result() { var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings); var result = subject.CreateCommand(null); var expectedResult = new BsonDocument { { "distinct", _collectionNamespace.CollectionName }, { "key", _fieldName } }; result.Should().Be(expectedResult); }
public async Task ExecuteAsync_should_return_the_correct_results() { var subject = new DistinctOperation<int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings) { Filter = BsonDocument.Parse("{ _id : { $gt : 2 } }"), MaxTime = TimeSpan.FromSeconds(20), }; var result = await ExecuteOperationAsync(subject); result.Should().HaveCount(2); result.Should().OnlyHaveUniqueItems(); result.Should().Contain(new[] { 2, 3 }); }
public void Execute_should_throw_when_ReadConcern_is_set_and_not_supported( [Values(false, true)] bool async) { RequireServer.Check().DoesNotSupport(Feature.ReadConcern); var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings) { ReadConcern = new ReadConcern(ReadConcernLevel.Local) }; var exception = Record.Exception(() => ExecuteOperation(subject, async)); exception.Should().BeOfType <MongoClientException>(); }
public void Execute_should_return_expected_result( [Values(false, true)] bool async) { RequireServer.Check(); EnsureTestData(); var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings); var cursor = ExecuteOperation(subject, async); var result = ReadCursorToEnd(cursor, async); result.Should().HaveCount(3); result.Should().OnlyHaveUniqueItems(); result.Should().Contain(new[] { 1, 2, 3 }); }
public void Execute_should_throw_when_maxTime_is_exceeded( [Values(false, true)] bool async) { RequireServer.Check().Supports(Feature.FailPoints).ClusterTypes(ClusterType.Standalone, ClusterType.ReplicaSet); var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings) { MaxTime = TimeSpan.FromSeconds(9001) }; using (var failPoint = FailPoint.ConfigureAlwaysOn(_cluster, _session, FailPointName.MaxTimeAlwaysTimeout)) { var exception = Record.Exception(() => ExecuteOperation(subject, failPoint.Binding, async)); exception.Should().BeOfType <MongoExecutionTimeoutException>(); } }
public void Execute_should_return_the_correct_results( [Values(false, true)] bool async) { var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings) { Filter = BsonDocument.Parse("{ _id : { $gt : 2 } }"), MaxTime = TimeSpan.FromSeconds(20), }; var cursor = ExecuteOperation(subject, async); var result = ReadCursorToEnd(cursor, async); result.Should().HaveCount(2); result.Should().OnlyHaveUniqueItems(); result.Should().Contain(new[] { 2, 3 }); }
public void CreateCommand_should_create_the_correct_command() { var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings) { Filter = new BsonDocument("x", 1), MaxTime = TimeSpan.FromSeconds(20), }; var expectedResult = new BsonDocument { { "distinct", _collectionNamespace.CollectionName }, { "key", _fieldName }, { "query", BsonDocument.Parse("{ x: 1 }") }, { "maxTimeMS", 20000 } }; var result = subject.CreateCommand(); result.Should().Be(expectedResult); }
public void Execute_should_return_expected_result_when_Collation_is_set( [Values(false, true)] bool async) { RequireServer.Check().Supports(Feature.Collation); EnsureTestData(); var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings) { Collation = new Collation("en_US", caseLevel: false, strength: CollationStrength.Primary), Filter = BsonDocument.Parse("{ x : \"d\" }") }; var cursor = ExecuteOperation(subject, async); var result = ReadCursorToEnd(cursor, async); result.Should().HaveCount(2); result.Should().OnlyHaveUniqueItems(); result.Should().Contain(new[] { 2, 3 }); }
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 DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings) { Collation = collation }; var result = subject.CreateCommand(Feature.Collation.FirstSupportedVersion); var expectedResult = new BsonDocument { { "distinct", _collectionNamespace.CollectionName }, { "key", _fieldName }, { "collation", () => collation.ToBsonDocument(), collation != null } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_expected_result_when_Filter_is_set( [Values(null, "{ x : 1 }", "{ x : 2 }")] string filterString) { var filter = filterString == null ? null : BsonDocument.Parse(filterString); var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings) { Filter = filter }; var result = subject.CreateCommand(null); var expectedResult = new BsonDocument { { "distinct", _collectionNamespace.CollectionName }, { "key", _fieldName }, { "query", filter, filter != null } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_expected_result_when_MaxTime_is_set( [Values(null, 1, 2)] int?milliseconds) { var maxTime = milliseconds.HasValue ? TimeSpan.FromMilliseconds(milliseconds.Value) : (TimeSpan?)null; var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings) { MaxTime = maxTime }; var result = subject.CreateCommand(null); var expectedResult = new BsonDocument { { "distinct", _collectionNamespace.CollectionName }, { "key", _fieldName }, { "maxTimeMS", () => maxTime.Value.TotalMilliseconds, maxTime.HasValue } }; 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 DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings) { ReadConcern = readConcern }; var result = subject.CreateCommand(Feature.ReadConcern.FirstSupportedVersion); var expectedResult = new BsonDocument { { "distinct", _collectionNamespace.CollectionName }, { "key", _fieldName }, { "readConcern", () => readConcern.ToBsonDocument(), !readConcern.IsServerDefault } }; result.Should().Be(expectedResult); }
public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(long maxTimeTicks, int expectedMaxTimeMS) { var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings) { MaxTime = TimeSpan.FromTicks(maxTimeTicks) }; var connectionDescription = OperationTestHelper.CreateConnectionDescription(); var session = OperationTestHelper.CreateSession(); var result = subject.CreateCommand(connectionDescription, session); var expectedResult = new BsonDocument { { "distinct", _collectionNamespace.CollectionName }, { "key", _fieldName }, { "maxTimeMS", expectedMaxTimeMS } }; result.Should().Be(expectedResult); result["maxTimeMS"].BsonType.Should().Be(BsonType.Int32); }
public void CreateCommand_should_create_the_correct_command( [Values("3.0.0", "3.2.0")] string serverVersion, [Values(null, ReadConcernLevel.Local, ReadConcernLevel.Majority)] ReadConcernLevel?readConcernLevel) { var semanticServerVersion = SemanticVersion.Parse(serverVersion); var subject = new DistinctOperation <int>(_collectionNamespace, _valueSerializer, _fieldName, _messageEncoderSettings) { Filter = new BsonDocument("x", 1), MaxTime = TimeSpan.FromSeconds(20), ReadConcern = new ReadConcern(readConcernLevel) }; var expectedResult = new BsonDocument { { "distinct", _collectionNamespace.CollectionName }, { "key", _fieldName }, { "query", BsonDocument.Parse("{ x: 1 }") }, { "maxTimeMS", 20000 } }; if (!subject.ReadConcern.IsServerDefault) { expectedResult["readConcern"] = subject.ReadConcern.ToBsonDocument(); } if (!subject.ReadConcern.IsSupported(semanticServerVersion)) { Action act = () => subject.CreateCommand(semanticServerVersion); act.ShouldThrow <MongoClientException>(); } else { var result = subject.CreateCommand(semanticServerVersion); result.Should().Be(expectedResult); } }