예제 #1
0
        private Task <BsonDocument> ExplainFindAsync <TResult>(FindModel <TResult> model, ExplainVerbosity verbosity, TimeSpan?timeout, CancellationToken cancellationToken)
        {
            var findOperation    = CreateFindOperation <TResult>(model);
            var explainOperation = findOperation.ToExplainOperation(verbosity.ToCore());

            return(ExecuteReadOperation(explainOperation, timeout, cancellationToken));
        }
예제 #2
0
        public Task <IAsyncEnumerable <TResult> > FindAsync <TResult>(FindModel <TResult> model, TimeSpan?timeout, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(model, "model");

            var operation = CreateFindOperation <TResult>(model);

            return(Task.FromResult <IAsyncEnumerable <TResult> >(new AsyncCursorAsyncEnumerable <TResult>(
                                                                     () => ExecuteReadOperation(operation, timeout, cancellationToken),
                                                                     model.Limit)));
        }
        public async Task FindAsync_should_execute_the_FindOperation()
        {
            var criteria   = BsonDocument.Parse("{x:1}");
            var projection = BsonDocument.Parse("{y:1}");
            var sort       = BsonDocument.Parse("{a:1}");
            var model      = new FindModel <BsonDocument>
            {
                AwaitData       = false,
                BatchSize       = 20,
                Comment         = "funny",
                Criteria        = criteria,
                Limit           = 30,
                MaxTime         = TimeSpan.FromSeconds(3),
                Modifiers       = BsonDocument.Parse("{$snapshot: true}"),
                NoCursorTimeout = true,
                Partial         = true,
                Projection      = projection,
                Skip            = 40,
                Sort            = sort,
                Tailable        = true
            };

            var fakeCursor = Substitute.For <IAsyncCursor <BsonDocument> >();

            _operationExecutor.EnqueueResult(fakeCursor);

            var result = await _subject.FindAsync(model, Timeout.InfiniteTimeSpan, CancellationToken.None);

            // we haven't executed the operation yet.
            _operationExecutor.QueuedCallCount.Should().Be(0);

            // this causes execution of the operation
            await result.GetAsyncEnumerator().MoveNextAsync();

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

            call.Operation.Should().BeOfType <FindOperation <BsonDocument> >();
            var operation = (FindOperation <BsonDocument>)call.Operation;

            operation.CollectionNamespace.FullName.Should().Be("foo.bar");
            operation.AwaitData.Should().Be(model.AwaitData);
            operation.BatchSize.Should().Be(model.BatchSize);
            operation.Comment.Should().Be("funny");
            operation.Criteria.Should().Be(criteria);
            operation.Limit.Should().Be(model.Limit);
            operation.MaxTime.Should().Be(model.MaxTime);
            operation.Modifiers.Should().Be(model.Modifiers);
            operation.NoCursorTimeout.Should().Be(model.NoCursorTimeout);
            operation.Partial.Should().Be(model.Partial);
            operation.Projection.Should().Be(projection);
            operation.Skip.Should().Be(model.Skip);
            operation.Sort.Should().Be(sort);
            operation.Tailable.Should().Be(model.Tailable);
        }
        public async Task ExplainAsync_for_find_should_execute_a_read_operation()
        {
            var findModel = new FindModel <BsonDocument>
            {
                Skip = 20
            };

            var model = new ExplainModel(findModel)
            {
                Verbosity = ExplainVerbosity.ExecutionStats
            };

            await _subject.ExplainAsync(model, Timeout.InfiniteTimeSpan, CancellationToken.None);

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

            call.Operation.Should().BeAssignableTo <IReadOperation <BsonDocument> >();
        }
예제 #5
0
        private FindOperation <TResult> CreateFindOperation <TResult>(FindModel <TResult> model)
        {
            var resultSerializer = model.ResultSerializer ?? _settings.SerializerRegistry.GetSerializer <TResult>();

            return(new FindOperation <TResult>(
                       _collectionNamespace,
                       resultSerializer,
                       _messageEncoderSettings)
            {
                AwaitData = model.AwaitData,
                BatchSize = model.BatchSize,
                Comment = model.Comment,
                Criteria = ConvertToBsonDocument(model.Criteria),
                Limit = model.Limit,
                MaxTime = model.MaxTime,
                Modifiers = model.Modifiers,
                NoCursorTimeout = model.NoCursorTimeout,
                Partial = model.Partial,
                Projection = ConvertToBsonDocument(model.Projection),
                Skip = model.Skip,
                Sort = ConvertToBsonDocument(model.Sort),
                Tailable = model.Tailable
            });
        }