public async Task NoIndexAsync()
        {
            var database    = TestConfiguration.GetDatabase();
            var collection  = database.GetCollection <NoIndexModel>("EntityIndexWriterTests.NoIndexModelAsync");
            var indexMapper = new EntityIndexMapper <NoIndexModel>();
            var indexWriter = new EntityIndexWriter <NoIndexModel>(collection, indexMapper);

            await AssertExtensions.DoesNotThrowAsync <Exception>(async() => await indexWriter.ApplyIndexingAsync().ConfigureAwait(false)).ConfigureAwait(false);
        }
        public void NoIndexSync()
        {
            var database    = TestConfiguration.GetDatabase();
            var collection  = database.GetCollection <NoIndexModel>("EntityIndexWriterTests.NoIndexModelSync");
            var indexMapper = new EntityIndexMapper <NoIndexModel>();
            var indexWriter = new EntityIndexWriter <NoIndexModel>(collection, indexMapper);

            AssertExtensions.DoesNotThrow <Exception>(() => indexWriter.ApplyIndexing());
        }
Esempio n. 3
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"));
        }
Esempio n. 4
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));
        }
        public async Task WriteIndexAsync()
        {
            var database    = TestConfiguration.GetDatabase();
            var collection  = database.GetCollection <IndexModel>("EntityIndexWriterTests.IndexModelAsync");
            var indexMapper = new EntityIndexMapper <IndexModel>();
            var indexWriter = new EntityIndexWriter <IndexModel>(collection, indexMapper);

            await indexWriter.ApplyIndexingAsync().ConfigureAwait(false);

            var dbIndexes = await collection.Indexes.List().ToListAsync().ConfigureAwait(false);

            Assert.AreEqual(3, dbIndexes.Count);
        }
        public void WriteIndexSync()
        {
            var database    = TestConfiguration.GetDatabase();
            var collection  = database.GetCollection <IndexModel>("EntityIndexWriterTests.IndexModelSync");
            var indexMapper = new EntityIndexMapper <IndexModel>();
            var indexWriter = new EntityIndexWriter <IndexModel>(collection, indexMapper);

            indexWriter.ApplyIndexing();

            var dbIndexes = collection.Indexes.List().ToList();

            Assert.AreEqual(3, dbIndexes.Count);
        }
Esempio n. 7
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"]);
        }
Esempio n. 8
0
        /// <summary>
        /// Initialise a new entity reader and writer to the specified database.
        /// </summary>
        /// <param name="database"></param>
        public void SetDatabase(IMongoDatabase database)
        {
            Database = database;

            var entityMapper = new EntityMapper <TEntity>();

            EntityWriter = new DbEntityWriter <TEntity>(database, entityMapper);
            EntityReader = new DbEntityReader <TEntity>(database, entityMapper);

            //TODO: Look at this again in the future, this seems unnecessarily complex
            var indexMapper = new EntityIndexMapper <TEntity>(entityMapper);
            var collection  = database.GetCollection <TEntity>(entityMapper.GetCollectionName());

            EntityIndexWriter = new EntityIndexWriter <TEntity>(collection, indexMapper);

            EntityRelationshipWriter = new EntityRelationshipWriter <TEntity>(database, entityMapper);
        }
Esempio n. 9
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);
        }
 public void EntityTypeMismatchFromEntityMapper()
 {
     var entityMapper = new EntityMapper <SomeEntity>();
     var indexMapper  = new EntityIndexMapper <AnotherEntity>(entityMapper);
 }