public void NoOpMigrationWhenMigratingDownwardPastInitialMigrationUsingDeploymentHistoryWithoutAnOverride()
{
const string serverName = @"(localdb)\mssqllocaldb";
var databaseName = $"GalenTest_{Guid.NewGuid():N}";
var assemblyLoader = new AssemblyLoader();
// start by initializing to v3
var initialDeploymentConfig = new DbDeploymentManagerConfiguration
{
Mode = DeploymentMode.InitializeOnly,
TargetAssemblyPath = TestUtils.BuildTestAssemblyPath(3),
Database = new DatabaseEndpoint { ServerName = serverName, DatabaseName = databaseName },
InitializationConfig = new InitializerConfigurationInfo
{
Type = "Pinpoint.Test.Data.Initializers.AnotherTestContextCreateDatabaseIfNotExists"
}
};
var expectedInitialMigrationHistory = new[]
{
"201404181743108_InitialCreate"
};
try
{
var sut = new DbDeploymentManager(
initialDeploymentConfig,
assemblyLoader,
new SqlClientDbConnectionInfoBuilder());
sut.Deploy();
var actualDeploymentHistoryRowCount = TestUtils.GetDeploymentHistoryRowCount(
serverName,
databaseName,
"Pinpoint.Test.Data.AnotherTestContextMigrations.Configuration");
Assert.AreEqual(1, actualDeploymentHistoryRowCount);
var migrationHistory = TestUtils.GetMigrationHistory(
serverName,
databaseName,
"Pinpoint.Test.Data.AnotherTestContextMigrations.Configuration");
Assert.IsNotNull(migrationHistory);
Assert.AreEqual(expectedInitialMigrationHistory.Length, migrationHistory.Count());
Assert.IsTrue(expectedInitialMigrationHistory.SequenceEqual(migrationHistory));
}
catch
{
// clean up if there was a problem
TestUtils.DropDatabase(
initialDeploymentConfig.Database.ServerName,
initialDeploymentConfig.Database.DatabaseName);
throw;
}
// attempt to migrate downward from v3 past initial create using Deployment History
// without specifying a deployed assembly override
var downwardMigrationConfig = new DbDeploymentManagerConfiguration
{
TargetAssemblyPath = TestUtils.BuildTestAssemblyPath(1),
Database = new DatabaseEndpoint { ServerName = serverName, DatabaseName = databaseName },
MigrationConfig = new MigrationConfigurationInfo
{
Type = "Pinpoint.Test.Data.AnotherTestContextMigrations.Configuration"
}
};
try
{
var sut = new DbDeploymentManager(
downwardMigrationConfig,
assemblyLoader,
new SqlClientDbConnectionInfoBuilder());
sut.Deploy();
// we expect no changes to migration history
var migrationHistory = TestUtils.GetMigrationHistory(
serverName,
databaseName,
downwardMigrationConfig.MigrationConfig.Type);
Assert.IsNotNull(migrationHistory);
Assert.AreEqual(expectedInitialMigrationHistory.Length, migrationHistory.Count());
Assert.IsTrue(expectedInitialMigrationHistory.SequenceEqual(migrationHistory));
// no new deployment history should be created because no migration should have occurred
var actualDeploymentHistoryRowCount = TestUtils.GetDeploymentHistoryRowCount(
serverName,
databaseName,
"Pinpoint.Test.Data.AnotherTestContextMigrations.Configuration");
Assert.AreEqual(1, actualDeploymentHistoryRowCount);
}
finally
{
// be sure to clean up
TestUtils.DropDatabase(downwardMigrationConfig.Database.ServerName, downwardMigrationConfig.Database.DatabaseName);
}
}