in SampleTests/TestDbLocationModifiers.cs [198:231]
public void TestDbCreateDatabaseModifier()
{
// Given database name, and paths to save to
string dbName = TestContext.TestName;
string dataFolder = GetTestDir();
string mdfFilePath = Path.Combine(dataFolder, "mydb.mdf");
string ldfFilePath = Path.Combine(dataFolder, "mydb_log.ldf");
TestUtils.DeleteIfExists(mdfFilePath);
TestUtils.DeleteIfExists(ldfFilePath);
// When deploying using the create database statement changing contributor
try
{
// Deploy to nonexistent database - should work quickly
DacDeployOptions options = SetCreateDatabaseContributorOptions(mdfFilePath, ldfFilePath);
Deploy(dbName, options);
// Then expect the database to be saved under that path
AssertDeploySucceeded(TestUtils.ServerConnectionString, dbName);
Assert.IsTrue(File.Exists(mdfFilePath));
Assert.IsTrue(File.Exists(ldfFilePath));
// Note: for a real application, after creating the DB on the server they may want to
// detach it and reattach using the database path. We are not doing this since it's
// not relevant to this test
}
finally
{
TestUtils.DropDatabase(TestUtils.ServerConnectionString, dbName);
TestUtils.DeleteIfExists(mdfFilePath);
TestUtils.DeleteIfExists(ldfFilePath);
}
}