Example #1
0
        public void IndexNaming()
        {
            var processor         = new BasicIndexProcessor();
            var entityIndexMapper = new EntityIndexMapper <IndexNamingModel>();
            var indexMapping      = entityIndexMapper.GetIndexMapping();

            var indexModel = processor.BuildIndexModel <IndexNamingModel>(indexMapping);

            Assert.AreEqual(2, indexModel.Count());
            Assert.IsTrue(indexModel.Any(m => m.Options.Name == null));
            Assert.IsTrue(indexModel.Any(m => m.Options.Name == "MyCustomIndexName"));
        }
Example #2
0
        public void AppliesUniqueConstraint()
        {
            var processor         = new BasicIndexProcessor();
            var entityIndexMapper = new EntityIndexMapper <UniqueConstraintModel>();
            var indexMapping      = entityIndexMapper.GetIndexMapping();

            var indexModel = processor.BuildIndexModel <UniqueConstraintModel>(indexMapping);

            Assert.AreEqual(2, indexModel.Count());
            Assert.IsTrue(indexModel.Any(m => m.Options.Name == "UniqueIndex" && m.Options.Unique == true));
            Assert.IsTrue(indexModel.Any(m => m.Options.Name == "NonUniqueIndex" && m.Options.Unique == false));
        }
Example #3
0
        public void AppliesIndexSortOrder()
        {
            var processor         = new BasicIndexProcessor();
            var entityIndexMapper = new EntityIndexMapper <IndexSortOrderModel>();
            var indexMapping      = entityIndexMapper.GetIndexMapping();

            var indexModel = processor.BuildIndexModel <IndexSortOrderModel>(indexMapping);

            Assert.AreEqual(2, indexModel.Count());

            var indexBsonDocument = indexModel.Select(m => m.Keys.Render(null, null)).ToArray();

            Assert.AreEqual(1, indexBsonDocument[0]["AscendingIndex"]);
            Assert.AreEqual(-1, indexBsonDocument[1]["DescendingIndex"]);
        }
Example #4
0
        public void NestedCompoundIndex()
        {
            var processor         = new BasicIndexProcessor();
            var entityIndexMapper = new EntityIndexMapper <NestedIndexBaseModel>();
            var indexMapping      = entityIndexMapper.GetIndexMapping();

            var indexModel = processor.BuildIndexModel <NestedIndexBaseModel>(indexMapping);

            Assert.AreEqual(1, indexModel.Count());

            var compoundIndex = indexModel.FirstOrDefault();

            Assert.AreEqual("MyCompoundIndex", compoundIndex.Options.Name);

            var indexBsonDocument = compoundIndex.Keys.Render(null, null);

            Assert.AreEqual("ChildModel.FirstPriority", indexBsonDocument.ElementAt(0).Name);
            Assert.AreEqual("SecondPriority", indexBsonDocument.ElementAt(1).Name);
        }