Beispiel #1
0
        public async Task NoIndexAsync()
        {
            var connection  = TestConfiguration.GetConnection();
            var indexWriter = new EntityIndexWriter <NoIndexModel>(connection);

            await AssertExtensions.DoesNotThrowAsync <Exception>(async() => await indexWriter.ApplyIndexingAsync().ConfigureAwait(false)).ConfigureAwait(false);
        }
Beispiel #2
0
        public void FailureFromMultipleTextIndexes()
        {
            var connection  = TestConfiguration.GetConnection();
            var indexWriter = new EntityIndexWriter <MultipleTextIndexModel>(connection);

            indexWriter.ApplyIndexing();
        }
        public virtual async Task SaveChangesAsync(CancellationToken cancellationToken = default)
        {
            await EntityIndexWriter.ApplyIndexingAsync(cancellationToken).ConfigureAwait(false);

            cancellationToken.ThrowIfCancellationRequested();
            await EntityWriterPipeline.WriteAsync(cancellationToken).ConfigureAwait(false);
        }
Beispiel #4
0
        public void NoIndexSync()
        {
            var connection  = TestConfiguration.GetConnection();
            var indexWriter = new EntityIndexWriter <NoIndexModel>(connection);

            AssertExtensions.DoesNotThrow <Exception>(() => indexWriter.ApplyIndexing());
        }
Beispiel #5
0
 private async ValueTask TryConfigureIndexes()
 {
     if (!HasSetIndexes)
     {
         HasSetIndexes = true;
         await EntityIndexWriter.ApplyIndexingAsync <DbCachedEntry>(Connection);
     }
 }
        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());
        }
 /// <summary>
 /// Writes all of the items in the changeset to the database.
 /// </summary>
 /// <returns></returns>
 public virtual void SaveChanges()
 {
     EntityIndexWriter.ApplyIndexing();
     EntityRelationshipWriter.CommitEntityRelationships(ChangeTracker);
     ChangeTracker.DetectChanges();
     CheckEntityValidation();
     EntityWriter.Write(ChangeTracker);
     ChangeTracker.CommitChanges();
 }
        public void SetConnection(IMongoDbConnection connection)
        {
            EntityWriterPipeline    = new EntityWriterPipeline <EntityBucket <TGroup, TSubEntity> >(connection);
            EntityReader            = new EntityReader <EntityBucket <TGroup, TSubEntity> >(connection);
            EntityIndexWriter       = new EntityIndexWriter <EntityBucket <TGroup, TSubEntity> >(connection);
            BucketStagingCollection = new EntityBucketStagingCollection <TGroup, TSubEntity>(EntityReader, BucketSize);
            ChangeTracker           = new EntityCollection <EntityBucket <TGroup, TSubEntity> >();

            EntityWriterPipeline.AddCollection(ChangeTracker);
            EntityWriterPipeline.AddCollection(BucketStagingCollection);
        }
Beispiel #10
0
        /// <summary>
        /// Initialise a new entity reader and writer to the specified database.
        /// </summary>
        /// <param name="connection"></param>
        public void SetConnection(IMongoDbConnection connection)
        {
            Connection               = connection;
            EntityWriterPipeline     = new EntityWriterPipeline <TEntity>(connection);
            EntityReader             = new EntityReader <TEntity>(connection);
            EntityIndexWriter        = new EntityIndexWriter <TEntity>(connection);
            EntityRelationshipWriter = new EntityRelationshipWriter <TEntity>(connection);
            ChangeTracker            = new EntityCollection <TEntity>();

            EntityWriterPipeline.AddCollection(ChangeTracker);
        }
        protected static void ResetMongoDb()
        {
            MongoDbDriverHelper.ResetDriver();
            EntityMapping.RemoveAllDefinitions();

            EntityMapping.RemoveAllMappingProcessors();
            EntityMapping.AddMappingProcessors(DefaultProcessors.CreateProcessors());

            TypeDiscovery.ClearCache();
            EntityIndexWriter.ClearCache();
        }
Beispiel #12
0
        public void WriteIndexSync()
        {
            var connection = TestConfiguration.GetConnection();

            EntityIndexWriter.ApplyIndexing <IndexModel>(connection);

            var collection = connection.GetDatabase().GetCollection <IndexModel>("IndexModel");
            var dbIndexes  = collection.Indexes.List().ToList();

            Assert.AreEqual(5, dbIndexes.Count);
        }
Beispiel #13
0
        public async Task WriteIndexAsync()
        {
            var connection = TestConfiguration.GetConnection();


            await EntityIndexWriter.ApplyIndexingAsync <IndexModel>(connection);

            var collection = connection.GetDatabase().GetCollection <IndexModel>("IndexModel");
            var dbIndexes  = await collection.Indexes.List().ToListAsync().ConfigureAwait(false);

            Assert.AreEqual(5, 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);
        }
        public async Task IsCacheAvailable()
        {
            EntityIndexWriter.ClearCache();

            await AssertCacheAvailabilityAsync(new MongoDbCacheLayer(MongoDbHelper.GetConnection()), true);

            var connectionMock = new Mock <IMongoDbConnection>();

            connectionMock.Setup(c => c.GetDatabase()).Throws <Exception>();
            EntityIndexWriter.ClearCache();

            await AssertCacheAvailabilityAsync(new MongoDbCacheLayer(connectionMock.Object), 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);
        }
Beispiel #17
0
        /// <summary>
        /// Writes all of the items in the changeset to the database.
        /// </summary>
        /// <returns></returns>
        public virtual async Task SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            await EntityIndexWriter.ApplyIndexingAsync(cancellationToken).ConfigureAwait(false);

            cancellationToken.ThrowIfCancellationRequested();
            await EntityRelationshipWriter.CommitEntityRelationshipsAsync(ChangeTracker, cancellationToken).ConfigureAwait(false);

            cancellationToken.ThrowIfCancellationRequested();
            ChangeTracker.DetectChanges();
            CheckEntityValidation();
            cancellationToken.ThrowIfCancellationRequested();
            await EntityWriter.WriteAsync(ChangeTracker, cancellationToken).ConfigureAwait(false);

            ChangeTracker.CommitChanges();
        }
Beispiel #18
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);
        }
 private static void InternalSaveChanges <TEntity>(IMongoDbConnection connection, IEnumerable <IWriteCommand> commands, WriteModelOptions options) where TEntity : class
 {
     EntityIndexWriter.ApplyIndexing <TEntity>(connection);
     EntityCommandWriter.Write <TEntity>(connection, commands, options);
 }
        private static async Task InternalSaveChangesAsync <TEntity>(IMongoDbConnection connection, IEnumerable <IWriteCommand> commands, WriteModelOptions options, CancellationToken cancellationToken) where TEntity : class
        {
            await EntityIndexWriter.ApplyIndexingAsync <TEntity>(connection);

            await EntityCommandWriter.WriteAsync <TEntity>(connection, commands, options, cancellationToken);
        }
 public virtual void SaveChanges()
 {
     EntityIndexWriter.ApplyIndexing();
     EntityWriterPipeline.Write();
 }
Beispiel #22
0
 /// <summary>
 /// Writes all of the items in the changeset to the database.
 /// </summary>
 /// <returns></returns>
 public virtual void SaveChanges()
 {
     EntityIndexWriter.ApplyIndexing();
     EntityRelationshipWriter.CommitEntityRelationships(ChangeTracker);
     EntityWriterPipeline.Write();
 }
 public void SetConnection(IMongoDbConnection connection)
 {
     EntityWriterPipeline = new EntityWriterPipeline <EntityBucket <TGroup, TSubEntity> >(connection);
     EntityReader         = new EntityReader <EntityBucket <TGroup, TSubEntity> >(connection);
     EntityIndexWriter    = new EntityIndexWriter <EntityBucket <TGroup, TSubEntity> >(connection);
 }
 public virtual void SaveChanges()
 {
     EntityIndexWriter.ApplyIndexing();
     EntityWriterPipeline.Write();
     BucketStagingCollection.Clear();
 }