コード例 #1
0
        public void WriteConcern_get_and_set_should_work(
            [Values(null, 1, 2)]
            int?w)
        {
            var indexName = "x_1";
            var subject   = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings);
            var value     = w.HasValue ? new WriteConcern(w.Value) : null;

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

            result.Should().BeSameAs(value);
        }
コード例 #2
0
        public void Execute_should_return_expected_result(
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check();
            EnsureIndexExists();
            var indexName = "x_1";
            var subject   = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings);

            var result = ExecuteOperation(subject, async);

            result["ok"].ToBoolean().Should().BeTrue();
        }
コード例 #3
0
        public void MaxTime_set_should_throw_when_value_is_invalid(
            [Values(-10001, -9999, -42, -1)] long maxTimeTicks)
        {
            var indexName = "x_1";
            var subject   = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings);
            var value     = TimeSpan.FromTicks(maxTimeTicks);

            var exception = Record.Exception(() => subject.MaxTime = value);

            var e = exception.Should().BeOfType <ArgumentOutOfRangeException>().Subject;

            e.ParamName.Should().Be("value");
        }
コード例 #4
0
        public void constructor_with_collectionNamespace_keys_messageEncoderSettings_should_initialize_subject()
        {
            var keys = new BsonDocument {
                { "x", 1 }
            };
            var expectedIndexName = "x_1";

            var subject = new DropIndexOperation(_collectionNamespace, keys, _messageEncoderSettings);

            subject.CollectionNamespace.Should().BeSameAs(_collectionNamespace);
            subject.IndexName.Should().Be(expectedIndexName);
            subject.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings);
        }
コード例 #5
0
        public void CreateCommand_should_return_expectedResult()
        {
            var indexName      = "x_1";
            var subject        = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings);
            var expectedResult = new BsonDocument
            {
                { "dropIndexes", _collectionNamespace.CollectionName },
                { "index", indexName }
            };

            var result = subject.CreateCommand(null);

            result.Should().Be(expectedResult);
        }
コード例 #6
0
        public void Execute_should_not_throw_when_collection_does_not_exist(
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check();
            DropCollection();
            using (var binding = CoreTestConfiguration.GetReadWriteBinding())
            {
                var indexName = "x_1";
                var subject   = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings);

                ExecuteOperation(subject, async); // should not throw
            }
        }
コード例 #7
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);
            EnsureIndexExists();
            var indexName = "x_1";
            var subject   = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings)
            {
                WriteConcern = new WriteConcern(9)
            };

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

            exception.Should().BeOfType <MongoWriteConcernException>();
        }
コード例 #8
0
        public void Execute_should_return_expected_result(
            [Values(false, true)]
            bool async)
        {
            var keys                 = new BsonDocument("x", 1);
            var requests             = new[] { new CreateIndexRequest(keys) };
            var createIndexOperation = new CreateIndexesOperation(_collectionNamespace, requests, _messageEncoderSettings);

            ExecuteOperation(createIndexOperation, async);
            var indexName = "x_1";
            var subject   = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings);

            var result = ExecuteOperation(subject, async);

            result["ok"].ToBoolean().Should().BeTrue();
        }
コード例 #9
0
        public void Execute_should_throw_when_maxTime_is_exceeded(
            [Values(false, true)] bool async)
        {
            RequireServer.Check().Supports(Feature.FailPoints).ClusterTypes(ClusterType.Standalone, ClusterType.ReplicaSet);
            var indexName = "x_1";
            var subject   = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings)
            {
                MaxTime = TimeSpan.FromSeconds(9001)
            };

            using (var failPoint = FailPoint.ConfigureAlwaysOn(_cluster, _session, FailPointName.MaxTimeAlwaysTimeout))
            {
                var exception = Record.Exception(() => ExecuteOperation(subject, failPoint.Binding, async));

                exception.Should().BeOfType <MongoExecutionTimeoutException>();
            }
        }
コード例 #10
0
        public async Task ExecuteAsync_should_return_expected_result()
        {
            using (var binding = CoreTestConfiguration.GetReadWriteBinding())
            {
                var keys                 = new BsonDocument("x", 1);
                var requests             = new[] { new CreateIndexRequest(keys) };
                var createIndexOperation = new CreateIndexesOperation(_collectionNamespace, requests, _messageEncoderSettings);
                await createIndexOperation.ExecuteAsync(binding, CancellationToken.None);

                var indexName = "x_1";
                var subject   = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings);

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

                result["ok"].ToBoolean().Should().BeTrue();
            }
        }
コード例 #11
0
        public void CreateCommand_should_return_expected_result_when_MaxTime_is_Set(long maxTimeTicks, int expectedMaxTimeMS)
        {
            var indexName = "x_1";
            var maxTime   = TimeSpan.FromTicks(maxTimeTicks);
            var subject   = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings);

            subject.MaxTime = maxTime;
            var expectedResult = new BsonDocument
            {
                { "dropIndexes", _collectionNamespace.CollectionName },
                { "index", indexName },
                { "maxTimeMS", expectedMaxTimeMS }
            };

            var result = subject.CreateCommand(null);

            result.Should().Be(expectedResult);
            result["maxTimeMS"].BsonType.Should().Be(BsonType.Int32);
        }
コード例 #12
0
        public void CreateCommand_should_return_expectedResult_when_WriteConcern_is_set(
            [Values(null, 1, 2)]
            int?w)
        {
            var indexName    = "x_1";
            var writeConcern = w.HasValue ? new WriteConcern(w.Value) : null;
            var subject      = new DropIndexOperation(_collectionNamespace, indexName, _messageEncoderSettings)
            {
                WriteConcern = writeConcern
            };
            var session = OperationTestHelper.CreateSession();
            var connectionDescription = OperationTestHelper.CreateConnectionDescription();

            var result = subject.CreateCommand(session);

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

            result.Should().Be(expectedResult);
        }