public void CreateCommand_should_return_expected_result_when_WriteConcern_is_set(
            [Values(null, 1, 2)]
            int?w,
            [Values(false, true)]
            bool isWriteConcernSupported)
        {
            var writeConcern = w.HasValue ? new WriteConcern(w.Value) : null;
            var subject      = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings)
            {
                WriteConcern = writeConcern
            };
            var serverVersion         = Feature.CommandsThatWriteAcceptWriteConcern.SupportedOrNotSupportedVersion(isWriteConcernSupported);
            var session               = OperationTestHelper.CreateSession();
            var connectionDescription = OperationTestHelper.CreateConnectionDescription(serverVersion: serverVersion);

            var result = subject.CreateCommand(session, connectionDescription);

            var expectedResult = new BsonDocument
            {
                { "drop", _collectionNamespace.CollectionName },
                { "writeConcern", () => writeConcern.ToBsonDocument(), writeConcern != null && isWriteConcernSupported }
            };

            result.Should().Be(expectedResult);
        }
Example #2
0
        public void constructor_should_initialize_subject()
        {
            var subject = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);

            subject.CollectionNamespace.Should().BeSameAs(_collectionNamespace);
            subject.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings);
        }
        internal static IWriteOperation <BsonDocument> CreateEncryptedDropCollectionOperationIfConfigured(
            CollectionNamespace collectionNamespace,
            BsonDocument encryptedFields,
            MessageEncoderSettings messageEncoderSettings,
            Action <DropCollectionOperation> configureDropCollectionConfigurator)
        {
            var mainOperation = new DropCollectionOperation(collectionNamespace, messageEncoderSettings)
            {
                EncryptedFields = encryptedFields
            };

            configureDropCollectionConfigurator?.Invoke(mainOperation);

            if (encryptedFields != null)
            {
                return(new CompositeWriteOperation <BsonDocument>(
                           (CreateInnerDropOperation(EncryptedCollectionHelper.GetAdditionalCollectionName(encryptedFields, collectionNamespace, HelperCollectionForEncryption.Esc)), IsMainOperation: false),
                           (CreateInnerDropOperation(EncryptedCollectionHelper.GetAdditionalCollectionName(encryptedFields, collectionNamespace, HelperCollectionForEncryption.Ecc)), IsMainOperation: false),
                           (CreateInnerDropOperation(EncryptedCollectionHelper.GetAdditionalCollectionName(encryptedFields, collectionNamespace, HelperCollectionForEncryption.Ecos)), IsMainOperation: false),
                           (mainOperation, IsMainOperation: true)));
            }
            else
            {
                return(mainOperation);
            }

            DropCollectionOperation CreateInnerDropOperation(string collectionName)
            => new DropCollectionOperation(new CollectionNamespace(collectionNamespace.DatabaseNamespace.DatabaseName, collectionName), messageEncoderSettings);
        }
        // private methods
        private void DropView(string viewName)
        {
            var collectionNamespace = new CollectionNamespace(_databaseNamespace, viewName);
            var operation           = new DropCollectionOperation(collectionNamespace, _messageEncoderSettings);

            ExecuteOperation(operation);
        }
Example #5
0
        public void CollectionNamespace_get_should_return_expected_result()
        {
            var subject = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);

            var result = subject.CollectionNamespace;

            result.Should().BeSameAs(_collectionNamespace);
        }
        // helper methods
        private void DropCollection()
        {
            var operation = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);

            using (var binding = CoreTestConfiguration.GetReadWriteBinding())
            {
                operation.ExecuteAsync(binding, CancellationToken.None).GetAwaiter().GetResult();
            }
        }
Example #7
0
        public void Execute_should_send_session_id_when_supported(
            [Values(false, true)] bool async)
        {
            RequireServer.Check();
            EnsureCollectionExists();
            var subject = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);

            VerifySessionIdWasSentWhenSupported(subject, "drop", async);
        }
Example #8
0
        // helper methods
        public void DropCollection()
        {
            var operation = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);

            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                operation.Execute(binding);
            }
        }
Example #9
0
        public void Execute_should_not_throw_when_collection_does_not_exist(
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check();
            DropCollection();
            var subject = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);

            ExecuteOperation(subject, async); // this will throw if we have a problem...
        }
Example #10
0
        public async Task ExecuteAsync_should_not_throw_when_collection_does_not_exist()
        {
            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var subject = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);
                var dropCollectionOperation = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);
                await dropCollectionOperation.ExecuteAsync(binding, CancellationToken.None);

                await subject.ExecuteAsync(binding, CancellationToken.None); // this will throw if we have a problem...
            }
        }
Example #11
0
        public void WriteConcern_get_and_set_should_work(
            [Values(null, 1, 2)]
            int?w)
        {
            var subject = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);
            var value   = w.HasValue ? new WriteConcern(w.Value) : null;

            subject.WriteConcern = value;
            var result = subject.WriteConcern;

            result.Should().BeSameAs(value);
        }
Example #12
0
        public void CreateCommand_should_return_expected_result()
        {
            var subject        = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);
            var expectedResult = new BsonDocument
            {
                { "drop", _collectionNamespace.CollectionName }
            };

            var result = subject.CreateCommand();

            result.Should().Be(expectedResult);
        }
 public void Execute_should_not_throw_when_collection_does_not_exist(
     [Values(false, true)]
     bool async)
 {
     using (var binding = CoreTestConfiguration.GetReadWriteBinding())
     {
         var subject = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);
         var dropCollectionOperation = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);
         ExecuteOperation(dropCollectionOperation, binding, async);
         ExecuteOperation(subject, binding, async); // this will throw if we have a problem...
     }
 }
Example #14
0
        public void Execute_should_return_expected_result(
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check();
            EnsureCollectionExists();
            var subject = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);

            var result = ExecuteOperation(subject, async);

            result["ok"].ToBoolean().Should().BeTrue();
            result["ns"].ToString().Should().Be(_collectionNamespace.FullName);
        }
        public async Task ExecuteAsync_should_not_throw_when_collection_does_not_exist()
        {
            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var subject = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);
                var dropCollectionOperation = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);
                await dropCollectionOperation.ExecuteAsync(binding);

                Func <Task> action = async() => { await subject.ExecuteAsync(binding); };

                action.ShouldNotThrow();
            }
        }
Example #16
0
        public async Task ExecuteAsync_should_return_expected_result()
        {
            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var subject = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);
                var createCollectionOperation = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings);
                await createCollectionOperation.ExecuteAsync(binding, CancellationToken.None);

                var result = await subject.ExecuteAsync(binding, CancellationToken.None);

                result["ok"].ToBoolean().Should().BeTrue();
                result["ns"].ToString().Should().Be(_collectionNamespace.FullName);
            }
        }
            public void Dispose()
            {
                var turnOff = new WriteCommandOperation <BsonDocument>(
                    _databaseNamespace,
                    new BsonDocument("profile", 0),
                    BsonDocumentSerializer.Instance,
                    new MessageEncoderSettings());

                _testBase.ExecuteOperation(turnOff);

                var drop = new DropCollectionOperation(CollectionNamespace, new MessageEncoderSettings());

                _testBase.ExecuteOperation(drop);
            }
Example #18
0
        public void Execute_should_throw_when_a_write_concern_error_occurs(
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check().Supports(Feature.CommandsThatWriteAcceptWriteConcern).ClusterType(ClusterType.ReplicaSet);
            EnsureCollectionExists();
            var subject = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings)
            {
                WriteConcern = new WriteConcern(9)
            };

            var exception = Record.Exception(() => ExecuteOperation(subject, async));

            exception.Should().BeOfType <MongoWriteConcernException>();
        }
        public void Execute_should_return_expected_result(
            [Values(false, true)]
            bool async)
        {
            using (var binding = CoreTestConfiguration.GetReadWriteBinding())
            {
                var subject = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);
                var createCollectionOperation = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings);
                ExecuteOperation(createCollectionOperation, binding, async);

                var result = ExecuteOperation(subject, binding, async);

                result["ok"].ToBoolean().Should().BeTrue();
                result["ns"].ToString().Should().Be(_collectionNamespace.FullName);
            }
        }
        public void CreateEncryptedDropCollectionOperationIfConfigured_should_return_expected_result_when_EncryptedFields_is_null()
        {
            var subject = DropCollectionOperation.CreateEncryptedDropCollectionOperationIfConfigured(_collectionNamespace, encryptedFields: null, _messageEncoderSettings, null);
            var session = OperationTestHelper.CreateSession();

            var s = subject.Should().BeOfType <DropCollectionOperation>().Subject;

            var command = s.CreateCommand(session);

            var expectedResult = new BsonDocument
            {
                { "drop", _collectionNamespace.CollectionName },
            };

            command.Should().Be(expectedResult);
        }
Example #21
0
        public void CreateCommand_should_return_expected_result_when_WriteConcern_is_set(
            [Values(null, 1, 2)]
            int?w)
        {
            var writeConcern = w.HasValue ? new WriteConcern(w.Value) : null;
            var subject      = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings)
            {
                WriteConcern = writeConcern
            };
            var session = OperationTestHelper.CreateSession();

            var result = subject.CreateCommand(session);

            var expectedResult = new BsonDocument
            {
                { "drop", _collectionNamespace.CollectionName },
                { "writeConcern", () => writeConcern.ToBsonDocument(), writeConcern != null }
            };

            result.Should().Be(expectedResult);
        }
Example #22
0
        // helper methods
        private void EnsureTestData()
        {
            if (_testDataHasBeenCreated)
            {
                return;
            }

            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                var dropCollectionOperation = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);
                dropCollectionOperation.Execute(binding);

                var requests = Enumerable.Range(1, 5)
                               .Select(id => new BsonDocument("_id", id))
                               .Select(document => new InsertRequest(document));
                var insertOperation = new BulkInsertOperation(_collectionNamespace, requests, _messageEncoderSettings);
                insertOperation.Execute(binding);
            }

            _testDataHasBeenCreated = true;
        }
Example #23
0
        // helper methods
        public Task DropCollectionAsync(IWriteBinding binding)
        {
            var operation = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);

            return(operation.ExecuteAsync(binding, CancellationToken.None));
        }
        // helper methods
        private void EnsureCollectionDoesNotExist(CollectionNamespace collectionNamespace, bool async)
        {
            var operation = new DropCollectionOperation(collectionNamespace, _messageEncoderSettings);

            ExecuteOperation(operation, async);
        }
Example #25
0
        // helper methods
        private void EnsureCollectionDoesNotExist(IWriteBinding binding, CollectionNamespace collectionNamespace)
        {
            var operation = new DropCollectionOperation(collectionNamespace, _messageEncoderSettings);

            operation.ExecuteAsync(binding, CancellationToken.None).GetAwaiter().GetResult();
        }
        // helper methods
        private void EnsureCollectionDoesNotExist(IWriteBinding binding, CollectionNamespace collectionNamespace)
        {
            var operation = new DropCollectionOperation(collectionNamespace, _messageEncoderSettings);

            operation.Execute(binding);
        }
Example #27
0
        // private methods
        private void DropCollection()
        {
            var operation = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);

            ExecuteOperation(operation, false);
        }
Example #28
0
        protected void DropCollection()
        {
            var dropCollectionOperation = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);

            ExecuteOperation(dropCollectionOperation);
        }
Example #29
0
        protected Task DropCollectionAsync()
        {
            var dropCollectionOperation = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);

            return(ExecuteOperationAsync(dropCollectionOperation));
        }
        // helper methods
        public void DropCollection(bool async)
        {
            var operation = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);

            ExecuteOperation(operation, async);
        }