Exemple #1
0
        public void IndexConfigTest()
        {
            var x = new IndexOptions();

            Console.WriteLine(x.ToString());

            x.Name = "name";
            Assert.That(x.Name, Is.EqualTo("name"));

            Assert.That(x.Type, Is.EqualTo(IndexOptions.DefaultType));
            x.Type = IndexType.Hashed;
            Assert.That(x.Type, Is.EqualTo(IndexType.Hashed));

            x = new IndexOptions(new [] { "aaa", "bbb" });
            Assert.That(x.Attributes.Count, Is.EqualTo(2));
            x.AddAttribute("ccc");
            Assert.That(x.Attributes.Count, Is.EqualTo(3));
            Assert.That(x.Attributes, Does.Contain("aaa"));
            Assert.That(x.Attributes, Does.Contain("bbb"));
            Assert.That(x.Attributes, Does.Contain("ccc"));

            Assert.That(x.BitmapIndexOptions, Is.Not.Null);
            var y = new BitmapIndexOptions();

            x.BitmapIndexOptions = y;
            Assert.That(x.BitmapIndexOptions, Is.SameAs(y));

            IndexOptions.ValidateAttribute(x, "flub");

            Assert.Throws <ArgumentNullException>(() => IndexOptions.ValidateAttribute(x, null));
            Assert.Throws <ArgumentException>(() => IndexOptions.ValidateAttribute(x, ""));
            Assert.Throws <ArgumentException>(() => IndexOptions.ValidateAttribute(x, "duh."));
        }
        private static IndexOptions BuildNormalizedConfig(string mapName, IndexType indexType, string indexName,
                                                          List <string> normalizedAttributeNames)
        {
            var newConfig = new IndexOptions {
                Type = indexType
            };

            var nameBuilder = indexName == null ? new StringBuilder(mapName + "_" + GetIndexTypeName(indexType)) : null;

            foreach (var normalizedAttributeName in normalizedAttributeNames)
            {
                newConfig.AddAttribute(normalizedAttributeName);
                nameBuilder?.Append('_').Append(normalizedAttributeName);
            }
            if (nameBuilder != null)
            {
                indexName = nameBuilder.ToString();
            }
            {
            }
            newConfig.Name = indexName;
            return(newConfig);
        }