public void NoOpWhenInitializingOrMigratingToCurrentDeployedVersion()
{
const string serverName = @"(localdb)\mssqllocaldb";
var databaseName = $"GalenTest_{Guid.NewGuid():N}";
var assemblyLoader = new AssemblyLoader();
var currentAssemblyPath = TestUtils.BuildTestAssemblyPath(3);
// start at v3 - (this creates deployment history)
var initializeOrMigrateConfig = new DbDeploymentManagerConfiguration
{
Mode = DeploymentMode.InitializeOrMigrate,
TargetAssemblyPath = currentAssemblyPath,
Database = new DatabaseEndpoint { ServerName = serverName, DatabaseName = databaseName },
InitializationConfig = new InitializerConfigurationInfo
{
Type = "Pinpoint.Test.Data.Initializers.TestContextCreateDatabaseIfNotExists"
},
MigrationConfig = new MigrationConfigurationInfo
{
Type = "Pinpoint.Test.Data.Migrations.Configuration"
}
};
var expectedMigrationHistory = new[]
{
"201404181533201_InitialCreate",
"201404181719410_AddedAddresInfoToCustomer",
"201404181726158_MoveAddressInformationIntoContactInfo",
"201404181729406_AddedRowVersionToDomainObjectBase",
"201404181740359_AddedMultiplePropertiesToCustomer"
};
try
{
var sut = new DbDeploymentManager(
initializeOrMigrateConfig,
assemblyLoader,
new SqlClientDbConnectionInfoBuilder());
sut.Deploy();
var actualDeploymentHistoryRowCount = TestUtils.GetDeploymentHistoryRowCount(
serverName,
databaseName,
initializeOrMigrateConfig.MigrationConfig.Type);
Assert.AreEqual(1, actualDeploymentHistoryRowCount);
var migrationHistory = TestUtils.GetMigrationHistory(
serverName,
databaseName,
initializeOrMigrateConfig.MigrationConfig.Type);
Assert.IsNotNull(migrationHistory);
Assert.AreEqual(expectedMigrationHistory.Length, migrationHistory.Count());
Assert.IsTrue(expectedMigrationHistory.SequenceEqual(migrationHistory));
}
catch
{
// clean up if there was a problem
TestUtils.DropDatabase(
initializeOrMigrateConfig.Database.ServerName,
initializeOrMigrateConfig.Database.DatabaseName);
throw;
}
try
{
// run another InitializeOrMigrate to the same version as what is deployed
// (this is a close representation of how our release management works)
var sut = new DbDeploymentManager(
initializeOrMigrateConfig, // <-- reuse; same as before, nothing has changed
assemblyLoader,
new SqlClientDbConnectionInfoBuilder());
sut.Deploy();
// nothing should be different in deployment history
var actualDeploymentHistoryRowCount = TestUtils.GetDeploymentHistoryRowCount(
serverName,
databaseName,
initializeOrMigrateConfig.MigrationConfig.Type);
Assert.AreEqual(1, actualDeploymentHistoryRowCount);
// nothing should be different in migration history
var migrationHistory = TestUtils.GetMigrationHistory(
serverName,
databaseName,
initializeOrMigrateConfig.MigrationConfig.Type);
Assert.IsNotNull(migrationHistory);
Assert.AreEqual(expectedMigrationHistory.Length, migrationHistory.Count());
Assert.IsTrue(expectedMigrationHistory.SequenceEqual(migrationHistory));
}
finally
{
// be sure to clean up
TestUtils.DropDatabase(initializeOrMigrateConfig.Database.ServerName, initializeOrMigrateConfig.Database.DatabaseName);
}
}