Exemple #1
0
        public void FromBsonDocument_should_return_expected_result_when_normalization_element_is_present(
            [Values(false, true)]
            bool normalization)
        {
            var document = new BsonDocument
            {
                { "locale", "en_US" },
                { "normalization", normalization }
            };

            var result = Collation.FromBsonDocument(document);

            result.Alternate.Should().BeNull();
            result.Backwards.Should().NotHaveValue();
            result.CaseFirst.Should().BeNull();
            result.CaseLevel.Should().NotHaveValue();
            result.Locale.Should().Be("en_US");
            result.MaxVariable.Should().BeNull();
            result.Normalization.Should().Be(normalization);
            result.NumericOrdering.Should().NotHaveValue();
            result.Strength.Should().BeNull();
        }
Exemple #2
0
        public void FromBsonDocument_should_return_expected_result_when_maxVariable_element_is_present(
            [Values("punct", "space")]
            string maxVariableString)
        {
            var document = new BsonDocument
            {
                { "locale", "en_US" },
                { "maxVariable", maxVariableString }
            };

            var result = Collation.FromBsonDocument(document);

            result.Alternate.Should().BeNull();
            result.Backwards.Should().NotHaveValue();
            result.CaseFirst.Should().BeNull();
            result.CaseLevel.Should().NotHaveValue();
            result.Locale.Should().Be("en_US");
            result.MaxVariable.Should().Be(Collation.ToCollationMaxVariable(maxVariableString));
            result.Normalization.Should().NotHaveValue();
            result.NumericOrdering.Should().NotHaveValue();
            result.Strength.Should().BeNull();
        }
Exemple #3
0
        public void FromBsonDocument_should_return_expected_result_when_strength_element_is_present(
            [Values(1, 2, 3, 4, 5)]
            int strengthInteger)
        {
            var document = new BsonDocument
            {
                { "locale", "en_US" },
                { "strength", strengthInteger }
            };

            var result = Collation.FromBsonDocument(document);

            result.Alternate.Should().BeNull();
            result.Backwards.Should().NotHaveValue();
            result.CaseFirst.Should().BeNull();
            result.CaseLevel.Should().NotHaveValue();
            result.Locale.Should().Be("en_US");
            result.MaxVariable.Should().BeNull();
            result.Normalization.Should().NotHaveValue();
            result.NumericOrdering.Should().NotHaveValue();
            result.Strength.Should().Be(Collation.ToCollationStrength(strengthInteger));
        }
        private CommandResult CreateView(IClientSessionHandle session, string viewName, string viewOn, IEnumerable <BsonDocument> pipeline, IMongoCreateViewOptions options)
        {
            if (viewName == null)
            {
                throw new ArgumentNullException(nameof(viewName));
            }
            if (viewOn == null)
            {
                throw new ArgumentNullException(nameof(viewOn));
            }
            if (pipeline == null)
            {
                throw new ArgumentNullException(nameof(pipeline));
            }

            Collation collation = null;

            if (options != null)
            {
                var optionsDocument = options.ToBsonDocument();

                BsonValue value;
                if (optionsDocument.TryGetValue("collation", out value))
                {
                    collation = Collation.FromBsonDocument(value.AsBsonDocument);
                }
            }

            var operation = new CreateViewOperation(_namespace, viewName, viewOn, pipeline, GetMessageEncoderSettings())
            {
                Collation    = collation,
                WriteConcern = _settings.WriteConcern
            };

            var response = ExecuteWriteOperation(session, operation);

            return(new CommandResult(response));
        }
        private CommandResult CreateCollection(IClientSessionHandle session, string collectionName, IMongoCollectionOptions options)
        {
            if (collectionName == null)
            {
                throw new ArgumentNullException("collectionName");
            }

            var                      collectionNamespace    = new CollectionNamespace(_namespace, collectionName);
            var                      messageEncoderSettings = GetMessageEncoderSettings();
            bool?                    autoIndexId            = null;
            bool?                    capped              = null;
            Collation                collation           = null;
            BsonDocument             indexOptionDefaults = null;
            int?                     maxDocuments        = null;
            long?                    maxSize             = null;
            bool?                    noPadding           = null;
            BsonDocument             storageEngine       = null;
            bool?                    usePowerOf2Sizes    = null;
            DocumentValidationAction?validationAction    = null;
            DocumentValidationLevel? validationLevel     = null;
            BsonDocument             validator           = null;

            if (options != null)
            {
                var optionsDocument = options.ToBsonDocument();

                BsonValue value;
                if (optionsDocument.TryGetValue("autoIndexId", out value))
                {
                    autoIndexId = value.ToBoolean();
                }
                if (optionsDocument.TryGetValue("capped", out value))
                {
                    capped = value.ToBoolean();
                }
                if (optionsDocument.TryGetValue("collation", out value))
                {
                    collation = Collation.FromBsonDocument(value.AsBsonDocument);
                }
                if (optionsDocument.TryGetValue("indexOptionDefaults", out value))
                {
                    indexOptionDefaults = value.AsBsonDocument;
                }
                if (optionsDocument.TryGetValue("max", out value))
                {
                    maxDocuments = value.ToInt32();
                }
                if (optionsDocument.TryGetValue("flags", out value))
                {
                    noPadding = ((CollectionUserFlags)value.ToInt32() & CollectionUserFlags.NoPadding) != 0;
                }
                if (optionsDocument.TryGetValue("size", out value))
                {
                    maxSize = value.ToInt64();
                }
                if (optionsDocument.TryGetValue("storageEngine", out value))
                {
                    storageEngine = value.AsBsonDocument;
                }
                if (optionsDocument.TryGetValue("flags", out value))
                {
                    usePowerOf2Sizes = ((CollectionUserFlags)value.ToInt32() & CollectionUserFlags.UsePowerOf2Sizes) != 0;
                }
                if (optionsDocument.TryGetValue("validationAction", out value))
                {
                    validationAction = (DocumentValidationAction)Enum.Parse(typeof(DocumentValidationAction), value.AsString, ignoreCase: true);
                }
                if (optionsDocument.TryGetValue("validationLevel", out value))
                {
                    validationLevel = (DocumentValidationLevel)Enum.Parse(typeof(DocumentValidationLevel), value.AsString, ignoreCase: true);
                }
                if (optionsDocument.TryGetValue("validator", out value))
                {
                    validator = value.AsBsonDocument;
                }
            }

            var operation = new CreateCollectionOperation(collectionNamespace, messageEncoderSettings)
            {
                AutoIndexId         = autoIndexId,
                Capped              = capped,
                Collation           = collation,
                IndexOptionDefaults = indexOptionDefaults,
                MaxDocuments        = maxDocuments,
                MaxSize             = maxSize,
                NoPadding           = noPadding,
                StorageEngine       = storageEngine,
                UsePowerOf2Sizes    = usePowerOf2Sizes,
                ValidationAction    = validationAction,
                ValidationLevel     = validationLevel,
                Validator           = validator,
                WriteConcern        = _settings.WriteConcern
            };

            var response = ExecuteWriteOperation(session, operation);

            return(new CommandResult(response));
        }
 // constructors
 internal BulkWriteRequestBuilder(Action <WriteRequest> addRequest, IMongoQuery query, Collation collation)
 {
     _addRequest = addRequest;
     _query      = query;
     _collation  = collation;
 }
 // constructors
 internal BulkUpdateRequestBuilder(Action <WriteRequest> addRequest, IMongoQuery query, Collation collation, bool upsert)
 {
     _addRequest = addRequest;
     _query      = query;
     _collation  = collation;
     _upsert     = upsert;
 }
Exemple #8
0
        public void ToString_with_maxVariable_should_return_expected_result(CollationMaxVariable maxVariable, string expectedResult)
        {
            var result = Collation.ToString(maxVariable);

            result.Should().Be(expectedResult);
        }
Exemple #9
0
        public void ToString_with_caseFirst_should_return_expected_result(CollationCaseFirst caseFirst, string expectedResult)
        {
            var result = Collation.ToString(caseFirst);

            result.Should().Be(expectedResult);
        }
Exemple #10
0
        public void ToString_with_alternate_should_return_expected_result(CollationAlternate alternate, string expectedResult)
        {
            var result = Collation.ToString(alternate);

            result.Should().Be(expectedResult);
        }
Exemple #11
0
        public void ToInt32_with_maxVariable_should_return_expected_result(CollationStrength strength, int expectedResult)
        {
            var result = Collation.ToInt32(strength);

            result.Should().Be(expectedResult);
        }
Exemple #12
0
        public void ToCollationStrength_should_return_expected_result(int value, CollationStrength expectedResult)
        {
            var result = Collation.ToCollationStrength(value);

            result.Should().Be(expectedResult);
        }
Exemple #13
0
        public void ToCollationMaxVariable_should_return_expected_result(string value, CollationMaxVariable expectedResult)
        {
            var result = Collation.ToCollationMaxVariable(value);

            result.Should().Be(expectedResult);
        }
Exemple #14
0
        public void ToCollationCaseFirst_should_return_expected_result(string value, CollationCaseFirst expectedResult)
        {
            var result = Collation.ToCollationCaseFirst(value);

            result.Should().Be(expectedResult);
        }
Exemple #15
0
        public void ToCollationAlternate_should_return_expected_result(string value, CollationAlternate expectedResult)
        {
            var result = Collation.ToCollationAlternate(value);

            result.Should().Be(expectedResult);
        }
 /// <summary>
 /// Sets the collation.
 /// </summary>
 /// <param name="collation">The collation.</param>
 /// <returns>The cursor (so you can chain method calls to it).</returns>
 public virtual MongoCursor SetCollation(Collation collation)
 {
     if (_isFrozen) { ThrowFrozen(); }
     _collation = collation;
     return this;
 }