public void CreateCommand_should_return_expected_result_when_WriteConcern_is_set(
            [Values(1, 2)]
            int w,
            [Values(false, true)]
            bool isWriteConcernSupported)
        {
            var requests     = new[] { new CreateIndexRequest(new BsonDocument("x", 1)) };
            var writeConcern = new WriteConcern(w);
            var subject      = new CreateIndexesUsingCommandOperation(_collectionNamespace, requests, _messageEncoderSettings)
            {
                WriteConcern = writeConcern
            };
            var session = OperationTestHelper.CreateSession();
            var connectionDescription = OperationTestHelper.CreateConnectionDescription(serverVersion: Feature.CommandsThatWriteAcceptWriteConcern.SupportedOrNotSupportedVersion(isWriteConcernSupported));

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

            var expectedResult = new BsonDocument
            {
                { "createIndexes", _collectionNamespace.CollectionName },
                { "indexes", new BsonArray {
                      requests[0].CreateIndexDocument(null)
                  } },
                { "writeConcern", () => writeConcern.ToBsonDocument(), isWriteConcernSupported }
            };

            result.Should().Be(expectedResult);
        }
Beispiel #2
0
        public void CreateCommand_should_return_expected_result_when_WriteConcern_is_set(
            [Values(1, 2)]
            int w)
        {
            var requests     = new[] { new CreateIndexRequest(new BsonDocument("x", 1)) };
            var writeConcern = new WriteConcern(w);
            var subject      = new CreateIndexesUsingCommandOperation(_collectionNamespace, requests, _messageEncoderSettings)
            {
                WriteConcern = writeConcern
            };
            var session = OperationTestHelper.CreateSession();
            var connectionDescription = OperationTestHelper.CreateConnectionDescription();

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

            var expectedResult = new BsonDocument
            {
                { "createIndexes", _collectionNamespace.CollectionName },
                { "indexes", new BsonArray {
                      requests[0].CreateIndexDocument()
                  } },
                { "writeConcern", writeConcern.ToBsonDocument() }
            };

            result.Should().Be(expectedResult);
        }
Beispiel #3
0
        public void CreateCommand_should_return_expected_result_when_CommitQuorum_with_w_is_Set(
            [Values(1, 2, 3)] int w)
        {
            var requests     = new[] { new CreateIndexRequest(new BsonDocument("x", 1)) };
            var commitQuorum = CreateIndexCommitQuorum.Create(w);
            var subject      = new CreateIndexesUsingCommandOperation(_collectionNamespace, requests, _messageEncoderSettings)
            {
                CommitQuorum = commitQuorum
            };
            var session = OperationTestHelper.CreateSession();
            var connectionDescription = OperationTestHelper.CreateConnectionDescription(serverVersion: Feature.CreateIndexCommitQuorum.FirstSupportedVersion);

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

            var expectedResult = new BsonDocument
            {
                { "createIndexes", _collectionNamespace.CollectionName },
                { "indexes", new BsonArray {
                      requests[0].CreateIndexDocument()
                  } },
                { "commitQuorum", w }
            };

            result.Should().Be(expectedResult);
            result["commitQuorum"].BsonType.Should().Be(BsonType.Int32);
        }
Beispiel #4
0
        public void CreateCommand_should_throw_when_commitQuorum_is_specified_and_not_supported()
        {
            var requests     = new[] { new CreateIndexRequest(new BsonDocument("x", 1)) };
            var commitQuorum = CreateIndexCommitQuorum.Create(1);
            var subject      = new CreateIndexesUsingCommandOperation(_collectionNamespace, requests, _messageEncoderSettings)
            {
                CommitQuorum = commitQuorum
            };
            var session = OperationTestHelper.CreateSession();
            var connectionDescription = OperationTestHelper.CreateConnectionDescription(serverVersion: Feature.CreateIndexCommitQuorum.LastNotSupportedVersion);

            var exception = Record.Exception(() => subject.CreateCommand(session, connectionDescription));

            exception.Should().BeOfType <NotSupportedException>();
        }
        public void CreateCommand_should_return_expected_result_when_creating_one_index()
        {
            var requests       = new[] { new CreateIndexRequest(new BsonDocument("x", 1)) };
            var subject        = new CreateIndexesUsingCommandOperation(_collectionNamespace, requests, _messageEncoderSettings);
            var expectedResult = new BsonDocument
            {
                { "createIndexes", _collectionNamespace.CollectionName },
                { "indexes", new BsonArray {
                      requests[0].CreateIndexDocument()
                  } }
            };

            var result = subject.CreateCommand();

            result.Should().Be(expectedResult);
        }
Beispiel #6
0
        public void CreateCommand_should_return_expected_result_when_MaxTime_is_Set(long maxTimeTicks, int expectedMaxTimeMS)
        {
            var requests = new[] { new CreateIndexRequest(new BsonDocument("x", 1)) };
            var subject  = new CreateIndexesUsingCommandOperation(_collectionNamespace, requests, _messageEncoderSettings);

            subject.MaxTime = TimeSpan.FromTicks(maxTimeTicks);

            var result = subject.CreateCommand(null);

            var expectedResult = new BsonDocument
            {
                { "createIndexes", _collectionNamespace.CollectionName },
                { "indexes", new BsonArray {
                      requests[0].CreateIndexDocument(null)
                  } },
                { "maxTimeMS", expectedMaxTimeMS },
            };

            result.Should().Be(expectedResult);
            result["maxTimeMS"].BsonType.Should().Be(BsonType.Int32);
        }
        public void CreateCommand_should_return_expected_result_when_creating_two_indexes()
        {
            var requests = new[]
            {
                new CreateIndexRequest(new BsonDocument("x", 1)),
                new CreateIndexRequest(new BsonDocument("y", 1))
            };
            var subject = new CreateIndexesUsingCommandOperation(_collectionNamespace, requests, _messageEncoderSettings);
            var session = OperationTestHelper.CreateSession();
            var connectionDescription = OperationTestHelper.CreateConnectionDescription();

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

            var expectedResult = new BsonDocument
            {
                { "createIndexes", _collectionNamespace.CollectionName },
                { "indexes", new BsonArray {
                      requests[0].CreateIndexDocument(null), requests[1].CreateIndexDocument(null)
                  } }
            };

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