public async Task AggregateAsync_should_execute_the_AggregateOperation_when_out_is_not_specified()
        {
            var pipeline = new object[] { BsonDocument.Parse("{$match: {x: 2}}") };
            var options  = new AggregateOptions <BsonDocument>()
            {
                AllowDiskUse = true,
                BatchSize    = 10,
                MaxTime      = TimeSpan.FromSeconds(3),
                UseCursor    = false
            };

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

            _operationExecutor.EnqueueResult(fakeCursor);

            await _subject.AggregateAsync(pipeline, options, CancellationToken.None);

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

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

            operation.CollectionNamespace.FullName.Should().Be("foo.bar");
            operation.AllowDiskUse.Should().Be(options.AllowDiskUse);
            operation.BatchSize.Should().Be(options.BatchSize);
            operation.MaxTime.Should().Be(options.MaxTime);
            operation.UseCursor.Should().Be(options.UseCursor);

            operation.Pipeline.Should().ContainInOrder(pipeline);
        }
        public async Task AggregateAsync_should_execute_the_AggregateOperation_when_out_is_not_specified()
        {
            var pipeline = new object[] { BsonDocument.Parse("{$match: {x: 2}}") };
            var model    = new AggregateModel <BsonDocument>(pipeline)
            {
                AllowDiskUse = true,
                BatchSize    = 10,
                MaxTime      = TimeSpan.FromSeconds(3),
                UseCursor    = false
            };

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

            _operationExecutor.EnqueueResult(fakeCursor);

            var result = await _subject.AggregateAsync(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 <AggregateOperation <BsonDocument> >();
            var operation = (AggregateOperation <BsonDocument>)call.Operation;

            operation.CollectionNamespace.FullName.Should().Be("foo.bar");
            operation.AllowDiskUse.Should().Be(model.AllowDiskUse);
            operation.BatchSize.Should().Be(model.BatchSize);
            operation.MaxTime.Should().Be(model.MaxTime);
            operation.UseCursor.Should().Be(model.UseCursor);

            operation.Pipeline.Should().ContainInOrder(pipeline);
        }