Ejemplo n.º 1
0
        private ListCollectionsOperation CreateListCollectionNamesOperation(ListCollectionNamesOptions options)
        {
            var messageEncoderSettings = GetMessageEncoderSettings();

            return(new ListCollectionsOperation(_databaseNamespace, messageEncoderSettings)
            {
                Filter = options?.Filter?.Render(_settings.SerializerRegistry.GetSerializer <BsonDocument>(), _settings.SerializerRegistry),
                NameOnly = true
            });
        }
Ejemplo n.º 2
0
        private ListCollectionsOperation CreateListCollectionNamesOperation(ListCollectionNamesOptions options)
        {
            var messageEncoderSettings = GetMessageEncoderSettings();

            return(new ListCollectionsOperation(_databaseNamespace, messageEncoderSettings)
            {
                AuthorizedCollections = options?.AuthorizedCollections,
                Filter = options?.Filter?.Render(_settings.SerializerRegistry.GetSerializer <BsonDocument>(), _settings.SerializerRegistry, _linqProvider),
                NameOnly = true,
                RetryRequested = _client.Settings.RetryReads
            });
        }
Ejemplo n.º 3
0
        public void ListCollectionNames_should_execute_a_ListCollectionsOperation(
            [Values(false, true)] bool usingSession,
            [Values(false, true)] bool usingOptions,
            [Values(false, true)] bool async)
        {
            var session          = CreateSession(usingSession);
            var filterDocument   = BsonDocument.Parse("{ name : \"awesome\" }");
            var filterDefinition = (FilterDefinition <BsonDocument>)filterDocument;
            ListCollectionNamesOptions options = null;

            if (usingOptions)
            {
                options = new ListCollectionNamesOptions
                {
                    Filter = filterDefinition
                };
            }
            var cancellationToken = new CancellationTokenSource().Token;

            var mockCursor = new Mock <IAsyncCursor <BsonDocument> >();

            _operationExecutor.EnqueueResult <IAsyncCursor <BsonDocument> >(mockCursor.Object);

            if (usingSession)
            {
                if (async)
                {
                    _subject.ListCollectionNamesAsync(session, options, cancellationToken).GetAwaiter().GetResult();
                }
                else
                {
                    _subject.ListCollectionNames(session, options, cancellationToken);
                }
            }
            else
            {
                if (async)
                {
                    _subject.ListCollectionNamesAsync(options, cancellationToken).GetAwaiter().GetResult();
                }
                else
                {
                    _subject.ListCollectionNames(options, cancellationToken);
                }
            }

            var call = _operationExecutor.GetReadCall <IAsyncCursor <BsonDocument> >();

            VerifySessionAndCancellationToken(call, session, cancellationToken);

            var op = call.Operation.Should().BeOfType <ListCollectionsOperation>().Subject;

            op.DatabaseNamespace.Should().Be(_subject.DatabaseNamespace);
            op.NameOnly.Should().BeTrue();
            if (usingOptions)
            {
                op.Filter.Should().Be(filterDocument);
            }
            else
            {
                op.Filter.Should().BeNull();
            }
            op.RetryRequested.Should().BeTrue();
        }
Ejemplo n.º 4
0
        public override async Task <IAsyncCursor <string> > ListCollectionNamesAsync(IClientSessionHandle session, ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(session, nameof(session));
            var operation = CreateListCollectionNamesOperation(options);
            var effectiveReadPreference = ReadPreferenceResolver.GetEffectiveReadPreference(session, null, ReadPreference.Primary);
            var cursor = await ExecuteReadOperationAsync(session, operation, effectiveReadPreference, cancellationToken).ConfigureAwait(false);

            return(new BatchTransformingAsyncCursor <BsonDocument, string>(cursor, ExtractCollectionNames));
        }
Ejemplo n.º 5
0
 public override Task <IAsyncCursor <string> > ListCollectionNamesAsync(ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(UsingImplicitSessionAsync(session => ListCollectionNamesAsync(session, options, cancellationToken), cancellationToken));
 }
 /// <inheritdoc />
 public virtual Task <IAsyncCursor <string> > ListCollectionNamesAsync(IClientSessionHandle session, ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
 /// <inheritdoc />
 public virtual IAsyncCursor <string> ListCollectionNames(ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }