Skip to content

Commit 57d287c

Browse files
author
Javad
authored
Test | Removing internal build of XunitExtensions and using the nuget (#2033)
1 parent 97863e5 commit 57d287c

File tree

88 files changed

+230
-1505
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+230
-1505
lines changed

.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,7 @@ dotnet_code_quality.ca1802.api_surface = private, internal
169169

170170
[*.cs]
171171
dotnet_code_quality.CA2100.excluded_type_names_with_derived_types = Microsoft.Data.SqlClient.ManualTesting.Tests.*
172+
dotnet_diagnostic.xUnit1031.severity=none
173+
dotnet_diagnostic.xUnit1030.severity=none
174+
175+

build.proj

-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
<FunctionalTests Include="**/tools/TDS/TDS/TDS.csproj" />
5454
<FunctionalTests Include="**/tools/TDS/TDS.EndPoint/TDS.EndPoint.csproj" />
5555
<FunctionalTests Include="**/tools/TDS/TDS.Servers/TDS.Servers.csproj" />
56-
<FunctionalTests Include="**/tools/Microsoft.DotNet.XUnitExtensions/Microsoft.DotNet.XUnitExtensions.csproj" />
5756
<FunctionalTests Include="**/tools/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.csproj" />
5857
<FunctionalTests Include="**/ManualTests/SQL/UdtTest/UDTs/Address/Address.csproj" />
5958
<FunctionalTests Include="**/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj" />
@@ -64,7 +63,6 @@
6463
<ManualTests Include="**/ManualTests/SQL/UdtTest/UDTs/Circle/Circle.csproj" />
6564
<ManualTests Include="**/ManualTests/SQL/UdtTest/UDTs/Shapes/Shapes.csproj" />
6665
<ManualTests Include="**/ManualTests/SQL/UdtTest/UDTs/Utf8String/Utf8String.csproj" />
67-
<ManualTests Include="**/tools/Microsoft.DotNet.XUnitExtensions/Microsoft.DotNet.XUnitExtensions.csproj" />
6866
<ManualTests Include="**/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj"/>
6967
<ManualTests Include="**/tools/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.csproj" />
7068
<ManualTests Include="**/CustomConfigurableRetryLogic/CustomRetryLogicProvider.csproj" />

src/Microsoft.Data.SqlClient.sln

-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.SqlClient.Al
7272
EndProject
7373
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "add-ons", "add-ons", "{C9726AED-D6A3-4AAC-BA04-92DD1F079594}"
7474
EndProject
75-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.XUnitExtensions", "Microsoft.Data.SqlClient\tests\tools\Microsoft.DotNet.XUnitExtensions\Microsoft.DotNet.XUnitExtensions.csproj", "{FDA6971D-9F57-4DA4-B10A-261C91684CFC}"
76-
EndProject
7775
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{ED952CF7-84DF-437A-B066-F516E9BE1C2C}"
7876
EndProject
7977
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "snippets", "snippets", "{71F356DC-DFA3-4163-8BFE-D268722CE189}"

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public void TestAeadEncryptionReversal(string dataType, object data, Utility.CCo
303303
break;
304304

305305
default:
306-
Assert.True(false, "unexpected data type.");
306+
Assert.Fail("unexpected data type.");
307307
break;
308308
}
309309

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Runtime.InteropServices;
67
using System.Threading.Tasks;
78
using System.Transactions;
89
using Xunit;
@@ -11,7 +12,7 @@ namespace Microsoft.Data.SqlClient.Tests
1112
{
1213
public class AmbientTransactionFailureTest
1314
{
14-
15+
private static readonly bool s_isNotArmProcess = TestUtility.IsNotArmProcess;
1516
private static readonly string s_servername = Guid.NewGuid().ToString();
1617
private static readonly string s_connectionStringWithEnlistAsDefault = $"Data Source={s_servername}; Integrated Security=true; Connect Timeout=1;";
1718
private static readonly string s_connectionStringWithEnlistOff = $"Data Source={s_servername}; Integrated Security=true; Connect Timeout=1;Enlist=False";
@@ -73,7 +74,7 @@ public class AmbientTransactionFailureTest
7374
new object[] { EnlistConnectionInTransaction, s_connectionStringWithEnlistOff }
7475
};
7576

76-
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArmProcess))] // https://github.com/dotnet/corefx/issues/21598
77+
[ConditionalTheory(nameof(s_isNotArmProcess))] // https://github.com/dotnet/corefx/issues/21598
7778
[MemberData(nameof(ExceptionTestDataForSqlException))]
7879
public void TestSqlException(Action<string> connectAction, string connectionString)
7980
{
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

55
using System.Linq;
66
using System.Runtime.InteropServices;
77
using System.Threading.Tasks;
8+
using Microsoft.Data.SqlClient.Tests;
89
using Xunit;
910
using Xunit.Sdk;
1011

1112
namespace System
1213
{
1314
public static class AssertExtensions
1415
{
15-
private static bool IsFullFramework => RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework", StringComparison.Ordinal);
16+
private static bool IsFullFramework => TestUtility.IsFullFramework;
1617

1718
public static void Throws<T>(Action action, string message)
1819
where T : Exception
@@ -35,7 +36,7 @@ public static void Throws<T>(string netCoreParamName, string netFxParamName, Act
3536
IsFullFramework ?
3637
netFxParamName : netCoreParamName;
3738

38-
if (!RuntimeInformation.FrameworkDescription.StartsWith(".NET Native", StringComparison.Ordinal))
39+
if (!TestUtility.NetNative)
3940
Assert.Equal(expectedParamName, exception.ParamName);
4041
}
4142

@@ -54,7 +55,7 @@ public static void Throws<T>(string netCoreParamName, string netFxParamName, Fun
5455
IsFullFramework ?
5556
netFxParamName : netCoreParamName;
5657

57-
if (!RuntimeInformation.FrameworkDescription.StartsWith(".NET Native", StringComparison.Ordinal))
58+
if (!TestUtility.NetNative)
5859
Assert.Equal(expectedParamName, exception.ParamName);
5960
}
6061

@@ -63,7 +64,7 @@ public static T Throws<T>(string paramName, Action action)
6364
{
6465
T exception = Assert.Throws<T>(action);
6566

66-
if (!RuntimeInformation.FrameworkDescription.StartsWith(".NET Native", StringComparison.Ordinal))
67+
if (!TestUtility.NetNative)
6768
Assert.Equal(paramName, exception.ParamName);
6869

6970
return exception;
@@ -82,7 +83,7 @@ public static T Throws<T>(string paramName, Func<object> testCode)
8283
{
8384
T exception = Assert.Throws<T>(testCode);
8485

85-
if (!RuntimeInformation.FrameworkDescription.StartsWith(".NET Native", StringComparison.Ordinal))
86+
if (!TestUtility.NetNative)
8687
Assert.Equal(paramName, exception.ParamName);
8788

8889
return exception;
@@ -93,7 +94,7 @@ public static async Task<T> ThrowsAsync<T>(string paramName, Func<Task> testCode
9394
{
9495
T exception = await Assert.ThrowsAsync<T>(testCode);
9596

96-
if (!RuntimeInformation.FrameworkDescription.StartsWith(".NET Native", StringComparison.Ordinal))
97+
if (!TestUtility.NetNative)
9798
Assert.Equal(paramName, exception.ParamName);
9899

99100
return exception;
@@ -298,24 +299,5 @@ public static void GreaterThanOrEqualTo<T>(T actual, T greaterThanOrEqualTo, str
298299
throw new XunitException(AddOptionalUserMessage($"Expected: {actual} to be greater than or equal to {greaterThanOrEqualTo}", userMessage));
299300
}
300301

301-
/// <summary>
302-
/// Validates that the actual byte array is equal to the expected byte array. XUnit only displays the first 5 values
303-
/// of each collection if the test fails. This doesn't display at what point or how the equality assertion failed.
304-
/// </summary>
305-
/// <param name="expected">The byte array that <paramref name="actual"/> should be equal to.</param>
306-
/// <param name="actual"></param>
307-
public static void Equal(byte[] expected, byte[] actual)
308-
{
309-
try
310-
{
311-
Assert.Equal(expected, actual);
312-
}
313-
catch (AssertActualExpectedException)
314-
{
315-
string expectedString = string.Join(", ", expected);
316-
string actualString = string.Join(", ", actual);
317-
throw new AssertActualExpectedException(expectedString, actualString, null);
318-
}
319-
}
320302
}
321303
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Runtime.InteropServices;
7+
8+
namespace Microsoft.Data.SqlClient.Tests
9+
{
10+
public static class TestUtility
11+
{
12+
public static readonly bool IsNotArmProcess = RuntimeInformation.ProcessArchitecture != Architecture.Arm;
13+
public static bool IsFullFramework => RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework");
14+
public static bool NetNative => RuntimeInformation.FrameworkDescription.StartsWith(".NET Native");
15+
}
16+
}

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

+27-6
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
<Compile Include="AlwaysEncryptedTests\SqlConnectionShould.cs" />
2626
<Compile Include="AlwaysEncryptedTests\TestFixtures.cs" />
2727
<Compile Include="AlwaysEncryptedTests\Utility.cs" />
28+
<Compile Include="AssertExtensions.cs" />
2829
<Compile Include="DataCommon\AssemblyResourceManager.cs" />
2930
<Compile Include="DataCommon\SystemDataResourceManager.cs" />
31+
<Compile Include="DataCommon\TestUtility.cs" />
3032
<Compile Include="LocalizationTest.cs" />
3133
<Compile Include="MultipartIdentifierTests.cs" />
3234
<Compile Include="SqlClientLoggerTest.cs" />
@@ -66,6 +68,25 @@
6668
<Compile Include="SqlHelperTest.cs" />
6769
<Compile Include="..\..\src\Microsoft\Data\Common\MultipartIdentifier.cs" />
6870
</ItemGroup>
71+
<!-- XUnit and XUnit extensions -->
72+
<ItemGroup>
73+
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="$(MicrosoftNETFrameworkReferenceAssembliesVersion)" Condition="$(TargetGroup) == 'netfx'">
74+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
75+
<PrivateAssets>all</PrivateAssets>
76+
</PackageReference>
77+
<PackageReference Condition="$(TargetGroup) == 'netfx'" Include="System.Runtime.InteropServices.RuntimeInformation" Version="$(SystemRuntimeInteropServicesRuntimeInformationVersion)" />
78+
<PackageReference Include="xunit" Version="$(XunitVersion)" />
79+
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)">
80+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
81+
<PrivateAssets>all</PrivateAssets>
82+
</PackageReference>
83+
<PackageReference Include="xunit.runner.console" Version="$(XunitVersion)">
84+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
85+
<PrivateAssets>all</PrivateAssets>
86+
</PackageReference>
87+
<PackageReference Include="xunit.runner.utility" Version="$(XunitVersion)" />
88+
<PackageReference Include="Microsoft.DotNet.XUnitExtensions" Version="$(MicrosoftDotNetXUnitExtensionsVersion)" />
89+
</ItemGroup>
6990
<ItemGroup>
7091
<PackageReference Include="Microsoft.Extensions.Hosting" Version="$(MicrosoftExtensionsHosting)" />
7192
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkVersion)" />
@@ -92,21 +113,21 @@
92113
<ProjectReference Include="$(TestsPath)tools\TDS\TDS\TDS.csproj">
93114
<Name>TDS</Name>
94115
</ProjectReference>
95-
<ProjectReference Include="$(TestsPath)tools\Microsoft.DotNet.XUnitExtensions\Microsoft.DotNet.XUnitExtensions.csproj">
96-
<Name>Microsoft.DotNet.XUnitExtensions</Name>
97-
</ProjectReference>
98116
<ProjectReference Condition="!$(ReferenceType.Contains('NetStandard'))" Include="$(AddOnsPath)AzureKeyVaultProvider\Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider.csproj" />
99117
<ProjectReference Condition="'$(TargetGroup)'=='netcoreapp' AND $(ReferenceType)=='Project'" Include="$(NetCoreSource)src\Microsoft.Data.SqlClient.csproj" />
100118
<ProjectReference Condition="'$(TargetGroup)'=='netfx' AND $(ReferenceType)=='Project'" Include="$(NetFxSource)src\Microsoft.Data.SqlClient.csproj" />
101119
<ProjectReference Condition="$(ReferenceType.Contains('NetStandard'))" Include="$(TestsPath)NSLibrary\Microsoft.Data.SqlClient.NSLibrary.csproj" />
102120
<ProjectReference Condition="!$(ReferenceType.Contains('Package'))" Include="$(SqlServerSource)Microsoft.SqlServer.Server.csproj" />
103121
<PackageReference Condition="$(ReferenceType.Contains('Package'))" Include="Microsoft.Data.SqlClient" Version="$(TestMicrosoftDataSqlClientVersion)" />
104-
<!-- .NET Core 3.1.2 known issue; It should be added manually! -->
105-
<!-- https://github.com/dotnet/core/blob/main/release-notes/3.1/3.1-known-issues.md#net-core-312-sdk-31102-sdk -->
106-
<PackageReference Condition="'$(TargetFramework)'=='net6.0' AND $(ReferenceType)=='Package'" Include="System.Security.Cryptography.Cng" Version="$(SystemSecurityCryptographyCngVersion)" />
107122
</ItemGroup>
108123
<ItemGroup>
109124
<None Condition="'$(TargetGroup)'=='netfx' AND $(ReferenceType)=='Project'" Include="$(BinFolder)$(Configuration).AnyCPU\Microsoft.Data.SqlClient\netfx\**\*SNI*.dll" CopyToOutputDirectory="PreserveNewest" />
110125
<PackageReference Condition="$(ReferenceType.Contains('Package'))" Include="Microsoft.Identity.Client" Version="$(MicrosoftIdentityClientVersion)" />
111126
</ItemGroup>
127+
<ItemGroup>
128+
<ContentWithTargetPath Include="..\tools\Microsoft.Data.SqlClient.TestUtilities\xunit.runner.json">
129+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
130+
<TargetPath>xunit.runner.json</TargetPath>
131+
</ContentWithTargetPath>
132+
</ItemGroup>
112133
</Project>

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

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System;
66
using System.Collections;
77
using System.Diagnostics;
8-
98
using Xunit;
109

1110
namespace Microsoft.Data.SqlClient.Tests
@@ -420,7 +419,7 @@ public void InsertAndClear_BehavesAsExpected()
420419
Assert.Same(item3, list[2]);
421420

422421
list.Clear();
423-
Assert.Equal(0, list.Count);
422+
Assert.Empty(list);
424423

425424
list.Add(item1);
426425
list.Add(item3);
@@ -435,7 +434,7 @@ public void InsertAndClear_BehavesAsExpected()
435434
Assert.Same(item3, list[2]);
436435

437436
list.Clear();
438-
Assert.Equal(0, list.Count);
437+
Assert.Empty(list);
439438
}
440439

441440
[Fact]
@@ -463,11 +462,11 @@ public void Remove_BehavesAsExpected()
463462
IList list = CreateCollection(item1, item2);
464463

465464
list.Remove(item1);
466-
Assert.Equal(1, list.Count);
465+
Assert.Single(list);
467466
Assert.Same(item2, list[0]);
468467

469468
list.Remove(item2);
470-
Assert.Equal(0, list.Count);
469+
Assert.Empty(list);
471470

472471
AssertExtensions.Throws<ArgumentException>(null, () => list.Remove(item2));
473472
AssertExtensions.Throws<ArgumentException>(null, () => list.Remove(new SqlBulkCopyColumnMapping(2, 2)));
@@ -504,11 +503,11 @@ public void RemoveAt_BehavesAsExpected()
504503
Assert.Same(item3, list[1]);
505504

506505
list.RemoveAt(1);
507-
Assert.Equal(1, list.Count);
506+
Assert.Single(list);
508507
Assert.Same(item2, list[0]);
509508

510509
list.RemoveAt(0);
511-
Assert.Equal(0, list.Count);
510+
Assert.Empty(list);
512511
}
513512

514513
[Fact]

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ public void InsertAndClear_BehavesAsExpected()
395395
Assert.Same(item3, list[2]);
396396

397397
list.Clear();
398-
Assert.Equal(0, list.Count);
398+
Assert.Empty(list);
399399

400400
list.Add(item1);
401401
list.Add(item3);
@@ -410,7 +410,7 @@ public void InsertAndClear_BehavesAsExpected()
410410
Assert.Same(item3, list[2]);
411411

412412
list.Clear();
413-
Assert.Equal(0, list.Count);
413+
Assert.Empty(list);
414414
}
415415

416416
[Fact]
@@ -434,11 +434,11 @@ public void Remove_BehavesAsExpected()
434434
IList list = CreateCollection(item1, item2);
435435

436436
list.Remove(item1);
437-
Assert.Equal(1, list.Count);
437+
Assert.Single(list);
438438
Assert.Same(item2, list[0]);
439439

440440
list.Remove(item2);
441-
Assert.Equal(0, list.Count);
441+
Assert.Empty(list);
442442

443443
AssertExtensions.Throws<ArgumentException>(null, () => list.Remove(item2));
444444
AssertExtensions.Throws<ArgumentException>(null, () => list.Remove(new SqlBulkCopyColumnOrderHint("column4", SortOrder.Ascending)));
@@ -473,11 +473,11 @@ public void RemoveAt_BehavesAsExpected()
473473
Assert.Same(item2, list[0]);
474474
Assert.Same(item3, list[1]);
475475
list.RemoveAt(1);
476-
Assert.Equal(1, list.Count);
476+
Assert.Single(list);
477477
Assert.Same(item2, list[0]);
478478

479479
list.RemoveAt(0);
480-
Assert.Equal(0, list.Count);
480+
Assert.Empty(list);
481481
}
482482

483483
[Fact]

0 commit comments

Comments
 (0)