public async Task DropDatabaseAsync_should_invoke_the_correct_operation()
        {
            var operationExecutor = new MockOperationExecutor();
            var client = new MongoClient(operationExecutor);
            await client.DropDatabaseAsync("awesome");

            var call = operationExecutor.GetWriteCall<BsonDocument>();

            call.Operation.Should().BeOfType<DropDatabaseOperation>();
            ((DropDatabaseOperation)call.Operation).DatabaseNamespace.Should().Be(new DatabaseNamespace("awesome"));
        }
        public void DropDatabase_should_invoke_the_correct_operation(
            [Values(false, true)] bool async)
        {
            var operationExecutor = new MockOperationExecutor();
            var client = new MongoClient(operationExecutor);

            if (async)
            {
                client.DropDatabaseAsync("awesome").GetAwaiter().GetResult();
            }
            else
            {
                client.DropDatabase("awesome");
            }

            var call = operationExecutor.GetWriteCall<BsonDocument>();

            call.Operation.Should().BeOfType<DropDatabaseOperation>();
            ((DropDatabaseOperation)call.Operation).DatabaseNamespace.Should().Be(new DatabaseNamespace("awesome"));
        }
        public void DropDatabase_should_invoke_the_correct_operation(
            [Values(false, true)] bool async)
        {
            var operationExecutor = new MockOperationExecutor();
            var writeConcern = new WriteConcern(1);
            var client = new MongoClient(operationExecutor, new MongoClientSettings()).WithWriteConcern(writeConcern);

            if (async)
            {
                client.DropDatabaseAsync("awesome").GetAwaiter().GetResult();
            }
            else
            {
                client.DropDatabase("awesome");
            }

            var call = operationExecutor.GetWriteCall<BsonDocument>();

            var dropDatabaseOperation = call.Operation.Should().BeOfType<DropDatabaseOperation>().Subject;
            dropDatabaseOperation.DatabaseNamespace.Should().Be(new DatabaseNamespace("awesome"));
            dropDatabaseOperation.WriteConcern.Should().BeSameAs(writeConcern);
        }
        public async Task AggregateAsync_should_execute_the_AggregateToCollectionOperation_and_the_FindOperation_when_out_is_specified()
        {
            var pipeline = new object[] { BsonDocument.Parse("{$match: {x: 2}}"), BsonDocument.Parse("{$out: \"funny\"}") };
            var options  = new AggregateOptions <BsonDocument>()
            {
                AllowDiskUse = true,
                BatchSize    = 10,
                MaxTime      = TimeSpan.FromSeconds(3),
                UseCursor    = false
            };

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

            _operationExecutor.QueuedCallCount.Should().Be(1);
            var writeCall = _operationExecutor.GetWriteCall <BsonDocument>();

            writeCall.Operation.Should().BeOfType <AggregateToCollectionOperation>();
            var writeOperation = (AggregateToCollectionOperation)writeCall.Operation;

            writeOperation.CollectionNamespace.FullName.Should().Be("foo.bar");
            writeOperation.AllowDiskUse.Should().Be(options.AllowDiskUse);
            writeOperation.MaxTime.Should().Be(options.MaxTime);
            writeOperation.Pipeline.Should().BeEquivalentTo(pipeline);

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

            _operationExecutor.EnqueueResult(fakeCursor);

            await result.MoveNextAsync(CancellationToken.None);

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

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

            operation.CollectionNamespace.FullName.Should().Be("foo.funny");
            operation.AllowPartialResults.Should().BeFalse();
            operation.BatchSize.Should().Be(options.BatchSize);
            operation.Comment.Should().BeNull();
            operation.CursorType.Should().Be(Core.Operations.CursorType.NonTailable);
            operation.Filter.Should().BeNull();
            operation.Limit.Should().Be(null);
            operation.MaxTime.Should().Be(options.MaxTime);
            operation.Modifiers.Should().BeNull();
            operation.NoCursorTimeout.Should().BeFalse();
            operation.Projection.Should().BeNull();
            operation.Skip.Should().Be(null);
            operation.Sort.Should().BeNull();
        }