Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test | Removing internal build of XunitExtensions and using the nuget #2033

Merged
merged 30 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 0 additions & 2 deletions build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
<FunctionalTests Include="**/tools/TDS/TDS/TDS.csproj" />
<FunctionalTests Include="**/tools/TDS/TDS.EndPoint/TDS.EndPoint.csproj" />
<FunctionalTests Include="**/tools/TDS/TDS.Servers/TDS.Servers.csproj" />
<FunctionalTests Include="**/tools/Microsoft.DotNet.XUnitExtensions/Microsoft.DotNet.XUnitExtensions.csproj" />
<FunctionalTests Include="**/tools/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.csproj" />
<FunctionalTests Include="**/ManualTests/SQL/UdtTest/UDTs/Address/Address.csproj" />
<FunctionalTests Include="**/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj" />
Expand All @@ -64,7 +63,6 @@
<ManualTests Include="**/ManualTests/SQL/UdtTest/UDTs/Circle/Circle.csproj" />
<ManualTests Include="**/ManualTests/SQL/UdtTest/UDTs/Shapes/Shapes.csproj" />
<ManualTests Include="**/ManualTests/SQL/UdtTest/UDTs/Utf8String/Utf8String.csproj" />
<ManualTests Include="**/tools/Microsoft.DotNet.XUnitExtensions/Microsoft.DotNet.XUnitExtensions.csproj" />
<ManualTests Include="**/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj"/>
<ManualTests Include="**/tools/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.csproj" />
<ManualTests Include="**/CustomConfigurableRetryLogic/CustomRetryLogicProvider.csproj" />
Expand Down
2 changes: 0 additions & 2 deletions src/Microsoft.Data.SqlClient.sln
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.SqlClient.Al
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "add-ons", "add-ons", "{C9726AED-D6A3-4AAC-BA04-92DD1F079594}"
EndProject
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}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{ED952CF7-84DF-437A-B066-F516E9BE1C2C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "snippets", "snippets", "{71F356DC-DFA3-4163-8BFE-D268722CE189}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public void TestAeadEncryptionReversal(string dataType, object data, Utility.CCo
break;

default:
Assert.True(false, "unexpected data type.");
Assert.Fail("unexpected data type.");
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Transactions;
using Xunit;
Expand All @@ -11,7 +12,7 @@ namespace Microsoft.Data.SqlClient.Tests
{
public class AmbientTransactionFailureTest
{

private static readonly bool s_isNotArmProcess = RuntimeInformation.ProcessArchitecture != Architecture.Arm;
private static readonly string s_servername = Guid.NewGuid().ToString();
private static readonly string s_connectionStringWithEnlistAsDefault = $"Data Source={s_servername}; Integrated Security=true; Connect Timeout=1;";
private static readonly string s_connectionStringWithEnlistOff = $"Data Source={s_servername}; Integrated Security=true; Connect Timeout=1;Enlist=False";
Expand Down Expand Up @@ -73,7 +74,7 @@ public class AmbientTransactionFailureTest
new object[] { EnlistConnectionInTransaction, s_connectionStringWithEnlistOff }
};

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

Expand All @@ -12,7 +12,7 @@ namespace System
{
public static class AssertExtensions
{
private static bool IsFullFramework => RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework", StringComparison.Ordinal);
private static bool IsFullFramework => RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework");

public static void Throws<T>(Action action, string message)
where T : Exception
Expand All @@ -35,7 +35,7 @@ public static void Throws<T>(string netCoreParamName, string netFxParamName, Act
IsFullFramework ?
netFxParamName : netCoreParamName;

if (!RuntimeInformation.FrameworkDescription.StartsWith(".NET Native", StringComparison.Ordinal))
if (!RuntimeInformation.FrameworkDescription.StartsWith(".NET Native"))
Assert.Equal(expectedParamName, exception.ParamName);
}

Expand All @@ -54,7 +54,7 @@ public static void Throws<T>(string netCoreParamName, string netFxParamName, Fun
IsFullFramework ?
netFxParamName : netCoreParamName;

if (!RuntimeInformation.FrameworkDescription.StartsWith(".NET Native", StringComparison.Ordinal))
if (!RuntimeInformation.FrameworkDescription.StartsWith(".NET Native"))
Assert.Equal(expectedParamName, exception.ParamName);
}

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

if (!RuntimeInformation.FrameworkDescription.StartsWith(".NET Native", StringComparison.Ordinal))
if (!RuntimeInformation.FrameworkDescription.StartsWith(".NET Native"))
Assert.Equal(paramName, exception.ParamName);

return exception;
Expand All @@ -82,7 +82,7 @@ public static T Throws<T>(string paramName, Func<object> testCode)
{
T exception = Assert.Throws<T>(testCode);

if (!RuntimeInformation.FrameworkDescription.StartsWith(".NET Native", StringComparison.Ordinal))
if (!RuntimeInformation.FrameworkDescription.StartsWith(".NET Native"))
Assert.Equal(paramName, exception.ParamName);

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

if (!RuntimeInformation.FrameworkDescription.StartsWith(".NET Native", StringComparison.Ordinal))
if (!RuntimeInformation.FrameworkDescription.StartsWith(".NET Native"))
Assert.Equal(paramName, exception.ParamName);

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

/// <summary>
/// Validates that the actual byte array is equal to the expected byte array. XUnit only displays the first 5 values
/// of each collection if the test fails. This doesn't display at what point or how the equality assertion failed.
/// </summary>
/// <param name="expected">The byte array that <paramref name="actual"/> should be equal to.</param>
/// <param name="actual"></param>
public static void Equal(byte[] expected, byte[] actual)
{
try
{
Assert.Equal(expected, actual);
}
catch (AssertActualExpectedException)
{
string expectedString = string.Join(", ", expected);
string actualString = string.Join(", ", actual);
throw new AssertActualExpectedException(expectedString, actualString, null);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<Compile Include="AlwaysEncryptedTests\SqlConnectionShould.cs" />
<Compile Include="AlwaysEncryptedTests\TestFixtures.cs" />
<Compile Include="AlwaysEncryptedTests\Utility.cs" />
<Compile Include="AssertExtensions.cs" />
<Compile Include="DataCommon\AssemblyResourceManager.cs" />
<Compile Include="DataCommon\SystemDataResourceManager.cs" />
<Compile Include="LocalizationTest.cs" />
Expand Down Expand Up @@ -66,6 +67,18 @@
<Compile Include="SqlHelperTest.cs" />
<Compile Include="..\..\src\Microsoft\Data\Common\MultipartIdentifier.cs" />
</ItemGroup>
<!-- XUnit and XUnit extensions -->
<ItemGroup>
<PackageReference Condition="$(TargetGroup) == 'netfx'" Include="System.Runtime.InteropServices.RuntimeInformation" Version="$(SystemRuntimeInteropServicesRuntimeInformationVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(xunitrunnervisualstudioVersion)">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.runner.console" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.utility" Version="$(XunitVersion)" />
<PackageReference Include="Microsoft.DotNet.XUnitExtensions" Version="$(MicrosoftDotNetXUnitExtensionsVersion)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="$(MicrosoftExtensionsHosting)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkVersion)" />
Expand All @@ -92,9 +105,6 @@
<ProjectReference Include="$(TestsPath)tools\TDS\TDS\TDS.csproj">
<Name>TDS</Name>
</ProjectReference>
<ProjectReference Include="$(TestsPath)tools\Microsoft.DotNet.XUnitExtensions\Microsoft.DotNet.XUnitExtensions.csproj">
<Name>Microsoft.DotNet.XUnitExtensions</Name>
</ProjectReference>
<ProjectReference Condition="!$(ReferenceType.Contains('NetStandard'))" Include="$(AddOnsPath)AzureKeyVaultProvider\Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider.csproj" />
<ProjectReference Condition="'$(TargetGroup)'=='netcoreapp' AND $(ReferenceType)=='Project'" Include="$(NetCoreSource)src\Microsoft.Data.SqlClient.csproj" />
<ProjectReference Condition="'$(TargetGroup)'=='netfx' AND $(ReferenceType)=='Project'" Include="$(NetFxSource)src\Microsoft.Data.SqlClient.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections;
using System.Diagnostics;

using Xunit;

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

list.Clear();
Assert.Equal(0, list.Count);
Assert.Empty(list);

list.Add(item1);
list.Add(item3);
Expand All @@ -435,7 +434,7 @@ public void InsertAndClear_BehavesAsExpected()
Assert.Same(item3, list[2]);

list.Clear();
Assert.Equal(0, list.Count);
Assert.Empty(list);
}

[Fact]
Expand Down Expand Up @@ -463,11 +462,11 @@ public void Remove_BehavesAsExpected()
IList list = CreateCollection(item1, item2);

list.Remove(item1);
Assert.Equal(1, list.Count);
Assert.Single(list);
Assert.Same(item2, list[0]);

list.Remove(item2);
Assert.Equal(0, list.Count);
Assert.Empty(list);

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

list.RemoveAt(1);
Assert.Equal(1, list.Count);
Assert.Single(list);
Assert.Same(item2, list[0]);

list.RemoveAt(0);
Assert.Equal(0, list.Count);
Assert.Empty(list);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public void InsertAndClear_BehavesAsExpected()
Assert.Same(item3, list[2]);

list.Clear();
Assert.Equal(0, list.Count);
Assert.Empty(list);

list.Add(item1);
list.Add(item3);
Expand All @@ -410,7 +410,7 @@ public void InsertAndClear_BehavesAsExpected()
Assert.Same(item3, list[2]);

list.Clear();
Assert.Equal(0, list.Count);
Assert.Empty(list);
}

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

list.Remove(item1);
Assert.Equal(1, list.Count);
Assert.Single(list);
Assert.Same(item2, list[0]);

list.Remove(item2);
Assert.Equal(0, list.Count);
Assert.Empty(list);

AssertExtensions.Throws<ArgumentException>(null, () => list.Remove(item2));
AssertExtensions.Throws<ArgumentException>(null, () => list.Remove(new SqlBulkCopyColumnOrderHint("column4", SortOrder.Ascending)));
Expand Down Expand Up @@ -473,11 +473,11 @@ public void RemoveAt_BehavesAsExpected()
Assert.Same(item2, list[0]);
Assert.Same(item3, list[1]);
list.RemoveAt(1);
Assert.Equal(1, list.Count);
Assert.Single(list);
Assert.Same(item2, list[0]);

list.RemoveAt(0);
Assert.Equal(0, list.Count);
Assert.Empty(list);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -18,6 +19,7 @@ namespace Microsoft.Data.SqlClient.Tests
{
public class SqlConnectionBasicTests
{
private static readonly bool s_isNotArmProcess = RuntimeInformation.ProcessArchitecture != Architecture.Arm;
JRahnama marked this conversation as resolved.
Show resolved Hide resolved
[Fact]
public void ConnectionTest()
{
Expand All @@ -26,8 +28,7 @@ public void ConnectionTest()
connection.Open();
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArmProcess))]
[ActiveIssue(4830, TestPlatforms.AnyUnix)]
[ConditionalFact(nameof(s_isNotArmProcess))]
[PlatformSpecific(TestPlatforms.Windows)]
public void IntegratedAuthConnectionTest()
{
Expand All @@ -38,7 +39,7 @@ public void IntegratedAuthConnectionTest()
connection.Open();
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArmProcess))]
[ConditionalTheory(nameof(s_isNotArmProcess))]
[InlineData(40613)]
[InlineData(42108)]
[InlineData(42109)]
Expand All @@ -58,7 +59,7 @@ public async Task TransientFaultTestAsync(uint errorCode)
Assert.Equal(ConnectionState.Open, connection.State);
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArmProcess))]
[ConditionalTheory(nameof(s_isNotArmProcess))]
[InlineData(40613)]
[InlineData(42108)]
[InlineData(42109)]
Expand All @@ -81,11 +82,11 @@ public void TransientFaultTest(uint errorCode)
}
catch (Exception e)
{
Assert.False(true, e.Message);
Assert.Fail(e.Message);
}
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArmProcess))]
[ConditionalTheory(nameof(s_isNotArmProcess))]
[InlineData(40613)]
[InlineData(42108)]
[InlineData(42109)]
Expand All @@ -107,7 +108,7 @@ public void TransientFaultDisabledTestAsync(uint errorCode)
Assert.Equal(ConnectionState.Closed, connection.State);
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArmProcess))]
[ConditionalTheory(nameof(s_isNotArmProcess))]
[InlineData(40613)]
[InlineData(42108)]
[InlineData(42109)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ public void RetrieveStatistics_Clear_Success()
d.Clear();

Assert.Empty(d);
Assert.Equal(0, d.Count);
Assert.Empty(d);

Assert.Empty(d.Keys);
Assert.Equal(0, d.Keys.Count);
Assert.Empty(d.Keys);

Assert.Empty(d.Values);
Assert.Equal(0, d.Values.Count);
Assert.Empty(d.Values);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void SqlRecordFillTest()

char[] expectedValue = new char[] { 'a', 'b', 'e', 'f', 'g' };
Assert.Equal(expectedValue.Length, record.GetChars(3, 0, cb2, 0, 5));
Assert.Equal<char>(expectedValue, new string(cb2, 0, (int)record.GetChars(3, 0, null, 0, 0)));
Assert.Equal<char>(expectedValue, new string(cb2, 0, (int)record.GetChars(3, 0, null, 0, 0)).ToCharArray());

record.SetString(3, "");
string xyz = "xyz";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void SqlErrorSerializationTest()
}
catch (Exception ex)
{
Assert.False(true, $"Unexpected Exception occurred: {ex.Message}");
Assert.Fail($"Unexpected Exception occurred: {ex.Message}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static void SqlExcpetionSerializationTest()
}
catch (Exception ex)
{
Assert.False(true, $"Unexpected Exception occurred: {ex.Message}");
Assert.Fail($"Unexpected Exception occurred: {ex.Message}");
}
}
}
Expand Down
Loading