Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 98 additions & 10 deletions build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,109 @@
</Target>

<!-- Tests -->

<!-- Run all unit tests applicable to the host OS. -->
<Target Name="RunTests" DependsOnTargets="RunFunctionalTests;RunManualTests"/>
<Target Name="RunFunctionalTests">
<!-- Windows -->
<Exec ConsoleToMsBuild="true" Command="$(DotnetPath)dotnet test &quot;@(FunctionalTestsProj)&quot; -p:Configuration=$(Configuration) -p:Target$(TFGroup)Version=$(TF) -p:ReferenceType=$(ReferenceType) --no-build -v n --collect &quot;Code coverage&quot; -p:TestSet=$(TestSet) --results-directory $(ResultsDirectory) -p:TestTargetOS=Windows$(TargetGroup) --filter &quot;category!=non$(TargetGroup)tests&amp;category!=failing&amp;category!=nonwindowstests&quot; &quot;--logger:trx;LogFilePrefix=Functional-Windows$(TargetGroup)-$(TestSet)&quot;" Condition="'$(IsEnabledWindows)' == 'true'"/>
<!-- Unix -->
<Exec ConsoleToMsBuild="true" Command="$(DotnetPath)dotnet test &quot;@(FunctionalTestsProj)&quot; -p:Configuration=$(Configuration) -p:TargetNetCoreVersion=$(TF) -p:ReferenceType=$(ReferenceType) --no-build -v n -p:TestSet=$(TestSet) --results-directory $(ResultsDirectory) -p:TestTargetOS=Unixnetcoreapp --collect &quot;Code coverage&quot; --filter &quot;category!=nonnetcoreapptests&amp;category!=failing&amp;category!=nonlinuxtests&amp;category!=nonuaptests&quot; &quot;--logger:trx;LogFilePrefix=Functional-Unixnetcoreapp-$(TestSet)&quot;" Condition="'$(IsEnabledWindows)' != 'true'"/>

<!-- Run all Functional tests applicable to the host OS. -->
<Target Name="RunFunctionalTests" DependsOnTargets="RunFunctionalTestsWindows;RunFunctionalTestsUnix"/>

<!-- Run all Functional tests applicable to Windows. -->
<Target Name="RunFunctionalTestsWindows" Condition="'$(IsEnabledWindows)' == 'true'">
<PropertyGroup>
<TestCommand>
$(DotnetPath)dotnet test "@(FunctionalTestsProj)"
Copy link
Contributor Author

@paulmedynski paulmedynski Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatted for readability, and then squished back into a single line since <Exec> treats each line in the Command as a separate command!

--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&amp;category!=failing&amp;category!=nonwindowstests"
--logger:"trx;LogFilePrefix=Functional-Windows$(TargetGroup)-$(TestSet)"
</TestCommand>
<TestCommand>$(TestCommand.Replace($([System.Environment]::NewLine), " "))</TestCommand>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modern dotnet tooling supports String.ReplaceLineEndings(), but we're using the old .NET Framework msbuild.exe tooling to build, so we can't have the nice toys :(

</PropertyGroup>
<Message Text=">>> Running Functional test for Windows via command: $(TestCommand)"/>
<Exec ConsoleToMsBuild="true" Command="$(TestCommand)"/>
</Target>

<!-- Run all Functional tests applicable to Unix. -->
<Target Name="RunFunctionalTestsUnix" Condition="'$(IsEnabledWindows)' != 'true'">
<PropertyGroup>
<TestCommand>
$(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&amp;category!=failing&amp;category!=nonlinuxtests&amp;category!=nonuaptests"
--logger:"trx;LogFilePrefix=Functional-Unixnetcoreapp-$(TestSet)"
</TestCommand>
<TestCommand>$(TestCommand.Replace($([System.Environment]::NewLine), " "))</TestCommand>
</PropertyGroup>
<Message Text=">>> Running Functional test for Unix via command: $(TestCommand)"/>
<Exec ConsoleToMsBuild="true" Command="$(TestCommand)"/>
</Target>

<!-- Run all Manual tests applicable to the host OS. -->
<Target Name="RunManualTests" DependsOnTargets="RunManualTestsWindows;RunManualTestsUnix"/>

<!-- Run all Manual tests applicable to Windows. -->
<Target Name="RunManualTestsWindows" Condition="'$(IsEnabledWindows)' == 'true'">
<PropertyGroup>
<TestCommand>
$(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&amp;category!=failing&amp;category!=nonwindowstests"
--logger:"trx;LogFilePrefix=Manual-Windows$(TargetGroup)-$(TestSet)"
</TestCommand>
<TestCommand>$(TestCommand.Replace($([System.Environment]::NewLine), " "))</TestCommand>
</PropertyGroup>
<Message Text=">>> Running Manual test for Windows via command: $(TestCommand)"/>
<Exec ConsoleToMsBuild="true" Command="$(TestCommand)"/>

Check failure on line 257 in build.proj

View check run for this annotation

Azure Pipelines / CI-SqlClient (Win22_Sql19 net8_0_AnyCPU_NativeSNI_3)

build.proj#L257

build.proj(257,5): Error MSB3073: The command " dotnet test "src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj" --no-build -v n -p:Configuration=Release -p:TargetnetcoreVersion=net8.0 -p:ReferenceType=Project -p:TestSet=3 -p:TestTargetOS=Windowsnetcoreapp --collect "Code coverage" --results-directory TestResults --filter "category!=nonnetcoreapptests&category!=failing&category!=nonwindowstests" --logger:"trx;LogFilePrefix=Manual-Windowsnetcoreapp-3" " exited with code 1.

Check failure on line 257 in build.proj

View check run for this annotation

Azure Pipelines / CI-SqlClient (Win22_Azure_Sql net8_0_AnyCPU_ManagedSNI_3)

build.proj#L257

build.proj(257,5): Error MSB3073: The command " dotnet test "src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj" --no-build -v n -p:Configuration=Release -p:TargetnetcoreVersion=net8.0 -p:ReferenceType=Project -p:TestSet=3 -p:TestTargetOS=Windowsnetcoreapp --collect "Code coverage" --results-directory TestResults --filter "category!=nonnetcoreapptests&category!=failing&category!=nonwindowstests" --logger:"trx;LogFilePrefix=Manual-Windowsnetcoreapp-3" " exited with code 1.

Check failure on line 257 in build.proj

View check run for this annotation

Azure Pipelines / CI-SqlClient (Win22_Azure_Sql net8_0_AnyCPU_NativeSNI_3)

build.proj#L257

build.proj(257,5): Error MSB3073: The command " dotnet test "src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj" --no-build -v n -p:Configuration=Release -p:TargetnetcoreVersion=net8.0 -p:ReferenceType=Project -p:TestSet=3 -p:TestTargetOS=Windowsnetcoreapp --collect "Code coverage" --results-directory TestResults --filter "category!=nonnetcoreapptests&category!=failing&category!=nonwindowstests" --logger:"trx;LogFilePrefix=Manual-Windowsnetcoreapp-3" " exited with code 1.

Check failure on line 257 in build.proj

View check run for this annotation

Azure Pipelines / CI-SqlClient-Package (Win22_Azure_ARM64_Sql net8_0_AnyCPU_ManagedSNI_1)

build.proj#L257

build.proj(257,5): Error MSB3073: The command " dotnet test "src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj" --no-build -v n -p:Configuration=Release -p:TargetnetcoreVersion=net8.0 -p:ReferenceType=Package -p:TestSet=1 -p:TestTargetOS=Windowsnetcoreapp --collect "Code coverage" --results-directory TestResults --filter "category!=nonnetcoreapptests&category!=failing&category!=nonwindowstests" --logger:"trx;LogFilePrefix=Manual-Windowsnetcoreapp-1" " exited with code 1.

Check failure on line 257 in build.proj

View check run for this annotation

Azure Pipelines / CI-SqlClient-Package (Win22_Sql22_x86 net462_AnyCPU_3)

build.proj#L257

build.proj(257,5): Error MSB3073: The command " C:\x86\dotnet test "src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj" --no-build -v n -p:Configuration=Release -p:TargetnetfxVersion=net462 -p:ReferenceType=Package -p:TestSet=3 -p:TestTargetOS=Windowsnetfx --collect "Code coverage" --results-directory TestResults --filter "category!=nonnetfxtests&category!=failing&category!=nonwindowstests" --logger:"trx;LogFilePrefix=Manual-Windowsnetfx-3" " exited with code 1.

Check failure on line 257 in build.proj

View check run for this annotation

Azure Pipelines / CI-SqlClient-Package (Win22_Azure_Sql net9_0_AnyCPU_ManagedSNI_3)

build.proj#L257

build.proj(257,5): Error MSB3073: The command " dotnet test "src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj" --no-build -v n -p:Configuration=Release -p:TargetnetcoreVersion=net9.0 -p:ReferenceType=Package -p:TestSet=3 -p:TestTargetOS=Windowsnetcoreapp --collect "Code coverage" --results-directory TestResults --filter "category!=nonnetcoreapptests&category!=failing&category!=nonwindowstests" --logger:"trx;LogFilePrefix=Manual-Windowsnetcoreapp-3" " exited with code 1.

Check failure on line 257 in build.proj

View check run for this annotation

Azure Pipelines / CI-SqlClient-Package (Win22_Azure_Sql net8_0_AnyCPU_ManagedSNI_3)

build.proj#L257

build.proj(257,5): Error MSB3073: The command " dotnet test "src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj" --no-build -v n -p:Configuration=Release -p:TargetnetcoreVersion=net8.0 -p:ReferenceType=Package -p:TestSet=3 -p:TestTargetOS=Windowsnetcoreapp --collect "Code coverage" --results-directory TestResults --filter "category!=nonnetcoreapptests&category!=failing&category!=nonwindowstests" --logger:"trx;LogFilePrefix=Manual-Windowsnetcoreapp-3" " exited with code 1.

Check failure on line 257 in build.proj

View check run for this annotation

Azure Pipelines / CI-SqlClient

build.proj#L257

build.proj(257,5): Error MSB3073: The command " dotnet test "src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlClient.ManualTesting.Tests.csproj" --no-build -v n -p:Configuration=Release -p:TargetnetcoreVersion=net8.0 -p:ReferenceType=Project -p:TestSet=3 -p:TestTargetOS=Windowsnetcoreapp --collect "Code coverage" --results-directory TestResults --filter "category!=nonnetcoreapptests&category!=failing&category!=nonwindowstests" --logger:"trx;LogFilePrefix=Manual-Windowsnetcoreapp-3" " exited with code 1.
</Target>

<Target Name="RunManualTests">
<!-- Windows -->
<Exec ConsoleToMsBuild="true" Command="$(DotnetPath)dotnet test &quot;@(ManualTestsProj)&quot; -p:Configuration=$(Configuration) -p:Target$(TFGroup)Version=$(TF) -p:ReferenceType=$(ReferenceType) --no-build -l &quot;console;verbosity=normal&quot; --collect &quot;Code coverage&quot; -p:TestSet=$(TestSet) --results-directory $(ResultsDirectory) -p:TestTargetOS=Windows$(TargetGroup) --filter &quot;category!=non$(TargetGroup)tests&amp;category!=failing&amp;category!=nonwindowstests&quot; &quot;--logger:trx;LogFilePrefix=Manual-Windows$(TargetGroup)-$(TestSet)&quot;" Condition="'$(IsEnabledWindows)' == 'true'"/>
<!-- Unix -->
<Exec ConsoleToMsBuild="true" Command="$(DotnetPath)dotnet test &quot;@(ManualTestsProj)&quot; -p:Configuration=$(Configuration) -p:TargetNetCoreVersion=$(TF) -p:ReferenceType=$(ReferenceType) --no-build -l &quot;console;verbosity=normal&quot; --collect &quot;Code coverage&quot; -p:TestSet=$(TestSet) --results-directory $(ResultsDirectory) -p:TestTargetOS=Unixnetcoreapp --filter &quot;category!=nonnetcoreapptests&amp;category!=failing&amp;category!=nonlinuxtests&amp;category!=nonuaptests&quot; &quot;--logger:trx;LogFilePrefix=Manual-Unixnetcoreapp-$(TestSet)&quot;" Condition="'$(IsEnabledWindows)' != 'true'"/>
<!-- Run all Manual tests applicable to Unix. -->
<Target Name="RunManualTestsUnix" Condition="'$(IsEnabledWindows)' != 'true'">
<PropertyGroup>
<TestCommand>
$(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&amp;category!=failing&amp;category!=nonlinuxtests&amp;category!=nonuaptests"
--logger:"trx;LogFilePrefix=Manual-Unixnetcoreapp-$(TestSet)"
</TestCommand>
<TestCommand>$(TestCommand.Replace($([System.Environment]::NewLine), " "))</TestCommand>
</PropertyGroup>
<Message Text=">>> Running Manual test for Unix via command: $(TestCommand)"/>
<Exec ConsoleToMsBuild="true" Command="$(TestCommand)"/>
</Target>

<!-- Clean -->
<Target Name="Clean">
<RemoveDir Directories='$([System.IO.Directory]::GetDirectories(".","artifacts", SearchOption.AllDirectories))' />
<RemoveDir Directories='$([System.IO.Directory]::GetDirectories(".","bin", SearchOption.AllDirectories))' />
Expand Down
2 changes: 1 addition & 1 deletion eng/pipelines/common/templates/steps/pre-build-step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ steps:
displayName: 'Start SQLBrowser'

- task: NuGetToolInstaller@1
displayName: 'Use NuGet '
displayName: 'Use NuGet'
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,16 @@ public void EncryptAndDecryptDataSuccessfully()
}

[Theory]
[CEKEncryptionReversalParameters]
[MemberData(
nameof(CEKEncryptionReversalData)
#if NETFRAMEWORK
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.NET doesn't have a GAC, so these tests will enumerate correctly for those targets. We only need to disable for .NET Framework targets.

// .NET Framework puts system enums in something called the Global
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left a comment once in each file where we're using DisableDiscoveryEnumeration, to make it clear why we're using that flag.

// 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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -505,33 +519,25 @@ public override IEnumerable<Object[]> GetData(MethodInfo testMethod)
}
}

public class CEKEncryptionReversalParameters : DataAttribute
public static IEnumerable<object[]> CEKEncryptionReversalData()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since xUnit only supports DisableDiscoveryEnumeration on MemberData attributes, I have converted all of the data sources to be compatible with MemberData.

You will see similar changes throughout the tests, where data source classes become methods.

{
public override IEnumerable<Object[]> 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<object[]> ValidCertificatePathsData()
{

public override IEnumerable<Object[]> 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 };
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Runtime.InteropServices;
using System.Threading;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary.

using System.Threading.Tasks;
using System.Transactions;
using Xunit;
Expand Down Expand Up @@ -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<string> connectAction, string connectionString)
{
Assert.Throws<SqlException>(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a custom serializer help in this case? Not to say we should do it in this PR, just curious if you experimented with it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes looked into that, but didn't want to figure out serialization for all of the affected tests as part of this PR. The changes here don't affect how the tests run, and they don't change how they're visualized in IDEs. They just suppress the warnings on the console. I've opened an ADO task to track fixing the serialization itself.

public void FactoryMethodTest(Func<object> factory, Type expectedType, bool singleton)
{
object value1 = factory();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Reflection;
using Xunit;
Expand Down Expand Up @@ -29,9 +30,26 @@ public void AppendCommandWithEmptyString_Throws()
VerifyException<InvalidOperationException>(ex, "CommandText property has not been initialized");
}

public static IEnumerable<object[]> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) };
Expand All @@ -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<SqlDataRecord, object> getXXX)
{
SqlMetaData[] metaData = new SqlMetaData[]
Expand All @@ -360,7 +369,10 @@ public void GetXXX_ThrowsIfBadType(Func<SqlDataRecord, object> getXXX)
}

[Theory]
[ClassData(typeof(GetXXXCheckValueTestData))]
[MemberData(
nameof(GetXXXCheckValueTestData.Get),
MemberType = typeof(GetXXXCheckValueTestData),
DisableDiscoveryEnumeration = true)]
public void GetXXX_ReturnValue(SqlDbType dbType, object value, Func<SqlDataRecord, object> getXXX)
{
SqlMetaData[] metaData = new SqlMetaData[]
Expand All @@ -374,9 +386,9 @@ public void GetXXX_ReturnValue(SqlDbType dbType, object value, Func<SqlDataRecor
}
}

public class GetXXXBadTypeTestData : IEnumerable<object[]>
public class GetXXXBadTypeTestData
{
public IEnumerator<object[]> GetEnumerator()
public static IEnumerable<object[]> Get()
{
yield return new object[] { new Func<SqlDataRecord, object>(r => r.GetGuid(0)) };
yield return new object[] { new Func<SqlDataRecord, object>(r => r.GetInt16(0)) };
Expand All @@ -389,31 +401,21 @@ public IEnumerator<object[]> GetEnumerator()
yield return new object[] { new Func<SqlDataRecord, object>(r => r.GetDateTimeOffset(0)) };
yield return new object[] { new Func<SqlDataRecord, object>(r => r.GetTimeSpan(0)) };
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}

public class GetUdtTypeTestData : IEnumerable<object[]>
public class GetUdtTypeTestData
{
public IEnumerator<object[]> GetEnumerator()
public static IEnumerable<object[]> 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<object[]>
public class GetXXXCheckValueTestData
{
public IEnumerator<object[]> GetEnumerator()
public static IEnumerable<object[]> Get()
{
yield return new object[] { SqlDbType.UniqueIdentifier, Guid.NewGuid(), new Func<SqlDataRecord, object>(r => r.GetGuid(0)) };
yield return new object[] { SqlDbType.SmallInt, (short)123, new Func<SqlDataRecord, object>(r => r.GetInt16(0)) };
Expand All @@ -430,11 +432,6 @@ public IEnumerator<object[]> GetEnumerator()
yield return new object[] { SqlDbType.SmallDateTime, DateTime.Now, new Func<SqlDataRecord, object>(r => r.GetDateTime(0)) };
yield return new object[] { SqlDbType.TinyInt, (byte)1, new Func<SqlDataRecord, object>(r => r.GetByte(0)) };
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
[SqlServer.Server.SqlUserDefinedType(SqlServer.Server.Format.UserDefined)]
public class TestUdt {}
Expand Down
Loading
Loading