public void TestDeployerLocalDb() { var dbName = "TestDeployerLocalSqlInstance"; if (File.Exists(dbName + ".mdf")) { File.Delete(dbName + ".mdf"); } if (File.Exists(dbName + "_log.ldf")) { File.Delete(dbName + "_log.ldf"); } var deployer = new SsdtLocalDbDeployer(dbName + ".mdf", true); deployer.DeployDacPac(Utils.Dacpac); Assert.IsFalse(DacHelper.DbExists(SsdtLocalDbDeployer.LocalDbDataSource, deployer.DbName)); var connectString = String.Format(SsdtLocalDbDeployer.LocalDbConnectionString, dbName + ".mdf"); using (var c = new SqlConnection(connectString)) { c.Open(); using (var cmd = c.CreateCommand()) { cmd.CommandText = "TRUNCATE TABLE TESTTABLE"; cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); } c.Close(); } deployer.DetachDb(); File.Delete(dbName + ".mdf"); File.Delete(dbName + "_log.ldf"); }
public void TestCreateSqlDb() { var dbName = "TestDeployerCraeteOnLocalSqlInstance"; var connectString = String.Format(Utils.LocalInstanceConnectionString, dbName); if (DacHelper.DbExists(".", dbName)) { var deployer2 = new SsdtServerDeployer(connectString, dbName, false); deployer2.DeleteDb(); } Assert.IsFalse(DacHelper.DbExists(".", dbName)); var deployer = new SsdtServerDeployer(connectString, dbName, false); var name = dbName + ".mdf"; deployer.CreatDb(name); Assert.IsTrue(File.Exists(name)); using (var c = new SqlConnection(connectString)) { c.Open(); c.Close(); } deployer.DeleteDb(); Assert.IsFalse(File.Exists(name)); try { using (var c = new SqlConnection(connectString)) { c.Open(); } Assert.Fail("Should have thrown Exception"); } catch (SqlException) { } }