Beispiel #1
0
        public void AzureSqlDatabase_ReadModel_can_be_configured_using_a_migration()
        {
            var databaseSettings = Settings.Get <AzureSqlDatabaseSettings>();

            databaseSettings.DatabaseName = "ItsCqrsMigrationsTestReadModels";
            var connectionString = databaseSettings.BuildConnectionString();

            using (var context = new MigrationsTestReadModels(connectionString, typeof(OrderTallyEntityModelConfiguration)))
            {
                new ReadModelDatabaseInitializer <MigrationsTestReadModels>().InitializeDatabase(context);

                var migrator = new AzureSqlDbMigrator(
                    new AzureSqlDatabaseServiceObjective("Premium", "P1", 10 * 1024),
                    migrationVersion: new Version("0.0.42.1"));

                context.EnsureDatabaseIsUpToDate(migrator);
                var sku = context.GetAzureSqlDatabaseServiceObjective();

                sku.Edition.Should().Be("Premium");
                sku.ServiceObjective.Should().Be("P1");

                context.OpenConnection()
                .GetLatestAppliedMigrationVersions()
                .Should()
                .Contain(v => v.MigrationVersion.ToString() == "0.0.42.1");
            }
        }
Beispiel #2
0
        public void When_used_with_a_non_Azure_SQL_database_then_AzureSqlDbMigrator_is_applied_but_does_nothing()
        {
            // arrange
            Database.Delete(MigrationsTestReadModels.ConnectionString);

            using (var context = new MigrationsTestReadModels())
            {
                new CreateAndMigrate <MigrationsTestReadModels>().InitializeDatabase(context);

                var migrator = new AzureSqlDbMigrator(
                    new AzureSqlDatabaseServiceObjective("standard", "S0", 500),
                    migrationVersion: new Version("0.1.2.3"));

                // act
                context.EnsureDatabaseIsUpToDate(migrator);

                // assert
                var latestAppliedMigrationVersions = context.OpenConnection()
                                                     .GetLatestAppliedMigrationVersions();

                latestAppliedMigrationVersions
                .Should()
                .Contain(v => v.MigrationVersion.ToString() == "0.1.2.3");
            }
        }
        public void ReadModelDbContext_drops_the_database_and_recreates_it_when_the_prior_version_has_no_migrations()
        {
            // arrange
            Database.SetInitializer(new DropCreateDatabaseAlways <MigrationsTestReadModels>());

            using (var db = new MigrationsTestReadModels(
                       typeof(OrderTallyEntityModelConfiguration)))
            {
                db.Database.Initialize(true);

                db.Set <OrderTally>().Add(new OrderTally
                {
                    Count  = 1,
                    Status = Any.Word()
                });

                db.SaveChanges();

                db.Set <OrderTally>().Count().Should().Be(1);
            }

            Database.SetInitializer(new ReadModelDatabaseInitializer <MigrationsTestReadModels>(new Version("1.1")));

            using (var db = new MigrationsTestReadModels(
                       typeof(OrderTallyEntityModelConfiguration)))
            {
                // act
                db.Database.Initialize(true);

                // assert
                db.Set <OrderTally>().Count().Should().Be(0);
            }
        }
Beispiel #4
0
        public void AzureSqlDatabase_can_be_configured_during_creation()
        {
            var databaseSettings = Settings.Get <AzureSqlDatabaseSettings>();

            databaseSettings.DatabaseName = "ItsCqrsPremiumDatabase";
            var connectionString           = databaseSettings.BuildConnectionString();
            var sqlAzureDatabaseProperties = new AzureSqlDatabaseServiceObjective("Premium", "P1", 10 * 1024);

            using (var context = new MigrationsTestReadModels(connectionString, typeof(OrderTallyEntityModelConfiguration)))
                using (Disposable.Create(() =>
                {
                    // Drop the expensive database
                    context.Database.Connection.Close();
                    context.Database.Delete();
                }))
                {
                    new ReadModelDatabaseInitializer <MigrationsTestReadModels>()
                    .WithAzureSqlDatabaseServiceObjective(sqlAzureDatabaseProperties)
                    .InitializeDatabase(context);

                    var sku = context.GetAzureSqlDatabaseServiceObjective();

                    sku.Edition.Should().Be("Premium");
                    sku.ServiceObjective.Should().Be("P1");
                }
        }
        public void ReadModelDbContext_drops_the_database_and_recreates_it_when_the_schema_has_changed()
        {
            // arrange
            Database.SetInitializer(new ReadModelDatabaseInitializer <MigrationsTestReadModels>());

            using (var db = new MigrationsTestReadModels(
                       typeof(OrderTallyEntityModelConfiguration)))
            {
                db.Database.Initialize(true);

                db.Set <OrderTally>().Add(new OrderTally
                {
                    Count  = 1,
                    Status = Any.Word()
                });

                db.SaveChanges();

                db.Set <OrderTally>().Count().Should().Be(1);
            }

            using (var db = new MigrationsTestReadModels(
                       typeof(OrderTallyEntityModelConfiguration),
                       typeof(ProductInventoryEntityModelConfiguration)))
            {
                // act
                db.Database.Initialize(true);

                // assert
                db.Set <OrderTally>().Count().Should().Be(0);
                db.Set <ProductInventory>().Count().Should().Be(0);
            }
        }