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);
}
}