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