diff --git a/build.proj b/build.proj index 95b7ac947d..c470970f03 100644 --- a/build.proj +++ b/build.proj @@ -178,21 +178,109 @@ + + - - - - - + + + + + + + + + $(DotnetPath)dotnet test "@(FunctionalTestsProj)" + --no-build + -v n + -p:Configuration=$(Configuration) + -p:Target$(TFGroup)Version=$(TF) + -p:ReferenceType=$(ReferenceType) + -p:TestSet=$(TestSet) + -p:TestTargetOS=Windows$(TargetGroup) + --collect "Code coverage" + --results-directory $(ResultsDirectory) + --filter "category!=non$(TargetGroup)tests&category!=failing&category!=nonwindowstests" + --logger:"trx;LogFilePrefix=Functional-Windows$(TargetGroup)-$(TestSet)" + + $(TestCommand.Replace($([System.Environment]::NewLine), " ")) + + + + + + + + + + $(DotnetPath)dotnet test "@(FunctionalTestsProj)" + --no-build + -v n + -p:Configuration=$(Configuration) + -p:TargetNetCoreVersion=$(TF) + -p:ReferenceType=$(ReferenceType) + -p:TestSet=$(TestSet) + -p:TestTargetOS=Unixnetcoreapp + --collect "Code coverage" + --results-directory $(ResultsDirectory) + --filter "category!=nonnetcoreapptests&category!=failing&category!=nonlinuxtests&category!=nonuaptests" + --logger:"trx;LogFilePrefix=Functional-Unixnetcoreapp-$(TestSet)" + + $(TestCommand.Replace($([System.Environment]::NewLine), " ")) + + + + + + + + + + + + + $(DotnetPath)dotnet test "@(ManualTestsProj)" + --no-build + -v n + -p:Configuration=$(Configuration) + -p:Target$(TFGroup)Version=$(TF) + -p:ReferenceType=$(ReferenceType) + -p:TestSet=$(TestSet) + -p:TestTargetOS=Windows$(TargetGroup) + --collect "Code coverage" + --results-directory $(ResultsDirectory) + --filter "category!=non$(TargetGroup)tests&category!=failing&category!=nonwindowstests" + --logger:"trx;LogFilePrefix=Manual-Windows$(TargetGroup)-$(TestSet)" + + $(TestCommand.Replace($([System.Environment]::NewLine), " ")) + + + - - - - - + + + + + $(DotnetPath)dotnet test "@(ManualTestsProj)" + --no-build + -v n + -p:Configuration=$(Configuration) + -p:TargetNetCoreVersion=$(TF) + -p:ReferenceType=$(ReferenceType) + -p:TestSet=$(TestSet) + -p:TestTargetOS=Unixnetcoreapp + --collect "Code coverage" + --results-directory $(ResultsDirectory) + --filter "category!=nonnetcoreapptests&category!=failing&category!=nonlinuxtests&category!=nonuaptests" + --logger:"trx;LogFilePrefix=Manual-Unixnetcoreapp-$(TestSet)" + + $(TestCommand.Replace($([System.Environment]::NewLine), " ")) + + + + diff --git a/eng/pipelines/common/templates/steps/pre-build-step.yml b/eng/pipelines/common/templates/steps/pre-build-step.yml index fed1a8d93e..626042670e 100644 --- a/eng/pipelines/common/templates/steps/pre-build-step.yml +++ b/eng/pipelines/common/templates/steps/pre-build-step.yml @@ -29,4 +29,4 @@ steps: displayName: 'Start SQLBrowser' - task: NuGetToolInstaller@1 - displayName: 'Use NuGet ' + displayName: 'Use NuGet' diff --git a/eng/pipelines/common/templates/steps/update-config-file-step.yml b/eng/pipelines/common/templates/steps/update-config-file-step.yml index 78a1cfebe3..f49e552323 100644 --- a/eng/pipelines/common/templates/steps/update-config-file-step.yml +++ b/eng/pipelines/common/templates/steps/update-config-file-step.yml @@ -126,7 +126,7 @@ parameters: steps: # All properties should be added here, and this template should be used for any manipulation of the config.json file. -- powershell: | +- pwsh: | $jdata = Get-Content -Raw "config.default.json" | ConvertFrom-Json foreach ($p in $jdata) { @@ -186,7 +186,7 @@ steps: displayName: 'Update config.json' - ${{ if eq(parameters.debug, true) }}: - - powershell: | + - pwsh: | $jdata = Get-Content -Raw "config.json" | ConvertFrom-Json foreach ($p in $jdata) { diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/SqlColumnEncryptionCertificateStoreProviderShould.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/SqlColumnEncryptionCertificateStoreProviderShould.cs index 3a220cd9c7..216afef784 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/SqlColumnEncryptionCertificateStoreProviderShould.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AlwaysEncryptedTests/SqlColumnEncryptionCertificateStoreProviderShould.cs @@ -230,7 +230,16 @@ public void EncryptAndDecryptDataSuccessfully() } [Theory] - [CEKEncryptionReversalParameters] + [MemberData( + nameof(CEKEncryptionReversalData) +#if NETFRAMEWORK + // .NET Framework puts system enums in something called the Global + // Assembly Cache (GAC), and xUnit refuses to serialize enums that + // live there. So for .NET Framework, we disable enumeration of the + // test data to avoid warnings on the console when running tests. + , DisableDiscoveryEnumeration = true +#endif + )] [PlatformSpecific(TestPlatforms.Windows)] public void TestCEKEncryptionReversal(StoreLocation certificateStoreLocation, String certificateStoreNameAndLocation) { @@ -381,8 +390,13 @@ public void TestCustomKeyProviderListSetter() } [Theory] + [MemberData( + nameof(ValidCertificatePathsData) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] [PlatformSpecific(TestPlatforms.Windows)] - [ValidCertificatePathsParameters] public void TestValidCertificatePaths(string certificateStoreNameAndLocation, object location) { StoreLocation certificateStoreLocation; @@ -505,33 +519,25 @@ public override IEnumerable GetData(MethodInfo testMethod) } } - public class CEKEncryptionReversalParameters : DataAttribute + public static IEnumerable CEKEncryptionReversalData() { - public override IEnumerable GetData(MethodInfo testMethod) + yield return new object[2] { StoreLocation.CurrentUser, CurrentUserMyPathPrefix }; + // use localmachine cert path only when current user is Admin. + if (ColumnEncryptionCertificateFixture.IsAdmin) { - yield return new object[2] { StoreLocation.CurrentUser, CurrentUserMyPathPrefix }; - // use localmachine cert path only when current user is Admin. - if (ColumnEncryptionCertificateFixture.IsAdmin) - { - yield return new object[2] { StoreLocation.LocalMachine, LocalMachineMyPathPrefix }; - } + yield return new object[2] { StoreLocation.LocalMachine, LocalMachineMyPathPrefix }; } } - - public class ValidCertificatePathsParameters : DataAttribute + public static IEnumerable ValidCertificatePathsData() { - - public override IEnumerable GetData(MethodInfo testMethod) + yield return new object[2] { CurrentUserMyPathPrefix, StoreLocation.CurrentUser }; + // use localmachine cert path (or an incomplete path, which defaults to localmachine) only when current user is Admin. + if (ColumnEncryptionCertificateFixture.IsAdmin) { - yield return new object[2] { CurrentUserMyPathPrefix, StoreLocation.CurrentUser }; - // use localmachine cert path (or an incomplete path, which defaults to localmachine) only when current user is Admin. - if (ColumnEncryptionCertificateFixture.IsAdmin) - { - yield return new object[2] { MyPathPrefix, StoreLocation.LocalMachine }; - yield return new object[2] { @"", StoreLocation.LocalMachine }; - yield return new object[2] { LocalMachineMyPathPrefix, StoreLocation.LocalMachine }; - } + yield return new object[2] { MyPathPrefix, StoreLocation.LocalMachine }; + yield return new object[2] { @"", StoreLocation.LocalMachine }; + yield return new object[2] { LocalMachineMyPathPrefix, StoreLocation.LocalMachine }; } } diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AmbientTransactionFailureTest.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AmbientTransactionFailureTest.cs index ed70dbd07d..b5069f6197 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AmbientTransactionFailureTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/AmbientTransactionFailureTest.cs @@ -4,6 +4,7 @@ using System; using System.Runtime.InteropServices; +using System.Threading; using System.Threading.Tasks; using System.Transactions; using Xunit; @@ -75,7 +76,12 @@ public class AmbientTransactionFailureTest }; [ConditionalTheory(nameof(s_isNotArmProcess))] // https://github.com/dotnet/corefx/issues/21598 - [MemberData(nameof(ExceptionTestDataForSqlException))] + [MemberData( + nameof(ExceptionTestDataForSqlException), + // xUnit can't consistently serialize the data for this test, so we + // disable enumeration of the test data to avoid warnings on the + // console. + DisableDiscoveryEnumeration = true)] public void TestSqlException(Action connectAction, string connectionString) { Assert.Throws(() => diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlClientFactoryTest.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlClientFactoryTest.cs index b88ae0a260..a4b6cb1579 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlClientFactoryTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlClientFactoryTest.cs @@ -31,7 +31,12 @@ public void InstanceTest() }; [Theory] - [MemberData(nameof(FactoryMethodTestData))] + [MemberData( + nameof(FactoryMethodTestData), + // xUnit can't consistently serialize the data for this test, so we + // disable enumeration of the test data to avoid warnings on the + // console. + DisableDiscoveryEnumeration = true)] public void FactoryMethodTest(Func factory, Type expectedType, bool singleton) { object value1 = factory(); diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlCommandSetTest.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlCommandSetTest.cs index 1428bcc3e8..7e8a3f0377 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlCommandSetTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlCommandSetTest.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Data; using System.Reflection; using Xunit; @@ -29,9 +30,26 @@ public void AppendCommandWithEmptyString_Throws() VerifyException(ex, "CommandText property has not been initialized"); } + public static IEnumerable CommandTypeData() + { + return new object[][] + { + new object[] { CommandType.TableDirect }, + new object[] { (CommandType)5 } + }; + } + [Theory] - [InlineData(CommandType.TableDirect)] - [InlineData((CommandType)5)] + [MemberData( + nameof(CommandTypeData) +#if NETFRAMEWORK + // .NET Framework puts system enums in something called the Global + // Assembly Cache (GAC), and xUnit refuses to serialize enums that + // live there. So for .NET Framework, we disable enumeration of the + // test data to avoid warnings on the console when running tests. + , DisableDiscoveryEnumeration = true +#endif + )] public void AppendBadCommandType_Throws(CommandType commandType) { var cmdSet = CreateInstance(); diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlDataRecordTest.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlDataRecordTest.cs index 445488a0a5..0576a64eba 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlDataRecordTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlDataRecordTest.cs @@ -333,7 +333,13 @@ public void GetChar_ThrowsNotSupported() } [Theory] - [ClassData(typeof(GetUdtTypeTestData))] + [MemberData( + nameof(GetUdtTypeTestData.Get), + MemberType = typeof(GetUdtTypeTestData), + // xUnit can't consistently serialize the data for this test, so we + // disable enumeration of the test data to avoid warnings on the + // console. + DisableDiscoveryEnumeration = true)] public void GetUdt_ReturnsValue(Type udtType, object value, string serverTypeName) { SqlMetaData[] metadata = new SqlMetaData[] { new SqlMetaData(nameof(udtType.Name), SqlDbType.Udt, udtType, serverTypeName) }; @@ -346,7 +352,10 @@ public void GetUdt_ReturnsValue(Type udtType, object value, string serverTypeNam } [Theory] - [ClassData(typeof(GetXXXBadTypeTestData))] + [MemberData( + nameof(GetXXXBadTypeTestData.Get), + MemberType = typeof(GetXXXBadTypeTestData), + DisableDiscoveryEnumeration = true)] public void GetXXX_ThrowsIfBadType(Func getXXX) { SqlMetaData[] metaData = new SqlMetaData[] @@ -360,7 +369,10 @@ public void GetXXX_ThrowsIfBadType(Func getXXX) } [Theory] - [ClassData(typeof(GetXXXCheckValueTestData))] + [MemberData( + nameof(GetXXXCheckValueTestData.Get), + MemberType = typeof(GetXXXCheckValueTestData), + DisableDiscoveryEnumeration = true)] public void GetXXX_ReturnValue(SqlDbType dbType, object value, Func getXXX) { SqlMetaData[] metaData = new SqlMetaData[] @@ -374,9 +386,9 @@ public void GetXXX_ReturnValue(SqlDbType dbType, object value, Func + public class GetXXXBadTypeTestData { - public IEnumerator GetEnumerator() + public static IEnumerable Get() { yield return new object[] { new Func(r => r.GetGuid(0)) }; yield return new object[] { new Func(r => r.GetInt16(0)) }; @@ -389,31 +401,21 @@ public IEnumerator GetEnumerator() yield return new object[] { new Func(r => r.GetDateTimeOffset(0)) }; yield return new object[] { new Func(r => r.GetTimeSpan(0)) }; } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } } - public class GetUdtTypeTestData : IEnumerable + public class GetUdtTypeTestData { - public IEnumerator GetEnumerator() + public static IEnumerable Get() { yield return new object[] { typeof(SqlGeography), SqlGeography.Point(43, -81, 4326), "Geography" }; yield return new object[] { typeof(SqlGeometry), SqlGeometry.Point(43, -81, 4326), "Geometry" }; yield return new object[] { typeof(SqlHierarchyId), SqlHierarchyId.Parse("/"), "HierarchyId" }; } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } } - public class GetXXXCheckValueTestData : IEnumerable + public class GetXXXCheckValueTestData { - public IEnumerator GetEnumerator() + public static IEnumerable Get() { yield return new object[] { SqlDbType.UniqueIdentifier, Guid.NewGuid(), new Func(r => r.GetGuid(0)) }; yield return new object[] { SqlDbType.SmallInt, (short)123, new Func(r => r.GetInt16(0)) }; @@ -430,11 +432,6 @@ public IEnumerator GetEnumerator() yield return new object[] { SqlDbType.SmallDateTime, DateTime.Now, new Func(r => r.GetDateTime(0)) }; yield return new object[] { SqlDbType.TinyInt, (byte)1, new Func(r => r.GetByte(0)) }; } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } } [SqlServer.Server.SqlUserDefinedType(SqlServer.Server.Format.UserDefined)] public class TestUdt {} diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlMetaDataTest.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlMetaDataTest.cs index dd6c228fd2..9678c3e0f3 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlMetaDataTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlMetaDataTest.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Collections.Generic; using System.Data; using System.Data.SqlTypes; using System.Globalization; @@ -15,7 +16,12 @@ namespace Microsoft.Data.SqlClient.Tests public class SqlMetaDataTest { [Theory] - [MemberData(nameof(SqlMetaDataAdjustValues))] + [MemberData( + nameof(SqlMetaDataAdjustValues), + // xUnit can't consistently serialize the data for this test, so we + // disable enumeration of the test data to avoid warnings on the + // console. + DisableDiscoveryEnumeration = true)] [MemberData(nameof(SqlMetaDataDateTimeValues))] public void Adjust(SqlDbType dbType, object expected) { @@ -37,7 +43,9 @@ public void Adjust(SqlDbType dbType, object expected) } [Theory] - [MemberData(nameof(SqlMetaDataMaxLengthTrimValues))] + [MemberData( + nameof(SqlMetaDataMaxLengthTrimValues), + DisableDiscoveryEnumeration = true)] public void AdjustWithGreaterThanMaxLengthValues(SqlDbType dbType, object value) { int maxLength = 4; @@ -59,7 +67,9 @@ public void AdjustWithGreaterThanMaxLengthValues(SqlDbType dbType, object value) } [Theory] - [MemberData(nameof(SqlMetaDataInvalidValues))] + [MemberData( + nameof(SqlMetaDataInvalidValues), + DisableDiscoveryEnumeration = true)] public void AdjustWithInvalidType_Throws(SqlDbType dbType, object expected) { SqlMetaData metaData = new SqlMetaData( @@ -229,11 +239,28 @@ public void ConstructorWithDefaultLocaleInvalidType_Throws() Assert.Contains("dbType", ex.Message, StringComparison.OrdinalIgnoreCase); } + public static IEnumerable ConstructorCharData() + { + return new object[][] + { + new object[] { SqlDbType.Char }, + new object[] { SqlDbType.VarChar }, + new object[] { SqlDbType.NChar }, + new object[] { SqlDbType.NVarChar } + }; + } + [Theory] - [InlineData(SqlDbType.Char)] - [InlineData(SqlDbType.VarChar)] - [InlineData(SqlDbType.NChar)] - [InlineData(SqlDbType.NVarChar)] + [MemberData( + nameof(ConstructorCharData) +#if NETFRAMEWORK + // .NET Framework puts system enums in something called the Global + // Assembly Cache (GAC), and xUnit refuses to serialize enums that + // live there. So for .NET Framework, we disable enumeration of the + // test data to avoid warnings on the console when running tests. + , DisableDiscoveryEnumeration = true +#endif + )] public void ConstructorWithMaxLengthAndDefaultLocale(SqlDbType dbType) { const int maxLength = 5; @@ -257,10 +284,12 @@ public void ConstructorWithMaxLengthAndDefaultLocaleInvalidType_Throws() } [Theory] - [InlineData(SqlDbType.Char)] - [InlineData(SqlDbType.VarChar)] - [InlineData(SqlDbType.NChar)] - [InlineData(SqlDbType.NVarChar)] + [MemberData( + nameof(ConstructorCharData) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public void ConstructorWithMaxLengthAndLocale(SqlDbType dbType) { long maxLength = 5L; @@ -286,9 +315,22 @@ public void ConstructorWithMaxLengthAndLocaleInvalidType_Throws() Assert.Contains("dbType", ex.Message, StringComparison.OrdinalIgnoreCase); } + public static IEnumerable ConstructorTextData() + { + return new object[][] + { + new object[] { SqlDbType.NText }, + new object[] { SqlDbType.Text } + }; + } + [Theory] - [InlineData(SqlDbType.NText)] - [InlineData(SqlDbType.Text)] + [MemberData( + nameof(ConstructorTextData) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public void ConstructorWithMaxLengthTextAndDefaultLocale(SqlDbType dbType) { long maxLength = SqlMetaData.Max; @@ -302,8 +344,12 @@ public void ConstructorWithMaxLengthTextAndDefaultLocale(SqlDbType dbType) } [Theory] - [InlineData(SqlDbType.NText)] - [InlineData(SqlDbType.Text)] + [MemberData( + nameof(ConstructorTextData) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public void ConstructorWithMaxLengthTextAndLocale(SqlDbType dbType) { long maxLength = SqlMetaData.Max; @@ -319,11 +365,18 @@ public void ConstructorWithMaxLengthTextAndLocale(SqlDbType dbType) } [Theory] - [InlineData(SqlDbType.Char)] - [InlineData(SqlDbType.VarChar)] - [InlineData(SqlDbType.NChar)] - [InlineData(SqlDbType.NVarChar)] - [InlineData(SqlDbType.NText)] + [MemberData( + nameof(ConstructorCharData) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] + [MemberData( + nameof(ConstructorTextData) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public void ConstructorWithInvalidMaxLengthAndLocale_Throws(SqlDbType dbType) { int invalidMaxLength = -2; @@ -348,15 +401,35 @@ public void ConstructorWithInvalidMaxLengthAndLocaleCompareOptionsBinarySortAndI Assert.Contains("invalid", ex.Message, StringComparison.OrdinalIgnoreCase); } + public static IEnumerable ConstructorBinaryData() + { + return new object[][] + { + new object[] { SqlDbType.Binary }, + new object[] { SqlDbType.VarBinary }, + new object[] { SqlDbType.Image } + }; + } + [Theory] - [InlineData(SqlDbType.Char)] - [InlineData(SqlDbType.VarChar)] - [InlineData(SqlDbType.NChar)] - [InlineData(SqlDbType.NVarChar)] - [InlineData(SqlDbType.NText)] - [InlineData(SqlDbType.Binary)] - [InlineData(SqlDbType.VarBinary)] - [InlineData(SqlDbType.Image)] + [MemberData( + nameof(ConstructorCharData) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] + [MemberData( + nameof(ConstructorTextData) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] + [MemberData( + nameof(ConstructorBinaryData) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public void ConstructorWithInvalidMaxLengthDefaultLocale_Throws(SqlDbType dbType) { int invalidMaxLength = -2; @@ -506,9 +579,22 @@ public void DecimalConstructorWithPrecisionOutofRange2_Throws() // Assert.Contains("scale", ex.Message, StringComparison.OrdinalIgnoreCase); //} + public static IEnumerable ConstructorGenericData() + { + return new object[][] + { + new object[] { SqlDbType.Variant, null }, + new object[] { SqlDbType.Udt, typeof(Address) } + }; + } + [Theory] - [InlineData(SqlDbType.Variant, null)] - [InlineData(SqlDbType.Udt, typeof(Address))] + [MemberData( + nameof(ConstructorGenericData) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public void GenericConstructorWithoutXmlSchema(SqlDbType dbType, Type udt) { if (udt != null) @@ -550,10 +636,23 @@ public void GetPartialLengthWithXmlSqlMetaDataType_Throws() Assert.Contains("metadata", ex.InnerException.Message, StringComparison.OrdinalIgnoreCase); } + public static IEnumerable GetPartialLengthData() + { + return new object[][] + { + new object[] { SqlDbType.NVarChar }, + new object[] { SqlDbType.VarChar }, + new object[] { SqlDbType.VarBinary } + }; + } + [Theory] - [InlineData(SqlDbType.NVarChar)] - [InlineData(SqlDbType.VarChar)] - [InlineData(SqlDbType.VarBinary)] + [MemberData( + nameof(GetPartialLengthData) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public void GetPartialLengthWithVarSqlMetaDataType(SqlDbType sqlDbType) { Type sqlMetaDataType = typeof(SqlMetaData); @@ -577,7 +676,9 @@ public void GetPartialLengthWithVarSqlMetaDataType(SqlDbType sqlDbType) } [Theory] - [MemberData(nameof(SqlMetaDataInferredValues))] + [MemberData( + nameof(SqlMetaDataInferredValues), + DisableDiscoveryEnumeration = true)] public void InferFromValue(SqlDbType expectedDbType, object value) { SqlMetaData metaData = SqlMetaData.InferFromValue(value, "col1"); @@ -672,10 +773,23 @@ public void StringConstructorWithLocaleCompareOption() Assert.Equal(1, metaData.SortOrdinal); } + public static IEnumerable ConstructorTimeData() + { + return new object[][] + { + new object[] { SqlDbType.Time }, + new object[] { SqlDbType.DateTime2 }, + new object[] { SqlDbType.DateTimeOffset } + }; + } + [Theory] - [InlineData(SqlDbType.Time)] - [InlineData(SqlDbType.DateTime2)] - [InlineData(SqlDbType.DateTimeOffset)] + [MemberData( + nameof(ConstructorTimeData) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public void TimeConstructorWithOutOfRange_Throws(SqlDbType dbType) { byte precision = 8; diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlParameterTest.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlParameterTest.cs index ad6b7ec259..94e285b596 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlParameterTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlParameterTest.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Data.SqlTypes; @@ -217,37 +218,54 @@ public void Constructor2_Name_Null() Assert.Equal(string.Empty, p.ParameterName); } + public static IEnumerable Constructor3Data() + { + return new object[][] + { + new object[]{ SqlDbType.BigInt, DbType.Int64 }, + new object[]{ SqlDbType.Binary, DbType.Binary }, + new object[]{ SqlDbType.Bit, DbType.Boolean }, + new object[]{ SqlDbType.Char, DbType.AnsiStringFixedLength }, + new object[]{ SqlDbType.Date, DbType.Date }, + new object[]{ SqlDbType.DateTime, DbType.DateTime }, + new object[]{ SqlDbType.DateTimeOffset, DbType.DateTimeOffset }, + new object[]{ SqlDbType.Decimal, DbType.Decimal }, + new object[]{ SqlDbType.Float, DbType.Double }, + new object[]{ SqlDbType.Image, DbType.Binary }, + new object[]{ SqlDbType.Int, DbType.Int32 }, + new object[]{ SqlDbType.Money, DbType.Currency }, + new object[]{ SqlDbType.NChar, DbType.StringFixedLength }, + new object[]{ SqlDbType.NText, DbType.String }, + new object[]{ SqlDbType.NVarChar, DbType.String }, + new object[]{ SqlDbType.Real, DbType.Single }, + new object[]{ SqlDbType.SmallDateTime, DbType.DateTime }, + new object[]{ SqlDbType.SmallInt, DbType.Int16 }, + new object[]{ SqlDbType.SmallMoney, DbType.Currency }, + new object[]{ SqlDbType.Structured, DbType.Object }, + new object[]{ SqlDbType.Text, DbType.AnsiString }, + new object[]{ SqlDbType.Time, DbType.Time }, + new object[]{ SqlDbType.Timestamp, DbType.Binary }, + new object[]{ SqlDbType.TinyInt, DbType.Byte }, + new object[]{ SqlDbType.Udt, DbType.Object }, + new object[]{ SqlDbType.UniqueIdentifier, DbType.Guid }, + new object[]{ SqlDbType.VarBinary, DbType.Binary }, + new object[]{ SqlDbType.VarChar, DbType.AnsiString }, + new object[]{ SqlDbType.Variant, DbType.Object }, + new object[]{ SqlDbType.Xml, DbType.Xml } + }; + } + [Theory] - [InlineData(SqlDbType.BigInt, DbType.Int64)] - [InlineData(SqlDbType.Binary, DbType.Binary)] - [InlineData(SqlDbType.Bit, DbType.Boolean)] - [InlineData(SqlDbType.Char, DbType.AnsiStringFixedLength)] - [InlineData(SqlDbType.Date, DbType.Date)] - [InlineData(SqlDbType.DateTime, DbType.DateTime)] - [InlineData(SqlDbType.DateTimeOffset, DbType.DateTimeOffset)] - [InlineData(SqlDbType.Decimal, DbType.Decimal)] - [InlineData(SqlDbType.Float, DbType.Double)] - [InlineData(SqlDbType.Image, DbType.Binary)] - [InlineData(SqlDbType.Int, DbType.Int32)] - [InlineData(SqlDbType.Money, DbType.Currency)] - [InlineData(SqlDbType.NChar, DbType.StringFixedLength)] - [InlineData(SqlDbType.NText, DbType.String)] - [InlineData(SqlDbType.NVarChar, DbType.String)] - [InlineData(SqlDbType.Real, DbType.Single)] - [InlineData(SqlDbType.SmallDateTime, DbType.DateTime)] - [InlineData(SqlDbType.SmallInt, DbType.Int16)] - [InlineData(SqlDbType.SmallMoney, DbType.Currency)] - [InlineData(SqlDbType.Structured, DbType.Object)] - [InlineData(SqlDbType.Text, DbType.AnsiString)] - [InlineData(SqlDbType.Time, DbType.Time)] - [InlineData(SqlDbType.Timestamp, DbType.Binary)] - [InlineData(SqlDbType.TinyInt, DbType.Byte)] - [InlineData(SqlDbType.Udt, DbType.Object)] - [InlineData(SqlDbType.UniqueIdentifier, DbType.Guid)] - [InlineData(SqlDbType.VarBinary, DbType.Binary)] - [InlineData(SqlDbType.VarChar, DbType.AnsiString)] - [InlineData(SqlDbType.Variant, DbType.Object)] - [InlineData(SqlDbType.Xml, DbType.Xml)] + [MemberData( + nameof(Constructor3Data) +#if NETFRAMEWORK + // .NET Framework puts system enums in something called the Global + // Assembly Cache (GAC), and xUnit refuses to serialize enums that + // live there. So for .NET Framework, we disable enumeration of the + // test data to avoid warnings on the console when running tests. + , DisableDiscoveryEnumeration = true +#endif + )] public void Constructor3_Types(SqlDbType sqlDbType, DbType dbType) { SqlParameter p = new SqlParameter("types", sqlDbType); @@ -287,11 +305,24 @@ public void Constructor5(string value, string expected) Assert.Equal(expected, p.SourceColumn); } + public static IEnumerable Constructor6Data() + { + return new object[][] + { + new object[]{ ParameterDirection.Input, true, 0, 0, "", "", DataRowVersion.Current }, + new object[]{ ParameterDirection.InputOutput, true, 0, 0, null, "", DataRowVersion.Default }, + new object[]{ ParameterDirection.Output, false, 0, 255, "Col", "Col", DataRowVersion.Original }, + new object[]{ ParameterDirection.ReturnValue, false, 99, 100, " Col ", " Col ", DataRowVersion.Proposed } + }; + } + [Theory] - [InlineData(ParameterDirection.Input, true, 0, 0, "", "", DataRowVersion.Current)] - [InlineData(ParameterDirection.InputOutput, true, 0, 0, null, "", DataRowVersion.Default)] - [InlineData(ParameterDirection.Output, false, 0, 255, "Col", "Col", DataRowVersion.Original)] - [InlineData(ParameterDirection.ReturnValue, false, 99, 100, " Col ", " Col ", DataRowVersion.Proposed)] + [MemberData( + nameof(Constructor6Data) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public void Constructor6(ParameterDirection parameterDirection, bool isNullable, byte precision, byte scale, string sourceColumn, string expectedSourceColumn, DataRowVersion dataRowVersion) { SqlParameter p = new SqlParameter("", SqlDbType.Bit, int.MaxValue, parameterDirection, isNullable, precision, scale, sourceColumn, dataRowVersion, null); @@ -304,11 +335,24 @@ public void Constructor6(ParameterDirection parameterDirection, bool isNullable, Assert.Equal(dataRowVersion, p.SourceVersion); } + public static IEnumerable Constructor7Data() + { + return new object[][] + { + new object[]{ ParameterDirection.Input, 0, 0, null, "", DataRowVersion.Current, false, null, "", null, "", null, "" }, + new object[]{ ParameterDirection.InputOutput, 255, 255, "", "", DataRowVersion.Default, true, "", "", "", "", "", "" }, + new object[]{ ParameterDirection.Output, 99, 100, "Source", "Source", DataRowVersion.Original, false, "aaa", "aaa", "bbb", "bbb", "ccc", "ccc" }, + new object[]{ ParameterDirection.ReturnValue, 100, 99, " Source ", " Source ", DataRowVersion.Proposed, true, " aaa ", " aaa ", " bbb ", " bbb ", " ccc ", " ccc " } + }; + } + [Theory] - [InlineData(ParameterDirection.Input, 0, 0, null, "", DataRowVersion.Current, false, null, "", null, "", null, "")] - [InlineData(ParameterDirection.InputOutput, 255, 255, "", "", DataRowVersion.Default, true, "", "", "", "", "", "")] - [InlineData(ParameterDirection.Output, 99, 100, "Source", "Source", DataRowVersion.Original, false, "aaa", "aaa", "bbb", "bbb", "ccc", "ccc")] - [InlineData(ParameterDirection.ReturnValue, 100, 99, " Source ", " Source ", DataRowVersion.Proposed, true, " aaa ", " aaa ", " bbb ", " bbb ", " ccc ", " ccc ")] + [MemberData( + nameof(Constructor7Data) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public void Constructor7(ParameterDirection parameterDirection, byte precision, byte scale, string sourceColumn, string expectedSourceColumn, DataRowVersion dataRowVersion, bool sourceColumnNullMapping, string xmlSchemaCollectionDatabase, string expectedXmlSchemaCollectionDatabase, string xmlSchemaCollectionOwningSchema, string expectedXmlSchemaCollectionOwningSchema, string xmlSchemaCollectionName, string expectedXmlSchemaCollectionName) { SqlParameter p = new SqlParameter("", SqlDbType.Bit, int.MaxValue, parameterDirection, precision, scale, sourceColumn, dataRowVersion, sourceColumnNullMapping, null, xmlSchemaCollectionDatabase, xmlSchemaCollectionOwningSchema, xmlSchemaCollectionName); @@ -1010,28 +1054,41 @@ public void ResetDbType() Assert.Null(p.Value); } + public static IEnumerable ParameterSupportedData() + { + return new object[][] + { + new object[]{ DbType.AnsiString, SqlDbType.VarChar }, + new object[]{ DbType.AnsiStringFixedLength, SqlDbType.Char }, + new object[]{ DbType.Binary, SqlDbType.VarBinary }, + new object[]{ DbType.Boolean, SqlDbType.Bit }, + new object[]{ DbType.Byte, SqlDbType.TinyInt }, + new object[]{ DbType.Currency, SqlDbType.Money }, + new object[]{ DbType.Date, SqlDbType.Date }, + new object[]{ DbType.DateTime, SqlDbType.DateTime }, + new object[]{ DbType.DateTime2, SqlDbType.DateTime2 }, + new object[]{ DbType.DateTimeOffset, SqlDbType.DateTimeOffset }, + new object[]{ DbType.Decimal, SqlDbType.Decimal }, + new object[]{ DbType.Double, SqlDbType.Float }, + new object[]{ DbType.Guid, SqlDbType.UniqueIdentifier }, + new object[]{ DbType.Int16, SqlDbType.SmallInt }, + new object[]{ DbType.Int32, SqlDbType.Int }, + new object[]{ DbType.Int64, SqlDbType.BigInt }, + new object[]{ DbType.Object, SqlDbType.Variant }, + new object[]{ DbType.Single, SqlDbType.Real }, + new object[]{ DbType.String, SqlDbType.NVarChar }, + new object[]{ DbType.Time, SqlDbType.Time }, + new object[]{ DbType.Xml, SqlDbType.Xml } + }; + } + [Theory] - [InlineData(DbType.AnsiString, SqlDbType.VarChar)] - [InlineData(DbType.AnsiStringFixedLength, SqlDbType.Char)] - [InlineData(DbType.Binary, SqlDbType.VarBinary)] - [InlineData(DbType.Boolean, SqlDbType.Bit)] - [InlineData(DbType.Byte, SqlDbType.TinyInt)] - [InlineData(DbType.Currency, SqlDbType.Money)] - [InlineData(DbType.Date, SqlDbType.Date)] - [InlineData(DbType.DateTime, SqlDbType.DateTime)] - [InlineData(DbType.DateTime2, SqlDbType.DateTime2)] - [InlineData(DbType.DateTimeOffset, SqlDbType.DateTimeOffset)] - [InlineData(DbType.Decimal, SqlDbType.Decimal)] - [InlineData(DbType.Double, SqlDbType.Float)] - [InlineData(DbType.Guid, SqlDbType.UniqueIdentifier)] - [InlineData(DbType.Int16, SqlDbType.SmallInt)] - [InlineData(DbType.Int32, SqlDbType.Int)] - [InlineData(DbType.Int64, SqlDbType.BigInt)] - [InlineData(DbType.Object, SqlDbType.Variant)] - [InlineData(DbType.Single, SqlDbType.Real)] - [InlineData(DbType.String, SqlDbType.NVarChar)] - [InlineData(DbType.Time, SqlDbType.Time)] - [InlineData(DbType.Xml, SqlDbType.Xml)] + [MemberData( + nameof(ParameterSupportedData) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public void Parameter_Supported(DbType dbType, SqlDbType sqlDbType) { var parameter = new SqlParameter(); @@ -1040,12 +1097,25 @@ public void Parameter_Supported(DbType dbType, SqlDbType sqlDbType) Assert.Equal(sqlDbType, parameter.SqlDbType); } + public static IEnumerable ParameterNotSupportedData() + { + return new object[][] + { + new object[]{ DbType.SByte }, + new object[]{ DbType.UInt16 }, + new object[]{ DbType.UInt32 }, + new object[]{ DbType.UInt64 }, + new object[]{ DbType.VarNumeric } + }; + } + [Theory] - [InlineData(DbType.SByte)] - [InlineData(DbType.UInt16)] - [InlineData(DbType.UInt32)] - [InlineData(DbType.UInt64)] - [InlineData(DbType.VarNumeric)] + [MemberData( + nameof(ParameterNotSupportedData) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public void Parameter_NotSupported(DbType dbType) { var parameter = new SqlParameter(); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/ApiShould.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/ApiShould.cs index fc65ecabf5..184b5465ec 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/ApiShould.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/ApiShould.cs @@ -425,7 +425,17 @@ public void TestSqlDataAdapterFillDataTable(string connection) } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))] - [ClassData(typeof(AEConnectionStringProviderWithSchemaType))] + [MemberData( + nameof(DataHelpers.AEConnectionStringProviderWithSchemaType), + MemberType = typeof(DataHelpers) +#if NETFRAMEWORK + // .NET Framework puts system enums in something called the Global + // Assembly Cache (GAC), and xUnit refuses to serialize enums that + // live there. So for .NET Framework, we disable enumeration of the + // test data to avoid warnings on the console when running tests. + , DisableDiscoveryEnumeration = true +#endif + )] public void TestSqlDataAdapterFillSchema(string connection, SchemaType schemaType) { CleanUpTable(connection, _tableName); @@ -744,7 +754,13 @@ public async Task TestExecuteReaderAsyncWithLargeQuery(string connectionString) } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))] - [ClassData(typeof(AEConnectionStringProviderWithCommandBehaviorSet1))] + [MemberData( + nameof(DataHelpers.AEConnectionStringProviderWithCommandBehaviorSet1), + MemberType = typeof(DataHelpers) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public void TestExecuteReaderWithCommandBehavior(string connection, CommandBehavior commandBehavior) { string[] columnNames = new string[3] { "CustomerId", "FirstName", "LastName" }; @@ -1141,7 +1157,13 @@ public void TestPrepareWithExecuteNonQueryAsync(string connection) } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))] - [ClassData(typeof(AEConnectionStringProviderWithCommandBehaviorSet2))] + [MemberData( + nameof(DataHelpers.AEConnectionStringProviderWithCommandBehaviorSet2), + MemberType = typeof(DataHelpers) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public void TestPrepareWithExecuteReaderAsync(string connection, CommandBehavior commandBehavior) { CleanUpTable(connection, _tableName); @@ -1828,7 +1850,13 @@ public void TestSqlDataReaderAPIsWithSequentialAccess(string connection) } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))] - [ClassData(typeof(AEConnectionStringProviderWithCommandBehaviorSet2))] + [MemberData( + nameof(DataHelpers.AEConnectionStringProviderWithCommandBehaviorSet2), + MemberType = typeof(DataHelpers) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public void TestSqlCommandSequentialAccessCodePaths(string connection, CommandBehavior value) { CleanUpTable(connection, _tableName); @@ -1913,7 +1941,13 @@ public void TestExecuteXmlReader(string connection) [ActiveIssue("10620")] // Randomly hangs the process. [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))] - [ClassData(typeof(AEConnectionStringProviderWithCommandBehaviorSet1))] + [MemberData( + nameof(DataHelpers.AEConnectionStringProviderWithCommandBehaviorSet1), + MemberType = typeof(DataHelpers) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public void TestBeginAndEndExecuteReaderWithAsyncCallback(string connection, CommandBehavior commandbehavior) { CleanUpTable(connection, _tableName); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/ConversionTests.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/ConversionTests.cs index 94f137dbe9..d5c2ade38b 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/ConversionTests.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/ConversionTests.cs @@ -82,7 +82,16 @@ public ConversionTests() } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))] - [ClassData(typeof(ConversionSmallerToLargerInsertAndSelectData))] + [MemberData( + nameof(ConversionSmallerToLargerInsertAndSelectData) +#if NETFRAMEWORK + // .NET Framework puts system enums in something called the Global + // Assembly Cache (GAC), and xUnit refuses to serialize enums that + // live there. So for .NET Framework, we disable enumeration of the + // test data to avoid warnings on the console when running tests. + , DisableDiscoveryEnumeration = true +#endif + )] public void ConversionSmallerToLargerInsertAndSelect(string connString, SqlDbType smallDbType, SqlDbType largeDbType) { ColumnMetaData largeColumnInfo = new ColumnMetaData(largeDbType, 0, 1, 1, false); @@ -162,7 +171,12 @@ public void ConversionSmallerToLargerInsertAndSelect(string connString, SqlDbTyp } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))] - [ClassData(typeof(ConversionSmallerToLargerInsertAndSelectBulkData))] + [MemberData( + nameof(ConversionSmallerToLargerInsertAndSelectBulkData) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public void ConversionSmallerToLargerInsertAndSelectBulk(string connString, SqlDbType smallDbType, SqlDbType largeDbType) { ColumnMetaData largeColumnInfo = new ColumnMetaData(largeDbType, 0, 1, 1, false); @@ -251,7 +265,12 @@ smallColumnInfo.ColumnType is SqlDbType.Char || } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))] - [ClassData(typeof(TestOutOfRangeValuesData))] + [MemberData( + nameof(TestOutOfRangeValuesData) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public void TestOutOfRangeValues(string connString, SqlDbType currentDbType) { ColumnMetaData currentColumnInfo = new ColumnMetaData(currentDbType, 0, 1, 1, false); @@ -565,7 +584,20 @@ private void ExecuteAndCheckForError(SqlCommand sqlCmd, bool expectError) try { sqlCmd.ExecuteNonQuery(); - Assert.Fail("We should have gotten an error but passed instead."); + StringBuilder builder = new( + "We should have gotten an error but passed instead; " + + $"command: {sqlCmd.CommandText}; parameters: "); + foreach (SqlParameter param in sqlCmd.Parameters) + { + builder.Append('('); + builder.Append(param.ParameterName); + builder.Append(' '); + builder.Append(param.SqlDbType); + builder.Append(' '); + builder.Append(param.Value); + builder.Append(") "); + } + Assert.Fail(builder.ToString()); } catch (Exception e) { @@ -1336,11 +1368,8 @@ public void Dispose() } } } - } - public class ConversionSmallerToLargerInsertAndSelectData : IEnumerable - { - public IEnumerator GetEnumerator() + public static IEnumerable ConversionSmallerToLargerInsertAndSelectData() { foreach (string connStrAE in DataTestUtility.AEConnStrings) { @@ -1374,12 +1403,8 @@ public IEnumerator GetEnumerator() yield return new object[] { connStrAE, SqlDbType.Real, SqlDbType.Real }; } } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - } - public class ConversionSmallerToLargerInsertAndSelectBulkData : IEnumerable - { - public IEnumerator GetEnumerator() + public static IEnumerable ConversionSmallerToLargerInsertAndSelectBulkData() { foreach (string connStrAE in DataTestUtility.AEConnStrings) { @@ -1414,13 +1439,7 @@ public IEnumerator GetEnumerator() } } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - } - - - public class TestOutOfRangeValuesData : IEnumerable - { - public IEnumerator GetEnumerator() + public static IEnumerable TestOutOfRangeValuesData() { foreach (string connStrAE in DataTestUtility.AEConnStrings) { @@ -1449,7 +1468,5 @@ public IEnumerator GetEnumerator() yield return new object[] { connStrAE, SqlDbType.VarChar }; } } - - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } } diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/DatabaseHelper.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/DatabaseHelper.cs index 63cfdab974..33d548cd85 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/DatabaseHelper.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/DatabaseHelper.cs @@ -213,68 +213,59 @@ internal static byte[] GenerateRandomBytes(int length) internal static string GenerateUniqueName(string baseName) => string.Concat("AE_", baseName, "_", Guid.NewGuid().ToString().Replace('-', '_')); } - public class AEConnectionStringProviderWithBooleanVariable : IEnumerable + public static class DataHelpers { - public IEnumerator GetEnumerator() + public static IEnumerable AEConnectionStringProviderWithSchemaType() { foreach (string connStrAE in DataTestUtility.AEConnStrings) { - yield return new object[] { connStrAE, true }; - yield return new object[] { connStrAE, false }; + yield return new object[] { connStrAE, SchemaType.Source }; + yield return new object[] { connStrAE, SchemaType.Mapped }; } } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - } - - public class AEConnectionStringProvider : IEnumerable - { - public IEnumerator GetEnumerator() + public static IEnumerable AEConnectionStringProviderWithCommandBehaviorSet1() { foreach (string connStrAE in DataTestUtility.AEConnStrings) { - yield return new object[] { connStrAE }; + yield return new object[] { connStrAE, CommandBehavior.SingleResult }; + yield return new object[] { connStrAE, CommandBehavior.SingleRow }; + yield return new object[] { connStrAE, CommandBehavior.CloseConnection }; + yield return new object[] { connStrAE, CommandBehavior.SequentialAccess }; } } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - } - public class AEConnectionStringProviderWithCommandBehaviorSet1 : IEnumerable - { - public IEnumerator GetEnumerator() + public static IEnumerable AEConnectionStringProviderWithCommandBehaviorSet2() { foreach (string connStrAE in DataTestUtility.AEConnStrings) { - yield return new object[] { connStrAE, CommandBehavior.SingleResult }; - yield return new object[] { connStrAE, CommandBehavior.SingleRow }; - yield return new object[] { connStrAE, CommandBehavior.CloseConnection }; + yield return new object[] { connStrAE, CommandBehavior.Default }; yield return new object[] { connStrAE, CommandBehavior.SequentialAccess }; } } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } - public class AEConnectionStringProviderWithCommandBehaviorSet2 : IEnumerable + public class AEConnectionStringProviderWithBooleanVariable : IEnumerable { public IEnumerator GetEnumerator() { foreach (string connStrAE in DataTestUtility.AEConnStrings) { - yield return new object[] { connStrAE, CommandBehavior.Default }; - yield return new object[] { connStrAE, CommandBehavior.SequentialAccess }; + yield return new object[] { connStrAE, true }; + yield return new object[] { connStrAE, false }; } } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } - public class AEConnectionStringProviderWithSchemaType : IEnumerable + public class AEConnectionStringProvider : IEnumerable { public IEnumerator GetEnumerator() { foreach (string connStrAE in DataTestUtility.AEConnStrings) { - yield return new object[] { connStrAE, SchemaType.Source }; - yield return new object[] { connStrAE, SchemaType.Mapped }; + yield return new object[] { connStrAE }; } } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionTestWithSSLCert/CertificateTestWithTdsServer.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionTestWithSSLCert/CertificateTestWithTdsServer.cs index 385390c188..51d04ad848 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionTestWithSSLCert/CertificateTestWithTdsServer.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionTestWithSSLCert/CertificateTestWithTdsServer.cs @@ -92,7 +92,13 @@ private static string ForceEncryptionRegistryPath } [ConditionalTheory(nameof(AreConnStringsSetup), nameof(IsNotAzureServer), nameof(IsLocalHost))] - [MemberData(nameof(ConnectionTestParametersData.GetConnectionTestParameters), MemberType = typeof(ConnectionTestParametersData))] + [MemberData( + nameof(ConnectionTestParametersData.GetConnectionTestParameters), + MemberType = typeof(ConnectionTestParametersData), + // xUnit can't consistently serialize the data for this test, so we + // disable enumeration of the test data to avoid warnings on the + // console. + DisableDiscoveryEnumeration = true)] [PlatformSpecific(TestPlatforms.Windows)] public void BeginWindowsConnectionTest(ConnectionTestParameters connectionTestParameters) { @@ -105,7 +111,10 @@ public void BeginWindowsConnectionTest(ConnectionTestParameters connectionTestPa } [ConditionalTheory(nameof(AreConnStringsSetup), nameof(IsNotAzureServer), nameof(IsLocalHost))] - [MemberData(nameof(ConnectionTestParametersData.GetConnectionTestParameters), MemberType = typeof(ConnectionTestParametersData))] + [MemberData( + nameof(ConnectionTestParametersData.GetConnectionTestParameters), + MemberType = typeof(ConnectionTestParametersData), + DisableDiscoveryEnumeration = true)] [PlatformSpecific(TestPlatforms.Linux)] public void BeginLinuxConnectionTest(ConnectionTestParameters connectionTestParameters) { diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataReaderTest/DataReaderStreamsTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataReaderTest/DataReaderStreamsTest.cs index a180c21b3b..cd516df696 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataReaderTest/DataReaderStreamsTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataReaderTest/DataReaderStreamsTest.cs @@ -17,7 +17,16 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests public static class DataReaderStreamsTest { [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] - [MemberData(nameof(GetCommandBehavioursAndIsAsync))] + [MemberData( + nameof(GetCommandBehavioursAndIsAsync) +#if NETFRAMEWORK + // .NET Framework puts system enums in something called the Global + // Assembly Cache (GAC), and xUnit refuses to serialize enums that + // live there. So for .NET Framework, we disable enumeration of the + // test data to avoid warnings on the console when running tests. + , DisableDiscoveryEnumeration = true +#endif + )] public static async Task GetFieldValueAsync_OfStream(CommandBehavior behavior, bool isExecuteAsync) { const int PacketSize = 512; // force minimun packet size so that the test data spans multiple packets to test sequential access spanning @@ -53,7 +62,12 @@ public static async Task GetFieldValueAsync_OfStream(CommandBehavior behavior, b } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))] - [MemberData(nameof(GetCommandBehavioursAndIsAsync))] + [MemberData( + nameof(GetCommandBehavioursAndIsAsync) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public static async Task GetFieldValueAsync_OfXmlReader(CommandBehavior behavior, bool isExecuteAsync) { const int PacketSize = 512; // force minimun packet size so that the test data spans multiple packets to test sequential access spanning @@ -87,7 +101,12 @@ public static async Task GetFieldValueAsync_OfXmlReader(CommandBehavior behavior } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] - [MemberData(nameof(GetCommandBehavioursAndIsAsync))] + [MemberData( + nameof(GetCommandBehavioursAndIsAsync) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public static async Task GetFieldValueAsync_OfTextReader(CommandBehavior behavior, bool isExecuteAsync) { const int PacketSize = 512; // force minimun packet size so that the test data spans multiple packets to test sequential access spanning @@ -121,7 +140,12 @@ public static async Task GetFieldValueAsync_OfTextReader(CommandBehavior behavio } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] - [MemberData(nameof(GetCommandBehavioursAndIsAsync))] + [MemberData( + nameof(GetCommandBehavioursAndIsAsync) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public static async Task GetFieldValueAsync_Char_OfTextReader(CommandBehavior behavior, bool isExecuteAsync) { const int PacketSize = 512; // force minimun packet size so that the test data spans multiple packets to test sequential access spanning @@ -156,7 +180,12 @@ public static async Task GetFieldValueAsync_Char_OfTextReader(CommandBehavior be // Synapse: Cannot find data type 'XML'. [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))] - [MemberData(nameof(GetCommandBehavioursAndIsAsync))] + [MemberData( + nameof(GetCommandBehavioursAndIsAsync) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public static async Task GetFieldValue_OfXmlReader(CommandBehavior behavior, bool isExecuteAsync) { const int PacketSize = 512; // force minimun packet size so that the test data spans multiple packets to test sequential access spanning @@ -190,7 +219,12 @@ public static async Task GetFieldValue_OfXmlReader(CommandBehavior behavior, boo } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] - [MemberData(nameof(GetCommandBehavioursAndIsAsync))] + [MemberData( + nameof(GetCommandBehavioursAndIsAsync) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public static async Task GetFieldValue_OfStream(CommandBehavior behavior, bool isExecuteAsync) { const int PacketSize = 512; // force minimun packet size so that the test data spans multiple packets to test sequential access spanning @@ -223,7 +257,12 @@ public static async Task GetFieldValue_OfStream(CommandBehavior behavior, bool i } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))] - [MemberData(nameof(GetCommandBehavioursAndIsAsync))] + [MemberData( + nameof(GetCommandBehavioursAndIsAsync) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public static async Task GetFieldValue_OfTextReader(CommandBehavior behavior, bool isExecuteAsync) { const int PacketSize = 512; // force minimun packet size so that the test data spans multiple packets to test sequential access spanning @@ -257,7 +296,12 @@ public static async Task GetFieldValue_OfTextReader(CommandBehavior behavior, bo } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] - [MemberData(nameof(GetCommandBehavioursAndIsAsync))] + [MemberData( + nameof(GetCommandBehavioursAndIsAsync) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public static async Task GetStream(CommandBehavior behavior, bool isExecuteAsync) { const int PacketSize = 512; // force minimun packet size so that the test data spans multiple packets to test sequential access spanning @@ -293,7 +337,12 @@ public static async Task GetStream(CommandBehavior behavior, bool isExecuteAsync } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))] - [MemberData(nameof(GetCommandBehavioursAndIsAsync))] + [MemberData( + nameof(GetCommandBehavioursAndIsAsync) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public static async Task GetXmlReader(CommandBehavior behavior, bool isExecuteAsync) { const int PacketSize = 512; // force minimun packet size so that the test data spans multiple packets to test sequential access spanning @@ -327,7 +376,12 @@ public static async Task GetXmlReader(CommandBehavior behavior, bool isExecuteAs } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] - [MemberData(nameof(GetCommandBehavioursAndIsAsync))] + [MemberData( + nameof(GetCommandBehavioursAndIsAsync) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public static async Task GetTextReader(CommandBehavior behavior, bool isExecuteAsync) { const int PacketSize = 512; // force minimun packet size so that the test data spans multiple packets to test sequential access spanning @@ -361,7 +415,12 @@ public static async Task GetTextReader(CommandBehavior behavior, bool isExecuteA } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))] - [MemberData(nameof(GetCommandBehaviourAndAccessorTypes))] + [MemberData( + nameof(GetCommandBehaviourAndAccessorTypes) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public static void NullStreamProperties(CommandBehavior behavior, AccessorType accessorType) { string query = "SELECT convert(xml,NULL) AS XmlData, convert(nvarchar(max),NULL) as TextData, convert(varbinary(max),NULL) as StreamData"; @@ -446,7 +505,12 @@ public static void NullStreamProperties(CommandBehavior behavior, AccessorType a } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))] - [MemberData(nameof(GetCommandBehaviourAndAccessorTypes))] + [MemberData( + nameof(GetCommandBehaviourAndAccessorTypes) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public static void InvalidCastExceptionStream(CommandBehavior behavior, AccessorType accessorType) { string query = "SELECT convert(xml,NULL) AS XmlData, convert(nvarchar(max),NULL) as TextData"; diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.cs index 816537cb8f..c92ba237b4 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.cs @@ -11,18 +11,6 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests.SQL.JsonTest { - public class JsonBulkCopyTestData : IEnumerable - { - public IEnumerator GetEnumerator() - { - yield return new object[] { CommandBehavior.Default, false, 300, 100 }; - yield return new object[] { CommandBehavior.Default, true, 300, 100 }; - yield return new object[] { CommandBehavior.SequentialAccess, false, 300, 100 }; - yield return new object[] { CommandBehavior.SequentialAccess, true, 300, 100 }; - } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - } - public class JsonBulkCopyTest { private readonly ITestOutputHelper _output; @@ -36,6 +24,14 @@ public JsonBulkCopyTest(ITestOutputHelper output) _output = output; } + public static IEnumerable JsonBulkCopyTestData() + { + yield return new object[] { CommandBehavior.Default, false, 300, 100 }; + yield return new object[] { CommandBehavior.Default, true, 300, 100 }; + yield return new object[] { CommandBehavior.SequentialAccess, false, 300, 100 }; + yield return new object[] { CommandBehavior.SequentialAccess, true, 300, 100 }; + } + private void PopulateData(int noOfRecords, int rows) { using (SqlConnection connection = new SqlConnection(DataTestUtility.TCPConnectionString)) @@ -270,7 +266,16 @@ private async Task BulkCopyDataAsync(CommandBehavior cb, bool enableStraming, in } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] - [ClassData(typeof(JsonBulkCopyTestData))] + [MemberData( + nameof(JsonBulkCopyTestData) +#if NETFRAMEWORK + // .NET Framework puts system enums in something called the Global + // Assembly Cache (GAC), and xUnit refuses to serialize enums that + // live there. So for .NET Framework, we disable enumeration of the + // test data to avoid warnings on the console when running tests. + , DisableDiscoveryEnumeration = true +#endif + )] public void TestJsonBulkCopy(CommandBehavior cb, bool enableStraming, int jsonArrayElements, int rows) { PopulateData(jsonArrayElements, rows); @@ -285,7 +290,12 @@ public void TestJsonBulkCopy(CommandBehavior cb, bool enableStraming, int jsonAr } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] - [ClassData(typeof(JsonBulkCopyTestData))] + [MemberData( + nameof(JsonBulkCopyTestData) +#if NETFRAMEWORK + , DisableDiscoveryEnumeration = true +#endif + )] public async Task TestJsonBulkCopyAsync(CommandBehavior cb, bool enableStraming, int jsonArrayElements, int rows) { PopulateData(jsonArrayElements, rows); diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json index d159b7628d..a5f6cd996e 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json @@ -1,6 +1,13 @@ { + // Typical Windows SQL Server on the local host via TCP. "TCPConnectionString": "Data Source=tcp:localhost;Database=Northwind;Integrated Security=true;Encrypt=false;", + + // Typical Linux SQL Server on the local host, WSL, or a container, via TCP. + // "TCPConnectionString": "Data Source=tcp:127.0.0.1;User Id=sa;Password=;Database=Northwind;Encrypt=false;TrustServerCertificate=true", + + // Typical Windows SQL Server on the local host via Named Pipes. "NPConnectionString": "Data Source=np:localhost;Database=Northwind;Integrated Security=true;Encrypt=false;", + "TCPConnectionStringHGSVBS": "", "TCPConnectionStringNoneVBS": "", "TCPConnectionStringAASSGX": "", @@ -28,5 +35,6 @@ "ManagedIdentitySupported": true, "UserManagedIdentityClientId": "", "PowerShellPath": "", - "AliasName": "" + "AliasName": "", + "IsJsonSupported": false }