Skip to content

Commit

Permalink
Tests | Clean up test resources (dotnet#244)
Browse files Browse the repository at this point in the history
* Fix leaking for CspProviderExt

* Clean stored procedures for APIShould
  • Loading branch information
karinazhou authored Oct 4, 2019
1 parent 58f2e3e commit 807babc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1882,7 +1882,9 @@ private void DropHelperProcedures(string[] procNames)
sqlConnection.Open();
foreach (string name in procNames)
{
using (SqlCommand cmd = new SqlCommand(string.Format("IF EXISTS (SELECT * FROM sys.procedures WHERE name = '{0}') \n DROP PROCEDURE {0}", name), sqlConnection))
string procedureName = name.Trim( new Char[] { '[', ']'});

using (SqlCommand cmd = new SqlCommand(string.Format("IF EXISTS (SELECT * FROM sys.procedures WHERE name = '{0}') \n DROP PROCEDURE {0}", procedureName), sqlConnection))
{
cmd.ExecuteNonQuery();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
[PlatformSpecific(TestPlatforms.Windows)]
public class CspProviderExt
{
private string GenerateUniqueName(string baseName) => string.Concat("AE-", baseName, "-", Guid.NewGuid().ToString());

// [Fact(Skip="Run this in non-parallel mode")] or [ConditionalFact()]
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
public void TestKeysFromCertificatesCreatedWithMultipleCryptoProviders()
Expand Down Expand Up @@ -102,7 +100,8 @@ public void TestKeysFromCertificatesCreatedWithMultipleCryptoProviders()
finally
{
CertificateUtilityWin.RemoveCertificate(certificateName, StoreLocation.CurrentUser);
sqlSetupStrategyCsp?.DropTable();
// clean up database resources
sqlSetupStrategyCsp?.Dispose();
}

}
Expand Down Expand Up @@ -187,7 +186,8 @@ public void TestEncryptDecryptWithCSP()
}
finally
{
sqlSetupStrategyCsp.DropTable();
// clean up database resources
sqlSetupStrategyCsp.Dispose();
}
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
{
public class SQLSetupStrategyCspExt : SQLSetupStrategy
{
//public string keyPath {get; private set;}
public Table CspProviderTable { get; private set; }
public SqlColumnEncryptionCspProvider keyStoreProvider { get; }

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

internal override void SetupDatabase()
{
ColumnMasterKey columnMasterKey = new CspColumnMasterKey(GenerateUniqueName("CMK"), SqlColumnEncryptionCspProvider.ProviderName, keyPath);
ColumnMasterKey columnMasterKey = new CspColumnMasterKey(GenerateUniqueName("CspExt"), SqlColumnEncryptionCspProvider.ProviderName, keyPath);
databaseObjects.Add(columnMasterKey);

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

return CspProviderTable;
}

public void DropTable()
{
using (SqlConnection sqlConnection = new SqlConnection(DataTestUtility.TcpConnStr))
{
sqlConnection.Open();
CspProviderTable.Drop(sqlConnection);
}
}
}
}

0 comments on commit 807babc

Please sign in to comment.