public void BucketSize_get_and_set_should_work(
            [Values(null, 1.0, 2.0)]
            double? value)
        {
            var subject = new CreateIndexRequest(new BsonDocument("x", 1));

            subject.BucketSize = value;
            var result = subject.BucketSize;

            result.Should().Be(value);
        }
        public void LanguageOverride_get_and_set_should_work(
            [Values(null, "en", "fr")]
            string value)
        {
            var subject = new CreateIndexRequest(new BsonDocument("x", 1));

            subject.LanguageOverride = value;
            var result = subject.LanguageOverride;

            result.Should().BeSameAs(value);
        }
        public void Background_get_and_set_should_work(
            [Values(null, false, true)]
            bool? value)
        {
            var subject = new CreateIndexRequest(new BsonDocument("x", 1));

            subject.Background = value;
            var result = subject.Background;

            result.Should().Be(value);
        }
        public void Bits_get_and_set_should_work(
            [Values(null, 1, 2)]
            int? value)
        {
            var subject = new CreateIndexRequest(new BsonDocument("x", 1));

            subject.Bits = value;
            var result = subject.Bits;

            result.Should().Be(value);
        }
        public void WildcardProjection_get_and_set_should_work(
            [Values(null, "{ x : 1 }", "{ x : 2 }")] string valueString)
        {
            var subject = new CreateIndexRequest(new BsonDocument("x", 1));
            var value   = valueString == null ? null : BsonDocument.Parse(valueString);

            subject.WildcardProjection = value;
            var result = subject.WildcardProjection;

            result.Should().BeSameAs(value);
        }
        public void Min_get_and_set_should_work(
            [Values(null, 1.0, 2.0)]
            double?value)
        {
            var subject = new CreateIndexRequest(new BsonDocument("x", 1));

            subject.Min = value;
            var result = subject.Min;

            result.Should().Be(value);
        }
        public void AdditionalOptions_get_and_set_should_work(
            [Values(false, true)]
            bool hasAdditionalOptions)
        {
            var subject = new CreateIndexRequest(new BsonDocument("x", 1));
            var value   = hasAdditionalOptions ? new BsonDocument("y", 2) : null;

            subject.AdditionalOptions = value;
            var result = subject.AdditionalOptions;

            result.Should().Be(value);
        }
        public void AdditionalOptions_get_and_set_should_work(
            [Values(false, true)]
            bool hasAdditionalOptions)
        {
            var subject = new CreateIndexRequest(new BsonDocument("x", 1));
            var value = hasAdditionalOptions ? new BsonDocument("y", 2) : null;

            subject.AdditionalOptions = value;
            var result = subject.AdditionalOptions;

            result.Should().Be(value);
        }
        public void AdditionalOptions_get_and_set_should_work(
            [Values(null, "{ x : 1 }", "{ x : 2 }")]
            string valueString)
        {
            var subject = new CreateIndexRequest(new BsonDocument("x", 1));
            var value = valueString == null ? null : BsonDocument.Parse(valueString);

            subject.AdditionalOptions = value;
            var result = subject.AdditionalOptions;

            result.Should().BeSameAs(value);
        }
        public void constructor_should_initialize_subject()
        {
            var keys = new BsonDocument("x", 1);

            var subject = new CreateIndexRequest(keys);

            subject.Keys.Should().BeSameAs(keys);
            subject.AdditionalOptions.Should().BeNull();
            subject.Background.Should().NotHaveValue();
            subject.Name.Should().BeNull();
            subject.Sparse.Should().NotHaveValue();
            subject.ExpireAfter.Should().NotHaveValue();
            subject.Unique.Should().NotHaveValue();
        }
        public void CreateIndexDocument_should_return_expected_result()
        {
            var keys = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);
            var expectedResult = new BsonDocument
            {
                { "key", keys },
                { "name", "x_1" }
            };

            var result = subject.CreateIndexDocument();

            result.Should().Be(expectedResult);
        }
        public void constructor_should_initialize_subject()
        {
            var keys = new BsonDocument("x", 1);

            var subject = new CreateIndexRequest(keys);

            subject.Keys.Should().BeSameAs(keys);
            subject.AdditionalOptions.Should().BeNull();
            subject.Background.Should().NotHaveValue();
            subject.Name.Should().BeNull();
            subject.Sparse.Should().NotHaveValue();
            subject.ExpireAfter.Should().NotHaveValue();
            subject.Unique.Should().NotHaveValue();
        }
        public void CreateCommand_should_return_expected_result_when_StorageEngine_has_value()
        {
            var keys    = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);

            subject.StorageEngine = new BsonDocument("awesome", true);
            var expectedResult = new BsonDocument
            {
                { "key", keys },
                { "name", "x_1" },
                { "storageEngine", new BsonDocument("awesome", true) }
            };

            var result = subject.CreateIndexDocument();

            result.Should().Be(expectedResult);
        }
        public void CreateIndexDocument_should_return_expected_result_when_languageOverride_has_value()
        {
            var keys    = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);

            subject.LanguageOverride = "en";
            var expectedResult = new BsonDocument
            {
                { "key", keys },
                { "name", "x_1" },
                { "language_override", "en" }
            };

            var result = subject.CreateIndexDocument();

            result.Should().Be(expectedResult);
        }
        public void CreateIndexDocument_should_return_expected_result_when_unique_has_value()
        {
            var keys    = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);

            subject.Unique = true;
            var expectedResult = new BsonDocument
            {
                { "key", keys },
                { "name", "x_1" },
                { "unique", true }
            };

            var result = subject.CreateIndexDocument();

            result.Should().Be(expectedResult);
        }
        public void CreateIndexDocument_should_return_expected_result_when_expireAfter_has_value()
        {
            var keys    = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);

            subject.ExpireAfter = TimeSpan.FromSeconds(3);
            var expectedResult = new BsonDocument
            {
                { "key", keys },
                { "name", "x_1" },
                { "expireAfterSeconds", 3 }
            };

            var result = subject.CreateIndexDocument();

            result.Should().Be(expectedResult);
        }
        public void CreateIndexDocument_should_return_expected_result_when_bucketSize_has_value()
        {
            var keys    = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);

            subject.BucketSize = 20;
            var expectedResult = new BsonDocument
            {
                { "key", keys },
                { "name", "x_1" },
                { "bucketSize", 20 }
            };

            var result = subject.CreateIndexDocument();

            result.Should().Be(expectedResult);
        }
        public void CreateIndexDocument_should_return_expected_result_when_partialFilterExpression_has_value()
        {
            var keys    = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);

            subject.PartialFilterExpression = new BsonDocument("x", new BsonDocument("$gt", 0));
            var expectedResult = new BsonDocument
            {
                { "key", keys },
                { "name", "x_1" },
                { "partialFilterExpression", subject.PartialFilterExpression }
            };

            var result = subject.CreateIndexDocument();

            result.Should().Be(expectedResult);
        }
        public void CreateIndexDocument_should_return_expected_result_when_background_has_value(
            [Values(false, true)]
            bool value)
        {
            var keys    = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);

            subject.Background = value;
            var expectedResult = new BsonDocument
            {
                { "key", keys },
                { "name", "x_1" },
                { "background", value }
            };

            var result = subject.CreateIndexDocument();

            result.Should().Be(expectedResult);
        }
        public void CreateOperation_should_return_expected_result()
        {
            var request = new CreateIndexRequest(new BsonDocument("x", 1));
            var requests = new[] { request };
            var writeConcern = new WriteConcern(1);
            var subject = new CreateIndexesUsingInsertOperation(_collectionNamespace, requests, _messageEncoderSettings);

            var result = subject.CreateOperation(null, request);

            result.BypassDocumentValidation.Should().NotHaveValue();
            result.CollectionNamespace.CollectionName.Should().Be("system.indexes");
            result.ContinueOnError.Should().BeFalse();
            result.DocumentSource.Batch.Should().NotBeNull();
            result.MaxBatchCount.Should().NotHaveValue();
            result.MaxDocumentSize.Should().NotHaveValue();
            result.MaxMessageSize.Should().NotHaveValue();
            result.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings);
            result.Serializer.Should().BeSameAs(BsonDocumentSerializer.Instance);
        }
        public void DefaultLanguage_get_and_set_should_work(
            [Values(null, "x", "y")]
            string value)
        {
            var subject = new CreateIndexRequest(new BsonDocument("x", 1));

            subject.DefaultLanguage = value;
            var result = subject.DefaultLanguage;

            result.Should().BeSameAs(value);
        }
        public void CreateIndexDocument_should_return_expected_result_when_weights_has_value()
        {
            var keys = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);
            subject.Weights = new BsonDocument("a", 1);
            var expectedResult = new BsonDocument
            {
                { "key", keys },
                { "name", "x_1" },
                { "weights", new BsonDocument("a", 1) }
            };

            var result = subject.CreateIndexDocument();

            result.Should().Be(expectedResult);
        }
        public void CreateIndexDocument_should_return_expected_result_when_name_is_in_additionalOptions()
        {
            var keys = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);
            subject.AdditionalOptions = new BsonDocument("name", "a");
            var expectedResult = new BsonDocument
            {
                { "key", keys },
                { "name", "a" }
            };

            var result = subject.CreateIndexDocument();

            result.Should().Be(expectedResult);
        }
        public void Collation_get_and_set_should_work(
            [Values(null, "en_US", "fr_CA")]
            string locale)
        {
            var subject = new CreateIndexRequest(new BsonDocument("x", 1));
            var value = locale == null ? null : new Collation(locale);

            subject.Collation = value;
            var result = subject.Collation;

            result.Should().BeSameAs(value);
        }
        public void CreateIndexDocument_should_return_expected_result_when_version_has_value()
        {
            var keys = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);
            subject.Version = 11;
            var expectedResult = new BsonDocument
            {
                { "key", keys },
                { "name", "x_1" },
                { "v", 11 }
            };

            var result = subject.CreateIndexDocument();

            result.Should().Be(expectedResult);
        }
        public void PartialFilterExpression_get_and_set_should_work()
        {
            var subject = new CreateIndexRequest(new BsonDocument("x", 1));
            var value = new BsonDocument("x", new BsonDocument("$gt", 0));

            subject.PartialFilterExpression = value;
            var result = subject.PartialFilterExpression;

            result.Should().Be(value);
        }
        public void CreateIndexDocument_should_throw_when_Collation__is_set_and_is_not_supported()
        {
            var keys = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys)
            {
                Collation = new Collation("en_US")
            };

            var exception = Record.Exception(() => subject.CreateIndexDocument(Feature.Collation.LastNotSupportedVersion));

            exception.Should().BeOfType<NotSupportedException>();
        }
        public void CreateIndexDocument_should_return_expected_result_when_languageOverride_has_value()
        {
            var keys = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);
            subject.LanguageOverride = "en";
            var expectedResult = new BsonDocument
            {
                { "key", keys },
                { "name", "x_1" },
                { "language_override", "en" }
            };

            var result = subject.CreateIndexDocument();

            result.Should().Be(expectedResult);
        }
        public void CreateIndexDocument_should_return_expected_result_when_partialFilterExpression_has_value()
        {
            var keys = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);
            subject.PartialFilterExpression = new BsonDocument("x", new BsonDocument("$gt", 0));
            var expectedResult = new BsonDocument
            {
                { "key", keys },
                { "name", "x_1" },
                { "partialFilterExpression", subject.PartialFilterExpression }
            };

            var result = subject.CreateIndexDocument();

            result.Should().Be(expectedResult);
        }
        public void CreateIndexDocument_should_return_expected_result_when_bucketSize_has_value()
        {
            var keys = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);
            subject.BucketSize = 20;
            var expectedResult = new BsonDocument
            {
                { "key", keys },
                { "name", "x_1" },
                { "bucketSize", 20 }
            };

            var result = subject.CreateIndexDocument();

            result.Should().Be(expectedResult);
        }
        public void CreateIndexDocument_should_return_expected_result_when_expireAfter_has_value()
        {
            var keys = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);
            subject.ExpireAfter = TimeSpan.FromSeconds(3);
            var expectedResult = new BsonDocument
            {
                { "key", keys },
                { "name", "x_1" },
                { "expireAfterSeconds", 3 }
            };

            var result = subject.CreateIndexDocument();

            result.Should().Be(expectedResult);
        }
        public void CreateIndexDocument_should_return_expected_result_when_background_has_value(
            [Values(false, true)]
            bool value)
        {
            var keys = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);
            subject.Background = value;
            var expectedResult = new BsonDocument
            {
                { "key", keys },
                { "name", "x_1" },
                { "background", value }
            };

            var result = subject.CreateIndexDocument();

            result.Should().Be(expectedResult);
        }
        public void LanguageOverride_get_and_set_should_work(
            [Values(null, "en", "fr")]
            string value)
        {
            var subject = new CreateIndexRequest(new BsonDocument("x", 1));

            subject.LanguageOverride = value;
            var result = subject.LanguageOverride;

            result.Should().BeSameAs(value);
        }
        public void PartialFilterExpression_get_and_set_should_work(
            [Values(null, "{ x : 1 }", "{ x : 2 }")]
            string valueString)
        {
            var subject = new CreateIndexRequest(new BsonDocument("x", 1));
            var value = valueString == null ? null : BsonDocument.Parse(valueString);

            subject.PartialFilterExpression = value;
            var result = subject.PartialFilterExpression;

            result.Should().BeSameAs(value);
        }
        public void Name_get_and_set_should_work(
            [Values(null, "name")]
            string value)
        {
            var subject = new CreateIndexRequest(new BsonDocument("x", 1));

            subject.Name = value;
            var result = subject.Name;

            result.Should().Be(value);
        }
        public void ExpireAfter_get_and_set_should_work(
            [Values(null, 1L, 2L)]
            long? milliseconds)
        {
            var subject = new CreateIndexRequest(new BsonDocument("x", 1));
            var value = milliseconds == null ? (TimeSpan?)null : TimeSpan.FromMilliseconds(milliseconds.Value);

            subject.ExpireAfter = value;
            var result = subject.ExpireAfter;

            result.Should().Be(value);
        }
        public void Keys_get_should_return_expected_result()
        {
            var keys = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);

            var result = subject.Keys;

            result.Should().Be(keys);
        }
        public void CreateCommand_should_return_expected_result_when_StorageEngine_has_value()
        {
            var keys = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);
            subject.StorageEngine = new BsonDocument("awesome", true);
            var expectedResult = new BsonDocument
            {
                { "key", keys },
                { "name", "x_1" },
                { "storageEngine", new BsonDocument("awesome", true) }
            };

            var result = subject.CreateIndexDocument();

            result.Should().Be(expectedResult);
        }
        public void TimeToLive_get_and_set_should_work(
            [Values(null, 1)]
            int? seconds)
        {
            var subject = new CreateIndexRequest(new BsonDocument("x", 1));
            var value = seconds.HasValue ? (TimeSpan?)TimeSpan.FromSeconds(seconds.Value) : null;

            subject.ExpireAfter = value;
            var result = subject.ExpireAfter;

            result.Should().Be(value);
        }
        public void CreateIndexDocument_should_return_expected_result_when_unique_has_value()
        {
            var keys = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);
            subject.Unique = true;
            var expectedResult = new BsonDocument
            {
                { "key", keys },
                { "name", "x_1" },
                { "unique", true }
            };

            var result = subject.CreateIndexDocument();

            result.Should().Be(expectedResult);
        }
        public void CreateIndexDocument_should_return_expected_result_when_additionalOptions_has_value()
        {
            var keys = new BsonDocument("x", 1);
            var subject = new CreateIndexRequest(keys);
            subject.Sparse = true;
            subject.AdditionalOptions = new BsonDocument
            {
                { "sparse", false }, // should not overwrite existing element
                { "x", 123 }
            };
            var expectedResult = new BsonDocument
            {
                { "key", keys },
                { "name", "x_1" },
                { "sparse", true },
                { "x", 123 }
            };

            var result = subject.CreateIndexDocument();

            result.Should().Be(expectedResult);
        }
        public void constructor_should_initialize_subject()
        {
            var keys = new BsonDocument("x", 1);

            var subject = new CreateIndexRequest(keys);

            subject.Keys.Should().BeSameAs(keys);

            subject.AdditionalOptions.Should().BeNull();
            subject.Background.Should().NotHaveValue();
            subject.Bits.Should().NotHaveValue();
            subject.BucketSize.Should().NotHaveValue();
            subject.Collation.Should().BeNull();
            subject.DefaultLanguage.Should().BeNull();
            subject.ExpireAfter.Should().NotHaveValue();
            subject.LanguageOverride.Should().BeNull();
            subject.Max.Should().NotHaveValue();
            subject.Min.Should().NotHaveValue();
            subject.Name.Should().BeNull();
            subject.PartialFilterExpression.Should().BeNull();
            subject.Sparse.Should().NotHaveValue();
            subject.SphereIndexVersion.Should().NotHaveValue();
            subject.TextIndexVersion.Should().NotHaveValue();
            subject.Unique.Should().NotHaveValue();
            subject.Version.Should().NotHaveValue();
            subject.Weights.Should().BeNull();
        }