public void Execute_should_return_the_expected_result_when_batchSize_is_used([Values(false, true)] bool async)
        {
            RequireServer.Check();
            EnsureCollectionsExist();
            int batchSize = 1;
            var subject   = new ListCollectionsOperation(_databaseNamespace, _messageEncoderSettings)
            {
                BatchSize = batchSize
            };

            using (var result = ExecuteOperation(subject, async))
            {
                AsyncCursor <BsonDocument> asyncCursor;
                if (Feature.ListCollectionsCommand.IsSupported(CoreTestConfiguration.ServerVersion))
                {
                    asyncCursor = (AsyncCursor <BsonDocument>)result;
                }
                else
                {
                    var batchTransformingAsyncCursor = (BatchTransformingAsyncCursor <BsonDocument, BsonDocument>)result;
                    asyncCursor = (AsyncCursor <BsonDocument>)batchTransformingAsyncCursor._wrapped();
                }
                asyncCursor._batchSize().Should().Be(batchSize);
            }
        }
Ejemplo n.º 2
0
        public void constructor_should_initialize_subject()
        {
            var subject = new ListCollectionsOperation(_databaseNamespace, _messageEncoderSettings);

            subject.DatabaseNamespace.Should().BeSameAs(_databaseNamespace);
            subject.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings);
            subject.Filter.Should().BeNull();
        }
Ejemplo n.º 3
0
        // methods
        public async Task <bool> ExecuteAsync(IReadBinding binding, TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(binding, "binding");
            var operation       = new ListCollectionsOperation(_databaseName);
            var collectionNames = await operation.ExecuteAsync(binding, timeout, cancellationToken);

            return(collectionNames.Contains(_collectionName));
        }
        private BsonDocument GetViewInfo(IReadBinding binding, string viewName)
        {
            var listCollectionsOperation = new ListCollectionsOperation(_collectionNamespace.DatabaseNamespace, _messageEncoderSettings)
            {
                Filter = new BsonDocument("name", viewName)
            };

            return(listCollectionsOperation.Execute(binding, CancellationToken.None).Single());
        }
        public async Task ExecuteAsync_should_return_the_expected_result_when_the_database_does_not_exist()
        {
            var databaseNamespace = new DatabaseNamespace(_databaseNamespace.DatabaseName + "-does-not-exist");
            var subject           = new ListCollectionsOperation(databaseNamespace, _messageEncoderSettings);

            var result = await ExecuteOperationAsync(subject);

            result.Should().HaveCount(0);
        }
        public async Task ExecuteAsync_should_return_the_expected_result()
        {
            var subject       = new ListCollectionsOperation(_databaseNamespace, _messageEncoderSettings);
            var expectedNames = new[] { "regular", "capped" };

            var result = await ExecuteOperationAsync(subject);

            result.Count.Should().BeGreaterThan(0);
            result.Select(c => c["name"].AsString).Where(n => n != "system.indexes").Should().BeEquivalentTo(expectedNames);
        }
Ejemplo n.º 7
0
        public void Filter_get_and_set_should_work()
        {
            var subject = new ListCollectionsOperation(_databaseNamespace, _messageEncoderSettings);
            var filter  = new BsonDocument("name", "abc");

            subject.Filter = filter;
            var result = subject.Filter;

            result.Should().BeSameAs(filter);
        }
        public void BatchSize_get_and_set_should_work()
        {
            var subject   = new ListCollectionsOperation(_databaseNamespace, _messageEncoderSettings);
            int batchSize = 2;

            subject.BatchSize = batchSize;
            var result = subject.BatchSize;

            result.Should().Be(batchSize);
        }
        public void RetryRequested_get_and_set_should_work(
            [Values(false, true)] bool value)
        {
            var subject = new ListCollectionsOperation(_databaseNamespace, _messageEncoderSettings);

            subject.RetryRequested = value;
            var result = subject.RetryRequested;

            result.Should().Be(value);
        }
        public void AuthorizedCollections_get_and_set_should_work()
        {
            var subject = new ListCollectionsOperation(_databaseNamespace, _messageEncoderSettings);
            var authorizedCollections = true;

            subject.AuthorizedCollections = authorizedCollections;
            var result = subject.AuthorizedCollections;

            result.Should().Be(authorizedCollections);
        }
        public void NameOnly_get_and_set_should_work(
            [Values(null, false, true)] bool?nameOnly)
        {
            var subject = new ListCollectionsOperation(_databaseNamespace, _messageEncoderSettings);

            subject.NameOnly = nameOnly;
            var result = subject.NameOnly;

            result.Should().Be(nameOnly);
        }
        public void Execute_should_send_session_id_when_supported(
            [Values(false, true)] bool async)
        {
            RequireServer.Check().Supports(Feature.ListCollectionsCommand);
            EnsureCollectionsExist();
            var subject       = new ListCollectionsOperation(_databaseNamespace, _messageEncoderSettings);
            var expectedNames = new[] { "regular", "capped" };

            VerifySessionIdWasSentWhenSupported(subject, "listCollections", async);
        }
Ejemplo n.º 13
0
        public void ExecuteAsync_should_throw_when_filter_name_is_not_a_string_and_connected_to_older_server()
        {
            var filter  = new BsonDocument("name", new BsonRegularExpression("^abc"));
            var subject = new ListCollectionsOperation(_databaseNamespace, _messageEncoderSettings)
            {
                Filter = filter
            };

            Func <Task> action = () => ExecuteOperationAsync(subject);

            action.ShouldThrow <NotSupportedException>();
        }
Ejemplo n.º 14
0
        public void Execute_should_return_the_expected_result_when_the_database_does_not_exist(
            [Values(false, true)]
            bool async)
        {
            var databaseNamespace = new DatabaseNamespace(_databaseNamespace.DatabaseName + "-not");
            var subject           = new ListCollectionsOperation(databaseNamespace, _messageEncoderSettings);

            var result = ExecuteOperation(subject, async);
            var list   = ReadCursorToEnd(result, async);

            list.Should().HaveCount(0);
        }
Ejemplo n.º 15
0
        public void Execute_should_return_the_expected_result(
            [Values(false, true)]
            bool async)
        {
            var subject       = new ListCollectionsOperation(_databaseNamespace, _messageEncoderSettings);
            var expectedNames = new[] { "regular", "capped" };

            var result = ExecuteOperation(subject, async);
            var list   = ReadCursorToEnd(result, async);

            list.Count.Should().BeGreaterThan(0);
            list.Select(c => c["name"].AsString).Where(n => n != "system.indexes").Should().BeEquivalentTo(expectedNames);
        }
        public async Task ExecuteAsync_should_return_the_expected_result_when_filter_is_used(string filterString, string expectedName)
        {
            var filter  = BsonDocument.Parse(filterString);
            var subject = new ListCollectionsOperation(_databaseNamespace, _messageEncoderSettings)
            {
                Filter = filter
            };

            var result = await ExecuteOperationAsync(subject);

            result.Should().HaveCount(1);
            result[0]["name"].AsString.Should().Be(expectedName);
        }
Ejemplo n.º 17
0
        public void Execute_should_return_the_expected_result_when_filter_is_used(string filterString, string expectedName, bool async)
        {
            var filter  = BsonDocument.Parse(filterString);
            var subject = new ListCollectionsOperation(_databaseNamespace, _messageEncoderSettings)
            {
                Filter = filter
            };

            var result = ExecuteOperation(subject, async);
            var list   = ReadCursorToEnd(result, async);

            list.Should().HaveCount(1);
            list[0]["name"].AsString.Should().Be(expectedName);
        }
        public void Execute_should_return_the_expected_result_when_batchSize_is_used([Values(false, true)] bool async)
        {
            RequireServer.Check();
            EnsureCollectionsExist();
            int batchSize = 1;
            var subject   = new ListCollectionsOperation(_databaseNamespace, _messageEncoderSettings)
            {
                BatchSize = batchSize
            };

            using (var cursor = ExecuteOperation(subject, async) as AsyncCursor <BsonDocument>)
            {
                cursor._batchSize().Should().Be(batchSize);
            }
        }
        public void Execute_should_throw_when_filter_name_is_not_a_string_and_connected_to_older_server(
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check().VersionLessThan("2.7.0");
            var filter  = new BsonDocument("name", new BsonRegularExpression("^abc"));
            var subject = new ListCollectionsOperation(_databaseNamespace, _messageEncoderSettings)
            {
                Filter = filter
            };

            Action action = () => ExecuteOperation(subject, async);

            action.ShouldThrow <NotSupportedException>();
        }
        public void CreateCommand_should_return_expected_result(
            bool?authorizedCollections,
            string filterString,
            bool?nameOnly,
            string expectedCommand)
        {
            var filter  = filterString == null ? null : BsonDocument.Parse(filterString);
            var subject = new ListCollectionsOperation(_databaseNamespace, _messageEncoderSettings)
            {
                AuthorizedCollections = authorizedCollections,
                Filter   = filter,
                NameOnly = nameOnly
            };

            var result = subject.CreateOperation();

            result.Command.Should().Be(expectedCommand);
            result.DatabaseNamespace.Should().BeSameAs(subject.DatabaseNamespace);
            result.ResultSerializer.Should().BeSameAs(BsonDocumentSerializer.Instance);
            result.MessageEncoderSettings.Should().BeSameAs(subject.MessageEncoderSettings);
        }
        public void CreateOperation_should_return_expected_result(
            [Values(null, false, true)] bool?nameOnly)
        {
            var filter  = new BsonDocument();
            var subject = new ListCollectionsOperation(_databaseNamespace, _messageEncoderSettings)
            {
                Filter   = filter,
                NameOnly = nameOnly
            };
            var connectionDescription = OperationTestHelper.CreateConnectionDescription();
            var mockChannel           = new Mock <IChannel>();

            mockChannel.SetupGet(m => m.ConnectionDescription).Returns(connectionDescription);

            var result = subject.CreateOperation(mockChannel.Object);

            var operation = result.Should().BeOfType <ListCollectionsUsingCommandOperation>().Subject;

            operation.Filter.Should().BeSameAs(subject.Filter);
            operation.DatabaseNamespace.Should().BeSameAs(subject.DatabaseNamespace);
            operation.MessageEncoderSettings.Should().BeSameAs(subject.MessageEncoderSettings);
            operation.NameOnly.Should().Be(subject.NameOnly);
        }
        public void CreateOperation_should_return_expected_result_when_list_collections_command_is_not_supported(
            [Values(null, false, true)] bool?nameOnly)
        {
            var filter  = new BsonDocument();
            var subject = new ListCollectionsOperation(_databaseNamespace, _messageEncoderSettings)
            {
                Filter   = filter,
                NameOnly = nameOnly
            };
            var serverVersion         = Feature.ListCollectionsCommand.LastNotSupportedVersion;
            var connectionDescription = OperationTestHelper.CreateConnectionDescription(serverVersion: serverVersion);
            var mockChannel           = new Mock <IChannel>();

            mockChannel.SetupGet(m => m.ConnectionDescription).Returns(connectionDescription);

            var result = subject.CreateOperation(mockChannel.Object);

            var operation = result.Should().BeOfType <ListCollectionsUsingQueryOperation>().Subject;

            operation.Filter.Should().BeSameAs(subject.Filter);
            operation.DatabaseNamespace.Should().BeSameAs(subject.DatabaseNamespace);
            operation.MessageEncoderSettings.Should().BeSameAs(subject.MessageEncoderSettings);
        }
 public static IReadOperation <IAsyncCursor <BsonDocument> > CreateOperation(this ListCollectionsOperation obj, IChannel channel) => (IReadOperation <IAsyncCursor <BsonDocument> >)Reflector.Invoke(obj, nameof(CreateOperation), channel);
 public static ReadCommandOperation <BsonDocument> CreateOperation(this ListCollectionsOperation obj) => (ReadCommandOperation <BsonDocument>)Reflector.Invoke(obj, nameof(CreateOperation));