Skip to content

Commit ce4605d

Browse files
author
Javad
authored
Tests | Addressing Net5 runtime issues (#880)
1 parent ca2fe25 commit ce4605d

27 files changed

+156
-140
lines changed

BUILDGUIDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ Tests can be built and run with custom Target Frameworks. See the below examples
209209
```bash
210210
> msbuild /t:BuildTestsNetCore /p:TargetNetCoreVersion=netcoreapp3.1
211211
# Build the tests for custom TargetFramework (.NET Core)
212-
# Applicable values: netcoreapp2.1 | netcoreapp2.2 | netcoreapp3.1 | netcoreapp5.0
212+
# Applicable values: netcoreapp2.1 | netcoreapp2.2 | netcoreapp3.1 | net5.0
213213
```
214214

215215
### Running Tests:
@@ -221,7 +221,7 @@ Tests can be built and run with custom Target Frameworks. See the below examples
221221

222222
> dotnet test /p:TargetNetCoreVersion=netcoreapp3.1 ...
223223
# Use above property to run Functional Tests with custom TargetFramework (.NET Core)
224-
# Applicable values: netcoreapp2.1 | netcoreapp2.2 | netcoreapp3.1 | netcoreapp5.0
224+
# Applicable values: netcoreapp2.1 | netcoreapp2.2 | netcoreapp3.1 | net5.0
225225
```
226226

227227
## Using Managed SNI on Windows

RunTests.cmd

Lines changed: 24 additions & 24 deletions
Large diffs are not rendered by default.

src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/ExceptionsCertStore.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void CertificateNotFound()
4141
Assert.Matches(expectedMessage, e.Message);
4242
}
4343

44-
#if NET46
44+
#if NETFX
4545
[Fact]
4646
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp)]
4747
public void CertificateWithNoPrivateKey()
@@ -68,7 +68,7 @@ public class ExceptionCertFixture : IDisposable
6868
public static string thumbprint;
6969
public static byte[] cek;
7070
public static byte[] encryptedCek;
71-
#if NET46
71+
#if NETFX
7272
public static X509Certificate2 masterKeyCertificateNPK; // no private key
7373
public static string thumbprintNPK; // No private key
7474
public static string masterKeyPathNPK;
@@ -84,7 +84,7 @@ public ExceptionCertFixture()
8484
certificatePath = string.Format("CurrentUser/My/{0}", thumbprint);
8585
cek = Utility.GenerateRandomBytes(32);
8686
encryptedCek = certStoreProvider.EncryptColumnEncryptionKey(certificatePath, "RSA_OAEP", cek);
87-
#if NET46
87+
#if NETFX
8888
if(masterKeyCertificateNPK == null)
8989
{
9090
masterKeyCertificateNPK = Utility.CreateCertificateWithNoPrivateKey();

src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/SqlColumnEncryptionCspProviderShould.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ public void Dispose()
183183

184184
public static void AddKeyToCsp(string containerName)
185185
{
186+
186187
CspParameters cspParams = new CspParameters();
187188
cspParams.KeyContainerName = containerName;
188189
RSACryptoServiceProvider rsaAlg = new RSACryptoServiceProvider(KEY_SIZE, cspParams);

src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22
<PropertyGroup>
33
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
44
<AssemblyName>FunctionalTests</AssemblyName>
5-
<TargetGroup Condition="$(TargetFramework.StartsWith('netcoreapp'))">netcoreapp</TargetGroup>
65
<TargetGroup Condition="$(TargetFramework.StartsWith('net4'))">netfx</TargetGroup>
6+
<TargetGroup Condition="$(TargetGroup) == ''">netcoreapp</TargetGroup>
77
<Configurations>Debug;Release;net461-Release;net461-Debug;netcoreapp2.1-Debug;netcoreapp2.1-Release;netcoreapp3.1-Debug;netcoreapp3.1-Release</Configurations>
88
<Platforms>AnyCPU;x86;x64</Platforms>
9+
<DefineConstants Condition="'$(TargetGroup)'=='netfx'">$(DefineConstants);NETFX</DefineConstants>
910
<DefineConstants Condition="'$(TargetGroup)'=='netcoreapp'">$(DefineConstants);NETCOREAPP</DefineConstants>
11+
<DefineConstants Condition="'$(TargetGroup)' == 'netcoreapp' AND !$(TargetFramework.StartsWith('netcoreapp'))">$(DefineConstants);NET50_OR_LATER</DefineConstants>
1012
<IntermediateOutputPath>$(ObjFolder)$(Configuration).$(Platform).$(AssemblyName)</IntermediateOutputPath>
1113
<OutputPath>$(BinFolder)$(Configuration).$(Platform).$(AssemblyName)</OutputPath>
1214
</PropertyGroup>
1315
<ItemGroup Condition="!$(ReferenceType.Contains('NetStandard'))">
1416
<Compile Include="SqlConnectionStringBuilderPoolBlockingTest.cs" />
1517
</ItemGroup>
16-
<ItemGroup>
17-
<Compile Include="AlwaysEncryptedTests\ExceptionsAlgorithmErrors.cs" />
18-
<Compile Include="AlwaysEncryptedTests\ExceptionsCertStore.cs" />
18+
<ItemGroup Condition="'OsGroup'=='Windows'">
1919
<Compile Include="AlwaysEncryptedTests\SqlColumnEncryptionCertificateStoreProviderShould.cs" />
2020
<Compile Include="AlwaysEncryptedTests\SqlColumnEncryptionCngProviderShould.cs" />
2121
<Compile Include="AlwaysEncryptedTests\SqlColumnEncryptionCspProviderShould.cs" />
22+
</ItemGroup>
23+
<ItemGroup>
24+
<Compile Include="AlwaysEncryptedTests\ExceptionsAlgorithmErrors.cs" />
25+
<Compile Include="AlwaysEncryptedTests\ExceptionsCertStore.cs" />
2226
<Compile Include="AlwaysEncryptedTests\ConnectionStringBuilderShould.cs" />
2327
<Compile Include="AlwaysEncryptedTests\DummyKeyStoreProvider.cs" />
2428
<Compile Include="AlwaysEncryptedTests\ExceptionRegisterKeyStoreProvider.cs" />

src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlCommandTest.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void Constructor1()
2424
Assert.Null(cmd.Container);
2525
Assert.True(cmd.DesignTimeVisible);
2626
Assert.Null(cmd.Notification);
27-
#if NET461
27+
#if NETFX
2828
// see https://github.com/dotnet/SqlClient/issues/17
2929
Assert.True(cmd.NotificationAutoEnlist);
3030
#endif
@@ -46,7 +46,7 @@ public void Constructor2()
4646
Assert.Null(cmd.Container);
4747
Assert.True(cmd.DesignTimeVisible);
4848
Assert.Null(cmd.Notification);
49-
#if NET461
49+
#if NETFX
5050
// see https://github.com/dotnet/SqlClient/issues/17
5151
Assert.True(cmd.NotificationAutoEnlist);
5252
#endif
@@ -64,7 +64,7 @@ public void Constructor2()
6464
Assert.Null(cmd.Container);
6565
Assert.True(cmd.DesignTimeVisible);
6666
Assert.Null(cmd.Notification);
67-
#if NET461
67+
#if NETFX
6868
// see https://github.com/dotnet/SqlClient/issues/17
6969
Assert.True(cmd.NotificationAutoEnlist);
7070
#endif
@@ -89,7 +89,7 @@ public void Constructor3()
8989
Assert.Null(cmd.Container);
9090
Assert.True(cmd.DesignTimeVisible);
9191
Assert.Null(cmd.Notification);
92-
#if NET461
92+
#if NETFX
9393
// see https://github.com/dotnet/SqlClient/issues/17
9494
Assert.True(cmd.NotificationAutoEnlist);
9595
#endif
@@ -107,7 +107,7 @@ public void Constructor3()
107107
Assert.Null(cmd.Container);
108108
Assert.True(cmd.DesignTimeVisible);
109109
Assert.Null(cmd.Notification);
110-
#if NET461
110+
#if NETFX
111111
// see https://github.com/dotnet/SqlClient/issues/17
112112
Assert.True(cmd.NotificationAutoEnlist);
113113
#endif
@@ -125,7 +125,7 @@ public void Constructor3()
125125
Assert.Null(cmd.Container);
126126
Assert.True(cmd.DesignTimeVisible);
127127
Assert.Null(cmd.Notification);
128-
#if NET461
128+
#if NETFX
129129
// see https://github.com/dotnet/SqlClient/issues/17
130130
Assert.True(cmd.NotificationAutoEnlist);
131131
#endif
@@ -166,7 +166,7 @@ public void Constructor4()
166166
Assert.Null(cmd.Container);
167167
Assert.True(cmd.DesignTimeVisible);
168168
Assert.Null(cmd.Notification);
169-
#if NET461
169+
#if NETFX
170170
// see https://github.com/dotnet/SqlClient/issues/17
171171
Assert.True(cmd.NotificationAutoEnlist);
172172
#endif
@@ -184,7 +184,7 @@ public void Constructor4()
184184
Assert.Null(cmd.Container);
185185
Assert.True(cmd.DesignTimeVisible);
186186
Assert.Null(cmd.Notification);
187-
#if NET461
187+
#if NETFX
188188
// see https://github.com/dotnet/SqlClient/issues/17
189189
Assert.True(cmd.NotificationAutoEnlist);
190190
#endif
@@ -202,7 +202,7 @@ public void Constructor4()
202202
Assert.Null(cmd.Container);
203203
Assert.True(cmd.DesignTimeVisible);
204204
Assert.Null(cmd.Notification);
205-
#if NET461
205+
#if NETFX
206206
// see https://github.com/dotnet/SqlClient/issues/17
207207
Assert.True(cmd.NotificationAutoEnlist);
208208
#endif
@@ -224,7 +224,7 @@ public void Clone()
224224
cmd.CommandType = CommandType.StoredProcedure;
225225
cmd.DesignTimeVisible = false;
226226
cmd.Notification = notificationReq;
227-
#if NET461
227+
#if NETFX
228228
// see https://github.com/dotnet/SqlClient/issues/17
229229
Assert.True(cmd.NotificationAutoEnlist);
230230
#endif
@@ -240,7 +240,7 @@ public void Clone()
240240
Assert.Null(cmd.Connection);
241241
Assert.False(cmd.DesignTimeVisible);
242242
Assert.Same(notificationReq, cmd.Notification);
243-
#if NET461
243+
#if NETFX
244244
// see https://github.com/dotnet/SqlClient/issues/17
245245
Assert.True(cmd.NotificationAutoEnlist);
246246
#endif

src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlExceptionTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public void SerializationTest()
3333
Assert.Equal(e.StackTrace, sqlEx.StackTrace);
3434
}
3535

36+
#if !NET50_OR_LATER
3637
[Fact]
3738
[ActiveIssue("12161", TestPlatforms.AnyUnix)]
3839
public static void SqlExcpetionSerializationTest()
@@ -53,6 +54,7 @@ public static void SqlExcpetionSerializationTest()
5354
}
5455
}
5556
}
57+
#endif
5658

5759
[Fact]
5860
public void JSONSerializationTest()

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public ConversionTests()
6767
certStoreProvider);
6868
databaseObjects.Add(columnEncryptionKey);
6969

70-
foreach(string connectionStr in DataTestUtility.AEConnStringsSetup)
70+
foreach (string connectionStr in DataTestUtility.AEConnStringsSetup)
7171
{
7272
using (SqlConnection sqlConnection = new SqlConnection(connectionStr))
7373
{
@@ -1346,7 +1346,7 @@ private void SetParamSizeScalePrecision(ref SqlParameter param, ColumnMetaData c
13461346
public void Dispose()
13471347
{
13481348
databaseObjects.Reverse();
1349-
foreach(string connectionStr in DataTestUtility.AEConnStringsSetup)
1349+
foreach (string connectionStr in DataTestUtility.AEConnStringsSetup)
13501350
{
13511351
using (SqlConnection sqlConnection = new SqlConnection(connectionStr))
13521352
{
@@ -1429,14 +1429,14 @@ public IEnumerator<object[]> GetEnumerator()
14291429
yield return new object[] { connStrAE, SqlDbType.DateTime2, SqlDbType.DateTime2 };
14301430
yield return new object[] { connStrAE, SqlDbType.DateTimeOffset, SqlDbType.DateTimeOffset };
14311431
yield return new object[] { connStrAE, SqlDbType.Float, SqlDbType.Float };
1432-
yield return new object[] { connStrAE, SqlDbType.Real, SqlDbType.Real};
1432+
yield return new object[] { connStrAE, SqlDbType.Real, SqlDbType.Real };
14331433
}
14341434
}
14351435

14361436
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
14371437
}
14381438

1439-
1439+
14401440
public class TestOutOfRangeValuesData : IEnumerable<object[]>
14411441
{
14421442
public IEnumerator<object[]> GetEnumerator()

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@
77
using System.Security.Cryptography.X509Certificates;
88
using Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted.Setup;
99
using Xunit;
10+
#if NET50_OR_LATER
11+
using System.Runtime.Versioning;
12+
#endif
1013

1114
namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
1215
{
1316
/// <summary>
1417
/// Always Encrypted public CspProvider Manual tests.
1518
/// TODO: These tests are marked as Windows only for now but should be run for all platforms once the Master Key is accessible to this app from Azure Key Vault.
1619
/// </summary>
20+
#if NET50_OR_LATER
21+
[SupportedOSPlatform("windows")]
22+
#endif
1723
[PlatformSpecific(TestPlatforms.Windows)]
1824
public class CspProviderExt
1925
{
@@ -81,9 +87,10 @@ public void TestKeysFromCertificatesCreatedWithMultipleCryptoProviders(string co
8187
DatabaseHelper.InsertCustomerData(sqlConn, tableName, customer);
8288

8389
// Test INPUT parameter on an encrypted parameter
84-
using (SqlCommand sqlCommand = new SqlCommand(string.Format(@"SELECT CustomerId, FirstName, LastName FROM [{0}] WHERE FirstName = @firstName", tableName),
90+
using (SqlCommand sqlCommand = new SqlCommand(@"SELECT CustomerId, FirstName, LastName FROM [@tableName] WHERE FirstName = @firstName",
8591
sqlConn, null, SqlCommandColumnEncryptionSetting.Enabled))
8692
{
93+
sqlCommand.Parameters.AddWithValue(@"tableName", tableName);
8794
SqlParameter customerFirstParam = sqlCommand.Parameters.AddWithValue(@"firstName", @"Microsoft");
8895
customerFirstParam.Direction = System.Data.ParameterDirection.Input;
8996

@@ -173,9 +180,10 @@ public void TestEncryptDecryptWithCSP(string connectionString)
173180
DatabaseHelper.InsertCustomerData(sqlConn, tableName, customer);
174181

175182
// Test INPUT parameter on an encrypted parameter
176-
using (SqlCommand sqlCommand = new SqlCommand(string.Format(@"SELECT CustomerId, FirstName, LastName FROM [{0}] WHERE FirstName = @firstName", tableName),
183+
using (SqlCommand sqlCommand = new SqlCommand(@"SELECT CustomerId, FirstName, LastName FROM [@tableName] WHERE FirstName = @firstName",
177184
sqlConn, null, SqlCommandColumnEncryptionSetting.Enabled))
178185
{
186+
sqlCommand.Parameters.AddWithValue(@"tableName", tableName);
179187
SqlParameter customerFirstParam = sqlCommand.Parameters.AddWithValue(@"firstName", @"Microsoft");
180188
customerFirstParam.Direction = System.Data.ParameterDirection.Input;
181189

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,22 @@ public PlatformSpecificTestContext()
272272
{
273273
certStoreFixture = new SQLSetupStrategyCertStoreProvider();
274274
}
275-
#if !NET46
276275
else
277276
{
278277
akvFixture = new SQLSetupStrategyAzureKeyVault();
279278
}
280-
#endif
281279
}
282280

283281
public void Dispose()
284282
{
285-
Fixture.Dispose();
283+
try
284+
{
285+
akvFixture?.Dispose();
286+
}
287+
finally
288+
{
289+
certStoreFixture?.Dispose();
290+
}
286291
}
287292
}
288293
}

0 commit comments

Comments
 (0)