From 91cacc97aa8a7141c3180557081391074342d809 Mon Sep 17 00:00:00 2001 From: JRahnama Date: Wed, 2 Nov 2022 10:47:41 -0700 Subject: [PATCH 1/2] Removing all net5 references from the driver --- .../src/System/Diagnostics/CodeAnalysis.cs | 2 +- .../SqlColumnEncryptionCertificateStoreProviderShould.cs | 2 +- .../SqlColumnEncryptionCngProviderShould.cs | 4 ++-- .../SqlColumnEncryptionCspProviderShould.cs | 4 ++-- .../FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj | 1 - .../tests/ManualTests/AlwaysEncrypted/CspProviderExt.cs | 4 ++-- .../TestFixtures/Setup/CertificateUtilityWin.cs | 4 ++-- .../tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs | 7 ++----- .../SQL/SqlDSEnumeratorTest/SqlDataSourceEnumeratorTest.cs | 2 +- .../Microsoft.Data.SqlClient.PerformanceTests.csproj | 2 +- 10 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/src/System/Diagnostics/CodeAnalysis.cs b/src/Microsoft.Data.SqlClient/src/System/Diagnostics/CodeAnalysis.cs index 256f7cd1e0..e62544d06d 100644 --- a/src/Microsoft.Data.SqlClient/src/System/Diagnostics/CodeAnalysis.cs +++ b/src/Microsoft.Data.SqlClient/src/System/Diagnostics/CodeAnalysis.cs @@ -59,7 +59,7 @@ internal sealed class NotNullWhenAttribute : Attribute } #endif -#if !NET5_0_OR_GREATER +#if !NET6_0_OR_GREATER [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = true, Inherited = false)] internal sealed class MemberNotNullAttribute : Attribute { diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/SqlColumnEncryptionCertificateStoreProviderShould.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/SqlColumnEncryptionCertificateStoreProviderShould.cs index b0c6297cda..5b7dd192ef 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/SqlColumnEncryptionCertificateStoreProviderShould.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/SqlColumnEncryptionCertificateStoreProviderShould.cs @@ -634,7 +634,7 @@ public static bool IsAdmin { get { -#if NET5_0_OR_GREATER +#if NET6_0_OR_GREATER System.Diagnostics.Debug.Assert(OperatingSystem.IsWindows()); #endif return new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator); diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/SqlColumnEncryptionCngProviderShould.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/SqlColumnEncryptionCngProviderShould.cs index 9d1c698f17..08a71335d9 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/SqlColumnEncryptionCngProviderShould.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/SqlColumnEncryptionCngProviderShould.cs @@ -182,7 +182,7 @@ public void Dispose() public static void AddKeyToCng(string providerName, string containerName) { -#if NET5_0_OR_GREATER +#if NET6_0_OR_GREATER System.Diagnostics.Debug.Assert(OperatingSystem.IsWindows()); #endif CngKeyCreationParameters keyParams = new CngKeyCreationParameters(); @@ -202,7 +202,7 @@ public static void AddKeyToCng(string providerName, string containerName) public static void RemoveKeyFromCng(string providerName, string containerName) { -#if NET5_0_OR_GREATER +#if NET6_0_OR_GREATER System.Diagnostics.Debug.Assert(OperatingSystem.IsWindows()); #endif CngProvider cngProvider = new CngProvider(providerName); diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/SqlColumnEncryptionCspProviderShould.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/SqlColumnEncryptionCspProviderShould.cs index a71fe5c473..609c62ea53 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/SqlColumnEncryptionCspProviderShould.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/SqlColumnEncryptionCspProviderShould.cs @@ -183,7 +183,7 @@ public void Dispose() public static void AddKeyToCsp(string containerName) { -#if NET5_0_OR_GREATER +#if NET6_0_OR_GREATER System.Diagnostics.Debug.Assert(OperatingSystem.IsWindows()); #endif CspParameters cspParams = new(); @@ -194,7 +194,7 @@ public static void AddKeyToCsp(string containerName) public static void RemoveKeyFromCsp(string containerName) { -#if NET5_0_OR_GREATER +#if NET6_0_OR_GREATER System.Diagnostics.Debug.Assert(OperatingSystem.IsWindows()); #endif CspParameters cspParams = new CspParameters(); diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj index 129d832488..2871cf9434 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj @@ -7,7 +7,6 @@ win $(DefineConstants);NETFRAMEWORK $(DefineConstants);NETCOREAPP - $(DefineConstants);NET50_OR_LATER NETSTANDARDREFERNCE $(ObjFolder)$(Configuration).$(Platform).$(AssemblyName) $(BinFolder)$(Configuration).$(Platform).$(AssemblyName) diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/CspProviderExt.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/CspProviderExt.cs index 387f364f56..5e998d057a 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/CspProviderExt.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/CspProviderExt.cs @@ -7,7 +7,7 @@ using System.Security.Cryptography.X509Certificates; using Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted.Setup; using Xunit; -#if NET50_OR_LATER +#if NET6_0_OR_GREATER using System.Runtime.Versioning; #endif @@ -17,7 +17,7 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted /// Always Encrypted public CspProvider Manual tests. /// 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. /// -#if NET50_OR_LATER +#if NET6_0_OR_GREATER [SupportedOSPlatform("windows")] #endif [PlatformSpecific(TestPlatforms.Windows)] diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/Setup/CertificateUtilityWin.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/Setup/CertificateUtilityWin.cs index 72b14c8f51..5a1249434a 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/Setup/CertificateUtilityWin.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/Setup/CertificateUtilityWin.cs @@ -7,13 +7,13 @@ using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using Xunit; -#if NET50_OR_LATER +#if NET6_0_OR_GREATER using System.Runtime.Versioning; #endif namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted { -#if NET50_OR_LATER +#if NET6_0_OR_GREATER [SupportedOSPlatform("windows")] #endif [PlatformSpecific(TestPlatforms.Windows)] diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs index dba70d5fcd..c8ae748bc1 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs @@ -1556,13 +1556,10 @@ private static void ReadStream(string connectionString) DataTestUtility.AssertThrowsWrapper(() => stream.Read(buffer, -1, 2)); DataTestUtility.AssertThrowsWrapper(() => stream.Read(buffer, 2, -1)); - // ArgumentException is thrown in net5 and earlier. ArgumentOutOfRangeException in net6 and later ArgumentException ex = Assert.ThrowsAny(() => stream.Read(buffer, buffer.Length, buffer.Length)); - Assert.True(ex.GetType() == typeof(ArgumentException) || ex.GetType() == typeof(ArgumentOutOfRangeException), - "Expected: ArgumentException in net5 and earlier. ArgumentOutOfRangeException in net6 and later."); + Assert.Equal(typeof(ArgumentOutOfRangeException), ex.GetType()); ex = Assert.ThrowsAny(() => stream.Read(buffer, int.MaxValue, int.MaxValue)); - Assert.True(ex.GetType() == typeof(ArgumentException) || ex.GetType() == typeof(ArgumentOutOfRangeException), - "Expected: ArgumentException in net5 and earlier. ArgumentOutOfRangeException in net6 and later."); + Assert.Equal(typeof(ArgumentOutOfRangeException), ex.GetType()); } // Once Reader is closed diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlDSEnumeratorTest/SqlDataSourceEnumeratorTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlDSEnumeratorTest/SqlDataSourceEnumeratorTest.cs index f5a9a063ac..2726f5441d 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlDSEnumeratorTest/SqlDataSourceEnumeratorTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlDSEnumeratorTest/SqlDataSourceEnumeratorTest.cs @@ -10,7 +10,7 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests { -#if NET50_OR_LATER +#if NET6_0_OR_GREATER [System.Runtime.Versioning.SupportedOSPlatform("windows")] #endif public class SqlDataSourceEnumeratorTest diff --git a/src/Microsoft.Data.SqlClient/tests/PerformanceTests/Microsoft.Data.SqlClient.PerformanceTests.csproj b/src/Microsoft.Data.SqlClient/tests/PerformanceTests/Microsoft.Data.SqlClient.PerformanceTests.csproj index b8b83efb00..c751a82c39 100644 --- a/src/Microsoft.Data.SqlClient/tests/PerformanceTests/Microsoft.Data.SqlClient.PerformanceTests.csproj +++ b/src/Microsoft.Data.SqlClient/tests/PerformanceTests/Microsoft.Data.SqlClient.PerformanceTests.csproj @@ -2,7 +2,7 @@ Exe PerformanceTests - net6.0;net5.0 + net6.0 false Debug;Release; $(ObjFolder)$(Configuration).$(Platform).$(AssemblyName) From b6062914065ad599721ca3035693ba4ff260ad9e Mon Sep 17 00:00:00 2001 From: JRahnama Date: Wed, 2 Nov 2022 11:35:02 -0700 Subject: [PATCH 2/2] Reverting back the change as netstandard2.1 still showing a different exception --- .../ManualTests/SQL/DataStreamTest/DataStreamTest.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs index c8ae748bc1..30a1505442 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs @@ -1556,10 +1556,14 @@ private static void ReadStream(string connectionString) DataTestUtility.AssertThrowsWrapper(() => stream.Read(buffer, -1, 2)); DataTestUtility.AssertThrowsWrapper(() => stream.Read(buffer, 2, -1)); + // Prior to net6 comment:ArgumentException is thrown in net5 and earlier. ArgumentOutOfRangeException in net6 and later + // After adding net6: Running tests against netstandard2.1 still showing ArgumentException, but the rest works fine. ArgumentException ex = Assert.ThrowsAny(() => stream.Read(buffer, buffer.Length, buffer.Length)); - Assert.Equal(typeof(ArgumentOutOfRangeException), ex.GetType()); + Assert.True(ex.GetType() == typeof(ArgumentException) || ex.GetType() == typeof(ArgumentOutOfRangeException), + "Expected: ArgumentException in net5 and earlier. ArgumentOutOfRangeException in net6 and later."); ex = Assert.ThrowsAny(() => stream.Read(buffer, int.MaxValue, int.MaxValue)); - Assert.Equal(typeof(ArgumentOutOfRangeException), ex.GetType()); + Assert.True(ex.GetType() == typeof(ArgumentException) || ex.GetType() == typeof(ArgumentOutOfRangeException), + "Expected: ArgumentException in net5 and earlier. ArgumentOutOfRangeException in net6 and later."); } // Once Reader is closed