public void Execute_should_return_the_expected_result_when_nameOnly_is_used( [Values(false, true)] bool nameOnly, [Values(false, true)] bool async) { RequireServer.Check().Supports(Feature.ListDatabasesNameOnlyOption); var subject = new ListDatabasesOperation(_messageEncoderSettings) { NameOnly = nameOnly }; EnsureDatabaseExists(async); var result = ExecuteOperation(subject, async); var databases = ReadCursorToEnd(result, async); foreach (var database in databases) { database.Contains("name").Should().BeTrue(); if (nameOnly) { database.ElementCount.Should().Be(1); } else { database.ElementCount.Should().BeGreaterThan(1); } } }
public void CreateCommand_should_return_expected_result( [Values(null, false, true)] bool?authorizedDatabases, [Values(null, "cake")] string filterString, [Values(null, false, true)] bool?nameOnly) { var filter = filterString != null ? BsonDocument.Parse($"{{ name : \"{filterString}\" }}") : null; var subject = new ListDatabasesOperation(_messageEncoderSettings) { AuthorizedDatabases = authorizedDatabases, NameOnly = nameOnly, Filter = filter }; var expectedResult = new BsonDocument { { "listDatabases", 1 }, { "filter", filter, filterString != null }, { "nameOnly", nameOnly, nameOnly != null }, { "authorizedDatabases", authorizedDatabases, authorizedDatabases != null } }; var result = subject.CreateCommand(); result.Should().Be(expectedResult); }
public void ExecuteAsync_should_throw_when_binding_is_null() { var subject = new ListDatabasesOperation(_messageEncoderSettings); Func <Task> action = () => subject.ExecuteAsync(null, CancellationToken.None); action.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("binding"); }
public void MessageEncoderSettings_get_should_return_expected_result() { var subject = new ListDatabasesOperation(_messageEncoderSettings); var result = subject.MessageEncoderSettings; result.Should().BeSameAs(_messageEncoderSettings); }
// methods public async Task <bool> ExecuteAsync(IReadBinding binding, TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(binding, "binding"); var operation = new ListDatabasesOperation(); var result = await operation.ExecuteAsync(binding, timeout, cancellationToken); return(result["databases"].AsBsonArray.Any(i => (string)i["name"] == _databaseName)); }
// methods /// <inheritdoc/> public bool Execute(IReadBinding binding, CancellationToken cancellationToken) { Ensure.IsNotNull(binding, nameof(binding)); var operation = new ListDatabasesOperation(_messageEncoderSettings); var result = operation.Execute(binding, cancellationToken); var list = result.ToList(cancellationToken); return(list.Any(x => x["name"] == _databaseNamespace.DatabaseName)); }
public void constructor_should_initialize_subject() { var subject = new ListDatabasesOperation(_messageEncoderSettings); subject.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings); subject.Filter.Should().BeNull(); subject.NameOnly.Should().NotHaveValue(); subject.RetryRequested.Should().BeFalse(); }
// methods /// <inheritdoc/> public async Task <bool> ExecuteAsync(IReadBinding binding, CancellationToken cancellationToken) { Ensure.IsNotNull(binding, "binding"); var operation = new ListDatabasesOperation(_messageEncoderSettings); var result = await operation.ExecuteAsync(binding, cancellationToken).ConfigureAwait(false); var list = await result.ToListAsync().ConfigureAwait(false); return(list.Any(x => x["name"] == _databaseNamespace.DatabaseName)); }
public void RetryRequested_get_and_set_should_work( [Values(false, true)] bool value) { var subject = new ListDatabasesOperation(_messageEncoderSettings); subject.RetryRequested = value; var result = subject.RetryRequested; result.Should().Be(value); }
public void NameOnly_get_and_set_should_work( [Values(false, true)] bool nameOnly) { var subject = new ListDatabasesOperation(_messageEncoderSettings); subject.NameOnly = nameOnly; var result = subject.NameOnly; result.Should().Be(nameOnly); }
public void AuthorizedDatabases_get_and_set_should_work( [Values(null, false, true)] bool?authorizedDatabases) { var subject = new ListDatabasesOperation(_messageEncoderSettings); subject.AuthorizedDatabases = authorizedDatabases; var result = subject.AuthorizedDatabases; result.Should().Be(authorizedDatabases); }
public void Filter_get_and_set_should_work() { var subject = new ListDatabasesOperation(_messageEncoderSettings); var filter = new BsonDocument("name", "abc"); subject.Filter = filter; var result = subject.Filter; result.Should().BeSameAs(filter); }
public void Execute_should_throw_when_binding_is_null( [Values(false, true)] bool async) { var subject = new ListDatabasesOperation(_messageEncoderSettings); IReadBinding binding = null; Action action = () => ExecuteOperation(subject, binding, async); action.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("binding"); }
public void CreateCommand_should_return_expected_result() { var subject = new ListDatabasesOperation(_messageEncoderSettings); var expectedResult = new BsonDocument { { "listDatabases", 1 } }; var result = subject.CreateCommand(); result.Should().Be(expectedResult); }
public void Execute_should_return_expected_result( [Values(false, true)] bool async) { RequireServer.Check(); var subject = new ListDatabasesOperation(_messageEncoderSettings); EnsureDatabaseExists(async); var result = ExecuteOperation(subject, async); var list = ReadCursorToEnd(result, async); list.Should().Contain(x => x["name"] == _databaseNamespace.DatabaseName); }
public async Task ExecuteAsync_should_return_expected_result() { using (var binding = CoreTestConfiguration.GetReadWriteBinding()) { var subject = new ListDatabasesOperation(_messageEncoderSettings); EnsureDatabaseExists(binding); var result = await subject.ExecuteAsync(binding, CancellationToken.None); var list = await result.ToListAsync(); list.Should().Contain(x => x["name"] == _databaseNamespace.DatabaseName); } }
public void Execute_should_return_the_expected_result_when_filter_is_used( [Values(false, true)] bool async) { RequireServer.Check().Supports(Feature.ListDatabasesFilter); var filterString = $"{{ name : \"{_databaseNamespace.DatabaseName}\" }}"; var filter = BsonDocument.Parse(filterString); var subject = new ListDatabasesOperation(_messageEncoderSettings) { Filter = filter }; EnsureDatabaseExists(async); var result = ExecuteOperation(subject, async); var databases = ReadCursorToEnd(result, async); databases.Should().HaveCount(1); databases[0]["name"].AsString.Should().Be(_databaseNamespace.DatabaseName); }
public void constructor_should_initialize_subject() { var subject = new ListDatabasesOperation(_messageEncoderSettings); subject.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings); }