Exemplo n.º 1
0
        public void Migrate_DropNoBackup_Success()
        {
            using (var dbContext = new HangfireDbContext(ConnectionUtils.GetConnectionString(), "Hangfire-Mongo-Migration-Tests"))
            {
                // ARRANGE
                dbContext.Client.DropDatabase(dbContext.Database.DatabaseNamespace.DatabaseName);
                SeedCollectionFromZipArchive(dbContext, Path.Combine("Migration", "Hangfire-Mongo-Schema-006.zip"));

                var storageOptions = new MongoStorageOptions
                {
                    MigrationOptions = new MongoMigrationOptions
                    {
                        Strategy       = MongoMigrationStrategy.Drop,
                        BackupStrategy = MongoBackupStrategy.None
                    }
                };

                var migrationManager = new MongoMigrationManager(storageOptions, dbContext);

                // ACT
                migrationManager.Migrate();

                // ASSERT
                AssertDataIntegrity(dbContext, assertCollectionHasItems: false);
            }
        }
Exemplo n.º 2
0
        private void FullMigration(string seedFile)
        {
            using (var connection = new HangfireDbContext(ConnectionUtils.GetConnectionString(), "Hangfire-Mongo-Migration-Tests"))
            {
                // ARRANGE
                connection.Client.DropDatabase(connection.Database.DatabaseNamespace.DatabaseName);
                if (seedFile != null)
                {
                    SeedCollectionFromZipArchive(connection, Path.Combine("Migration", seedFile));
                }

                var storageOptions = new MongoStorageOptions
                {
                    MigrationOptions = new MongoMigrationOptions
                    {
                        Strategy       = MongoMigrationStrategy.Migrate,
                        BackupStrategy = MongoBackupStrategy.None
                    }
                };

                var migrationManager = new MongoMigrationManager(storageOptions);

                // ACT
                migrationManager.Migrate(connection);

                // ASSERT
            }
        }
Exemplo n.º 3
0
        public void Migrate_Full_Success(string seedFile, bool assertCollectionHasItems)
        {
            using (var dbContext = new HangfireDbContext(ConnectionUtils.GetConnectionString(), "Hangfire-Mongo-Migration-Tests"))
            {
                // ARRANGE
                dbContext.Client.DropDatabase(dbContext.Database.DatabaseNamespace.DatabaseName);
                if (seedFile != null)
                {
                    SeedCollectionFromZipArchive(dbContext, Path.Combine("Migration", seedFile));
                }

                var storageOptions = new MongoStorageOptions
                {
                    MigrationOptions = new MongoMigrationOptions
                    {
                        Strategy       = MongoMigrationStrategy.Migrate,
                        BackupStrategy = MongoBackupStrategy.None
                    }
                };

                var migrationManager = new MongoMigrationManager(storageOptions, dbContext);

                // ACT
                migrationManager.Migrate();

                // ASSERT
                AssertDataIntegrity(dbContext, assertCollectionHasItems);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Constructs Job Storage by Mongo client settings, name and options
        /// </summary>
        /// <param name="mongoClientSettings">Client settings for MongoDB</param>
        /// <param name="databaseName">Database name</param>
        /// <param name="storageOptions">Storage options</param>
        public MongoStorage(MongoClientSettings mongoClientSettings, string databaseName, MongoStorageOptions storageOptions)
        {
            if (mongoClientSettings == null)
            {
                throw new ArgumentNullException(nameof(mongoClientSettings));
            }
            if (string.IsNullOrWhiteSpace(databaseName))
            {
                throw new ArgumentNullException(nameof(databaseName));
            }
            if (storageOptions == null)
            {
                throw new ArgumentNullException(nameof(storageOptions));
            }

            _mongoClientSettings = mongoClientSettings;
            _databaseName        = databaseName;
            _storageOptions      = storageOptions;

            _dbContext = new HangfireDbContext(mongoClientSettings, databaseName, _storageOptions.Prefix);

            using (var migrationManager = new MongoMigrationManager(storageOptions, _dbContext))
            {
                migrationManager.Migrate();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Constructs Job Storage by database connection string, name and options
        /// </summary>
        /// <param name="connectionString">MongoDB connection string</param>
        /// <param name="databaseName">Database name</param>
        /// <param name="storageOptions">Storage options</param>
        public MongoStorage(string connectionString, string databaseName, MongoStorageOptions storageOptions)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentNullException(nameof(connectionString));
            }
            if (string.IsNullOrWhiteSpace(databaseName))
            {
                throw new ArgumentNullException(nameof(databaseName));
            }

            _connectionString = connectionString;
            _databaseName     = databaseName;
            _storageOptions   = storageOptions ?? throw new ArgumentNullException(nameof(storageOptions));

            Connection = new HangfireDbContext(connectionString, databaseName, storageOptions.Prefix);

            var migrationManager = new MongoMigrationManager(storageOptions);

            migrationManager.Migrate(Connection);

            var defaultQueueProvider = new MongoJobQueueProvider(_storageOptions);

            QueueProviders = new PersistentJobQueueProviderCollection(defaultQueueProvider);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Constructs Job Storage by Mongo client settings, name and options
        /// </summary>
        /// <param name="mongoClientSettings">Client settings for MongoDB</param>
        /// <param name="databaseName">Database name</param>
        /// <param name="storageOptions">Storage options</param>
        public MongoStorage(MongoClientSettings mongoClientSettings, string databaseName, MongoStorageOptions storageOptions)
        {
            _mongoClientSettings = mongoClientSettings ?? throw new ArgumentNullException(nameof(mongoClientSettings));
            _databaseName        = databaseName ?? throw new ArgumentNullException(nameof(databaseName));
            _storageOptions      = storageOptions ?? throw new ArgumentNullException(nameof(storageOptions));

            if (string.IsNullOrWhiteSpace(databaseName))
            {
                throw new ArgumentException("Please state a connection name", nameof(databaseName));
            }

            Connection = new HangfireDbContext(mongoClientSettings, databaseName, _storageOptions.Prefix);

            var migrationManager = new MongoMigrationManager(storageOptions);

            migrationManager.Migrate(Connection);

            var defaultQueueProvider = new MongoJobQueueProvider(_storageOptions);

            QueueProviders = new PersistentJobQueueProviderCollection(defaultQueueProvider);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes intial collections schema for Hangfire
        /// </summary>
        public void Init(MongoStorageOptions storageOptions)
        {
            var migrationManager = new MongoMigrationManager(storageOptions);

            migrationManager.Migrate(this);
        }