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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 8
0
        // helper methods
        public void DropCollection()
        {
            var operation = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);

            using (var binding = SuiteConfiguration.GetReadWriteBinding())
            {
                operation.Execute(binding);
            }
        }
Ejemplo n.º 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...
        }
Ejemplo n.º 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...
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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...
     }
 }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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);
            }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 27
0
        // private methods
        private void DropCollection()
        {
            var operation = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);

            ExecuteOperation(operation, false);
        }
Ejemplo n.º 28
0
        protected void DropCollection()
        {
            var dropCollectionOperation = new DropCollectionOperation(_collectionNamespace, _messageEncoderSettings);

            ExecuteOperation(dropCollectionOperation);
        }
Ejemplo n.º 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);
        }