Ejemplo n.º 1
0
        public void RenameCollection_should_execute_the_RenameCollectionOperation(
            [Values(false, true)] bool async)
        {
            var writeConcern = new WriteConcern(1);
            var subject      = _subject.WithWriteConcern(writeConcern);
            var options      = new RenameCollectionOptions
            {
                DropTarget = false,
            };

            if (async)
            {
                subject.RenameCollectionAsync("bar", "baz", options, CancellationToken.None).GetAwaiter().GetResult();
            }
            else
            {
                subject.RenameCollection("bar", "baz", options, CancellationToken.None);
            }

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

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

            op.CollectionNamespace.Should().Be(new CollectionNamespace(new DatabaseNamespace("foo"), "bar"));
            op.NewCollectionNamespace.Should().Be(new CollectionNamespace(new DatabaseNamespace("foo"), "baz"));
            op.DropTarget.Should().Be(options.DropTarget);
            op.WriteConcern.Should().BeSameAs(writeConcern);
        }
Ejemplo n.º 2
0
        public override Task RenameCollectionAsync(string oldName, string newName, RenameCollectionOptions options, CancellationToken cancellationToken)
        {
            Ensure.IsNotNullOrEmpty(oldName, nameof(oldName));
            Ensure.IsNotNullOrEmpty(newName, nameof(newName));
            options = options ?? new RenameCollectionOptions();

            var operation = CreateRenameCollectionOperation(oldName, newName, options);

            return(ExecuteWriteOperationAsync(operation, cancellationToken));
        }
Ejemplo n.º 3
0
        public void RenameCollection_should_execute_a_RenameCollectionOperation(
            [Values(false, true)] bool usingSession,
            [Values(false, true)] bool async)
        {
            var writeConcern = new WriteConcern(1);
            var subject      = _subject.WithWriteConcern(writeConcern);
            var session      = CreateSession(usingSession);
            var oldName      = "bar";
            var newName      = "baz";
            var options      = new RenameCollectionOptions
            {
                DropTarget = true,
            };
            var cancellationToken = new CancellationTokenSource().Token;

            if (usingSession)
            {
                if (async)
                {
                    subject.RenameCollectionAsync(session, oldName, newName, options, cancellationToken).GetAwaiter().GetResult();
                }
                else
                {
                    subject.RenameCollection(session, oldName, newName, options, cancellationToken);
                }
            }
            else
            {
                if (async)
                {
                    subject.RenameCollectionAsync(oldName, newName, options, cancellationToken).GetAwaiter().GetResult();
                }
                else
                {
                    subject.RenameCollection(oldName, newName, options, cancellationToken);
                }
            }

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

            VerifySessionAndCancellationToken(call, session, cancellationToken);

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

            op.CollectionNamespace.Should().Be(new CollectionNamespace(_subject.DatabaseNamespace, oldName));
            op.NewCollectionNamespace.Should().Be(new CollectionNamespace(_subject.DatabaseNamespace, newName));
            op.DropTarget.Should().Be(options.DropTarget);
            op.WriteConcern.Should().BeSameAs(writeConcern);
        }
Ejemplo n.º 4
0
        public override Task RenameCollectionAsync(string oldName, string newName, RenameCollectionOptions options, CancellationToken cancellationToken)
        {
            Ensure.IsNotNullOrEmpty(oldName, nameof(oldName));
            Ensure.IsNotNullOrEmpty(newName, nameof(newName));

            var messageEncoderSettings = GetMessageEncoderSettings();
            var operation = new RenameCollectionOperation(
                new CollectionNamespace(_databaseNamespace, oldName),
                new CollectionNamespace(_databaseNamespace, newName),
                messageEncoderSettings)
            {
                DropTarget = options == null ? null : options.DropTarget
            };

            return(ExecuteWriteOperationAsync(operation, cancellationToken));
        }
Ejemplo n.º 5
0
        public async Task RenameCollectionAsync_should_execute_the_RenameCollectionOperation()
        {
            var options = new RenameCollectionOptions
            {
                DropTarget = false,
            };
            await _subject.RenameCollectionAsync("bar", "baz", options, CancellationToken.None);

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

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

            op.CollectionNamespace.Should().Be(new CollectionNamespace(new DatabaseNamespace("foo"), "bar"));
            op.NewCollectionNamespace.Should().Be(new CollectionNamespace(new DatabaseNamespace("foo"), "baz"));
            op.DropTarget.Should().Be(options.DropTarget);
        }
Ejemplo n.º 6
0
        private RenameCollectionOperation CreateRenameCollectionOperation(string oldName, string newName, RenameCollectionOptions options)
        {
            var messageEncoderSettings = GetMessageEncoderSettings();

            return(new RenameCollectionOperation(
                       new CollectionNamespace(_databaseNamespace, oldName),
                       new CollectionNamespace(_databaseNamespace, newName),
                       messageEncoderSettings)
            {
                DropTarget = options.DropTarget,
                WriteConcern = _settings.WriteConcern
            });
        }
Ejemplo n.º 7
0
 public override Task RenameCollectionAsync(string oldName, string newName, RenameCollectionOptions options, CancellationToken cancellationToken)
 {
     return(UsingImplicitSessionAsync(session => RenameCollectionAsync(session, oldName, newName, options, cancellationToken), cancellationToken));
 }
Ejemplo n.º 8
0
        public override void RenameCollection(IClientSessionHandle session, string oldName, string newName, RenameCollectionOptions options, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(session, nameof(session));
            Ensure.IsNotNullOrEmpty(oldName, nameof(oldName));
            Ensure.IsNotNullOrEmpty(newName, nameof(newName));
            options = options ?? new RenameCollectionOptions();

            var operation = CreateRenameCollectionOperation(oldName, newName, options);

            ExecuteWriteOperation(session, operation, cancellationToken);
        }
Ejemplo n.º 9
0
 public override void RenameCollection(string oldName, string newName, RenameCollectionOptions options, CancellationToken cancellationToken)
 {
     UsingImplicitSession(session => RenameCollection(session, oldName, newName, options, cancellationToken), cancellationToken);
 }
        public async Task RenameCollectionAsync_should_execute_the_RenameCollectionOperation()
        {
            var options = new RenameCollectionOptions
            {
                DropTarget = false,
            };
            await _subject.RenameCollectionAsync("bar", "baz", options, CancellationToken.None);

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

            call.Operation.Should().BeOfType<RenameCollectionOperation>();
            var op = (RenameCollectionOperation)call.Operation;
            op.CollectionNamespace.Should().Be(new CollectionNamespace(new DatabaseNamespace("foo"), "bar"));
            op.NewCollectionNamespace.Should().Be(new CollectionNamespace(new DatabaseNamespace("foo"), "baz"));
            op.DropTarget.Should().Be(options.DropTarget);
        }
 /// <inheritdoc />
 public virtual Task RenameCollectionAsync(IClientSessionHandle session, string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
 /// <inheritdoc />
 public abstract Task RenameCollectionAsync(string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
 /// <inheritdoc />
 public virtual void RenameCollection(string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 14
0
        public void RenameCollection_should_execute_the_RenameCollectionOperation(
            [Values(false, true)] bool async)
        {
            var options = new RenameCollectionOptions
            {
                DropTarget = false,
            };

            if (async)
            {
                _subject.RenameCollectionAsync("bar", "baz", options, CancellationToken.None).GetAwaiter().GetResult();
            }
            else
            {
                _subject.RenameCollection("bar", "baz", options, CancellationToken.None);
            }

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

            call.Operation.Should().BeOfType<RenameCollectionOperation>();
            var op = (RenameCollectionOperation)call.Operation;
            op.CollectionNamespace.Should().Be(new CollectionNamespace(new DatabaseNamespace("foo"), "bar"));
            op.NewCollectionNamespace.Should().Be(new CollectionNamespace(new DatabaseNamespace("foo"), "baz"));
            op.DropTarget.Should().Be(options.DropTarget);
        }