InitializeDatabase() public static method

public static InitializeDatabase ( System.Reflection.AssemblyLoader assemblyLoader, string contextAssemblyPath, string contextName, string serverName, string databaseName ) : void
assemblyLoader System.Reflection.AssemblyLoader
contextAssemblyPath string
contextName string
serverName string
databaseName string
return void
示例#1
0
        public void CorrectlyMigratesUpward()
        {
            string serverName               = @"(localdb)\mssqllocaldb";
            string databaseName             = $"GalenTest_{Guid.NewGuid():N}";
            string deployedAssemblyPath     = TestUtils.BuildTestAssemblyPath(2);
            var    expectedMigrationHistory = new[]
            {
                "201404181533201_InitialCreate",
                "201404181719410_AddedAddresInfoToCustomer",
                "201404181726158_MoveAddressInformationIntoContactInfo",
                "201404181729406_AddedRowVersionToDomainObjectBase",
                "201404181740359_AddedMultiplePropertiesToCustomer",
            };

            var assemblyLoader = new AssemblyLoader();

            TestUtils.InitializeDatabase(assemblyLoader, deployedAssemblyPath, "Pinpoint.Test.Data.TestContext", serverName, databaseName);

            //Migration v2 to v3
            var config = new DbDeploymentManagerConfiguration()
            {
                TargetAssemblyPath = TestUtils.BuildTestAssemblyPath(3),
                Database           = new DatabaseEndpoint {
                    ServerName = serverName, DatabaseName = databaseName
                },
                MigrationConfig = new MigrationConfigurationInfo
                {
                    Type = "Pinpoint.Test.Data.Migrations.Configuration"
                }
            };

            try
            {
                var sut = new DbDeploymentManager(config, assemblyLoader, new SqlClientDbConnectionInfoBuilder());
                sut.Deploy();

                Assert.AreEqual(1,
                                TestUtils.GetDeploymentHistoryRowCount(serverName, databaseName, config.MigrationConfig.Type));

                var migrationHistory = TestUtils.GetMigrationHistory(serverName, databaseName, config.MigrationConfig.Type);

                Assert.IsNotNull(migrationHistory);
                Assert.AreEqual(expectedMigrationHistory.Length, migrationHistory.Count());
                Assert.IsTrue(expectedMigrationHistory.SequenceEqual(migrationHistory));
            }
            finally
            {
                //Be sure to clean up
                TestUtils.DropDatabase(config.Database.ServerName, config.Database.DatabaseName);
            }
        }
示例#2
0
        public void CorrectlyMigratesDownward()
        {
            string serverName               = @"(localdb)\mssqllocaldb";
            string databaseName             = $"GalenTest_{Guid.NewGuid():N}";
            string deployedAssemblyPath     = TestUtils.BuildTestAssemblyPath(3);
            var    expectedMigrationHistory = new[]
            {
                "201404181533201_InitialCreate",
                "201404181719410_AddedAddresInfoToCustomer",
            };

            var assemblyLoader = new AssemblyLoader();

            TestUtils.InitializeDatabase(assemblyLoader, deployedAssemblyPath, "Pinpoint.Test.Data.TestContext", serverName, databaseName);

            //Migration v3 to v1
            var config = new DbDeploymentManagerConfiguration()
            {
                TargetAssemblyPath           = TestUtils.BuildTestAssemblyPath(1),
                DeployedAssemblyOverridePath = deployedAssemblyPath,                    // we didn't initialize using the deployer, so this has to be specified
                Database = new DatabaseEndpoint {
                    ServerName = serverName, DatabaseName = databaseName
                },
                MigrationConfig = new MigrationConfigurationInfo
                {
                    Type = "Pinpoint.Test.Data.Migrations.Configuration"
                }
            };

            try
            {
                var sut = new DbDeploymentManager(config, assemblyLoader, new SqlClientDbConnectionInfoBuilder());
                sut.Deploy();

                Assert.AreEqual(1,
                                TestUtils.GetDeploymentHistoryRowCount(serverName, databaseName, config.MigrationConfig.Type));

                var migrationHistory = TestUtils.GetMigrationHistory(serverName, databaseName, config.MigrationConfig.Type);

                Assert.IsNotNull(migrationHistory);
                Assert.AreEqual(expectedMigrationHistory.Length, migrationHistory.Count());
                Assert.IsTrue(expectedMigrationHistory.SequenceEqual(migrationHistory));
            }
            finally
            {
                //Be sure to clean up
                TestUtils.DropDatabase(config.Database.ServerName, config.Database.DatabaseName);
            }
        }
示例#3
0
        public void CorrectlyMigratesDownwardPastInitialMigration()
        {
            string serverName           = @"(localdb)\mssqllocaldb";
            string databaseName         = $"GalenTest_{Guid.NewGuid():N}";
            string deployedAssemblyPath = TestUtils.BuildTestAssemblyPath(3);

            var assemblyLoader = new AssemblyLoader();

            TestUtils.InitializeDatabase(assemblyLoader, deployedAssemblyPath, "Pinpoint.Test.Data.TestContext", serverName, databaseName);
            TestUtils.InitializeDatabase(assemblyLoader, deployedAssemblyPath, "Pinpoint.Test.Data.AnotherTestContext", serverName, databaseName);

            //Migration v3 to v1
            var config = new DbDeploymentManagerConfiguration()
            {
                TargetAssemblyPath           = TestUtils.BuildTestAssemblyPath(1),
                DeployedAssemblyOverridePath = deployedAssemblyPath,                    // we didn't initialize using the deployer so this is required
                Database = new DatabaseEndpoint {
                    ServerName = serverName, DatabaseName = databaseName
                },
                MigrationConfig = new MigrationConfigurationInfo
                {
                    Type = "Pinpoint.Test.Data.AnotherTestContextMigrations.Configuration"
                }
            };

            try
            {
                var sut = new DbDeploymentManager(config, assemblyLoader, new SqlClientDbConnectionInfoBuilder());
                sut.Deploy();

                Assert.AreEqual(1,
                                TestUtils.GetDeploymentHistoryRowCount(serverName, databaseName, config.MigrationConfig.Type));

                //We expect all schema related to AnotherTestContext would be deleted
                var migrationHistory = TestUtils.GetMigrationHistory(serverName, databaseName, config.MigrationConfig.Type);

                Assert.IsNotNull(migrationHistory);
                Assert.AreEqual(0, migrationHistory.Count());
            }
            finally
            {
                //Be sure to clean up
                TestUtils.DropDatabase(config.Database.ServerName, config.Database.DatabaseName);
            }
        }
示例#4
0
        public void NoOpInitializationWhenInitializingToCurrentDeployedVersion()
        {
            const string serverName   = @"(localdb)\mssqllocaldb";
            var          databaseName = $"GalenTest_{Guid.NewGuid():N}";

            string currentAssemblyPath = TestUtils.BuildTestAssemblyPath(3);

            var assemblyLoader = new AssemblyLoader();

            TestUtils.InitializeDatabase(assemblyLoader, currentAssemblyPath, "Pinpoint.Test.Data.TestContext", serverName, databaseName);

            var initializeConfig = new DbDeploymentManagerConfiguration
            {
                Mode = DeploymentMode.InitializeOnly,
                TargetAssemblyPath = currentAssemblyPath,      // use the current version as the target
                Database           = new DatabaseEndpoint {
                    ServerName = serverName, DatabaseName = databaseName
                },
                InitializationConfig = new InitializerConfigurationInfo
                {
                    Type = "Pinpoint.Test.Data.Initializers.TestContextCreateDatabaseIfNotExists"
                }
            };

            var expectedMigrationHistory = new[]
            {
                "201404181533201_InitialCreate",
                "201404181719410_AddedAddresInfoToCustomer",
                "201404181726158_MoveAddressInformationIntoContactInfo",
                "201404181729406_AddedRowVersionToDomainObjectBase",
                "201404181740359_AddedMultiplePropertiesToCustomer"
            };

            try
            {
                var sut = new DbDeploymentManager(
                    initializeConfig,
                    assemblyLoader,
                    new SqlClientDbConnectionInfoBuilder());
                sut.Deploy();

                // we expect no changes to migration history
                var migrationHistory = TestUtils.GetMigrationHistory(
                    serverName,
                    databaseName,
                    "Pinpoint.Test.Data.Migrations.Configuration");

                Assert.IsNotNull(migrationHistory);
                Assert.AreEqual(expectedMigrationHistory.Length, migrationHistory.Count());
                Assert.IsTrue(expectedMigrationHistory.SequenceEqual(migrationHistory));

                // no new deployment history should be created because no initialization nor migration should have occurred
                var actualDeploymentHistoryRowCount = TestUtils.GetDeploymentHistoryRowCount(
                    serverName,
                    databaseName,
                    "Pinpoint.Test.Data.Migrations.Configuration");
                Assert.AreEqual(0, actualDeploymentHistoryRowCount);
            }
            finally
            {
                // be sure to clean up
                TestUtils.DropDatabase(initializeConfig.Database.ServerName, initializeConfig.Database.DatabaseName);
            }
        }