Skip to content

Commit 7110853

Browse files
authored
Tests | Clean up test resources (#244)
* Fix leaking for CspProviderExt * Clean stored procedures for APIShould
1 parent 573558b commit 7110853

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/ApiShould.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,9 @@ private void DropHelperProcedures(string[] procNames)
18821882
sqlConnection.Open();
18831883
foreach (string name in procNames)
18841884
{
1885-
using (SqlCommand cmd = new SqlCommand(string.Format("IF EXISTS (SELECT * FROM sys.procedures WHERE name = '{0}') \n DROP PROCEDURE {0}", name), sqlConnection))
1885+
string procedureName = name.Trim( new Char[] { '[', ']'});
1886+
1887+
using (SqlCommand cmd = new SqlCommand(string.Format("IF EXISTS (SELECT * FROM sys.procedures WHERE name = '{0}') \n DROP PROCEDURE {0}", procedureName), sqlConnection))
18861888
{
18871889
cmd.ExecuteNonQuery();
18881890
}

src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/CspProviderExt.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
1616
[PlatformSpecific(TestPlatforms.Windows)]
1717
public class CspProviderExt
1818
{
19-
private string GenerateUniqueName(string baseName) => string.Concat("AE-", baseName, "-", Guid.NewGuid().ToString());
20-
2119
// [Fact(Skip="Run this in non-parallel mode")] or [ConditionalFact()]
2220
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
2321
public void TestKeysFromCertificatesCreatedWithMultipleCryptoProviders()
@@ -102,7 +100,8 @@ public void TestKeysFromCertificatesCreatedWithMultipleCryptoProviders()
102100
finally
103101
{
104102
CertificateUtilityWin.RemoveCertificate(certificateName, StoreLocation.CurrentUser);
105-
sqlSetupStrategyCsp?.DropTable();
103+
// clean up database resources
104+
sqlSetupStrategyCsp?.Dispose();
106105
}
107106

108107
}
@@ -187,7 +186,8 @@ public void TestEncryptDecryptWithCSP()
187186
}
188187
finally
189188
{
190-
sqlSetupStrategyCsp.DropTable();
189+
// clean up database resources
190+
sqlSetupStrategyCsp.Dispose();
191191
}
192192
}
193193
finally

src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/SQLSetupStrategyCspExt.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
99
{
1010
public class SQLSetupStrategyCspExt : SQLSetupStrategy
1111
{
12-
//public string keyPath {get; private set;}
1312
public Table CspProviderTable { get; private set; }
1413
public SqlColumnEncryptionCspProvider keyStoreProvider { get; }
1514

@@ -21,7 +20,7 @@ public SQLSetupStrategyCspExt(string cspKeyPath) : base(cspKeyPath)
2120

2221
internal override void SetupDatabase()
2322
{
24-
ColumnMasterKey columnMasterKey = new CspColumnMasterKey(GenerateUniqueName("CMK"), SqlColumnEncryptionCspProvider.ProviderName, keyPath);
23+
ColumnMasterKey columnMasterKey = new CspColumnMasterKey(GenerateUniqueName("CspExt"), SqlColumnEncryptionCspProvider.ProviderName, keyPath);
2524
databaseObjects.Add(columnMasterKey);
2625

2726
List<ColumnEncryptionKey> columnEncryptionKeys = CreateColumnEncryptionKeys(columnMasterKey, 2, keyStoreProvider);
@@ -43,14 +42,5 @@ private Table CreateTable(IList<ColumnEncryptionKey> columnEncryptionKeys)
4342

4443
return CspProviderTable;
4544
}
46-
47-
public void DropTable()
48-
{
49-
using (SqlConnection sqlConnection = new SqlConnection(DataTestUtility.TcpConnStr))
50-
{
51-
sqlConnection.Open();
52-
CspProviderTable.Drop(sqlConnection);
53-
}
54-
}
5545
}
5646
}

0 commit comments

Comments
 (0)