-
Notifications
You must be signed in to change notification settings - Fork 1
/
SqlInstanceTest.cs
80 lines (78 loc) · 2.5 KB
/
SqlInstanceTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SSDTDeployer;
namespace DeployerTest
{
[TestClass]
public class SqlInstanceTest
{
[TestMethod]
public void TestDeployerLocalSqlInstance()
{
var dbName = "TestDeployerLocalSqlInstance";
var connectString = String.Format(Utils.LocalInstanceConnectionString, dbName);
var deployer = new SsdtServerDeployer(connectString, dbName, true);
deployer.DeployDacPac(Utils.Dacpac);
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.DeleteDb();
try
{
using (var c = new SqlConnection(connectString))
{
c.Open();
}
Assert.Fail("Should have thrown Exception");
}
catch (SqlException)
{
}
}
[TestMethod]
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)
{
}
}
}
}