Skip to content

Commit

Permalink
Upgrade xunit3 (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
meziantou authored Dec 23, 2024
1 parent 66a5ec9 commit 5a81e88
Show file tree
Hide file tree
Showing 61 changed files with 243 additions and 244 deletions.
2 changes: 1 addition & 1 deletion common/SharedHttpClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NET462 || NET472
#if NETFRAMEWORK
using System.Net.Http;
#endif

Expand Down
6 changes: 6 additions & 0 deletions common/XUnitStaticHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace TestUtilities;

internal static class XUnitStaticHelpers
{
public static CancellationToken XunitCancellationToken => Xunit.TestContext.Current.CancellationToken;
}
4 changes: 4 additions & 0 deletions eng/validate-testprojects-configuration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ $Errors = $Projs | Foreach-Object -ThrottleLimit 5 -Parallel {
continue;
}

if ($RefTfm -eq "net462" -and $TestProjectTfms.Contains("net472")) {
continue;
}

if (-not $TestProjectTfms.Contains($RefTfm)) {
Write-Error "Project $($Proj.FullName) does not target $RefTfm, but it references $RefProj which does. ($TestProjectTfms) != ($RefTfms)"
return 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(LatestTargetFrameworks);netstandard2.0;net462</TargetFrameworks>
Expand All @@ -8,7 +8,7 @@
<Description>Class to parse and displaying values, such as file size, in Bytes</Description>
</PropertyGroup>

<ItemGroup Condition="$(TargetFramework) == 'net462'">
<ItemGroup Condition="$(TargetFramework) == 'net462' OR $(TargetFramework) == 'net472'">
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(LatestTargetFrameworks);netstandard2.0;net462</TargetFrameworks>
<TargetFrameworks>$(LatestTargetFrameworks);netstandard2.0;net462;net472</TargetFrameworks>
<RootNamespace>Meziantou.Framework</RootNamespace>
<Version>2.0.2</Version>
<IsTrimmable>true</IsTrimmable>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(LatestTargetFrameworks);net462</TargetFrameworks>
Expand Down
6 changes: 3 additions & 3 deletions src/Meziantou.Framework.SingleInstance/SingleInstance.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.IO.Pipes;
using System.Runtime.Versioning;

#if NET461 || NET462
#if NET461 || NET462 || NET472
using System.Security.AccessControl;
using System.Security.Principal;
#endif
Expand Down Expand Up @@ -64,7 +64,7 @@ private void StartNamedPipeServer()
NamedPipeServerStream.MaxAllowedServerInstances,
PipeTransmissionMode.Message,
PipeOptions.CurrentUserOnly);
#elif NET461 || NET462
#elif NET461 || NET462 || NET472
using (var currentIdentity = WindowsIdentity.GetCurrent())
{
var identifier = currentIdentity.Owner;
Expand Down Expand Up @@ -199,7 +199,7 @@ private static int GetCurrentProcessId()
{
#if NET5_0_OR_GREATER
return Environment.ProcessId;
#elif NET461 || NET462
#elif NET461 || NET462 || NET472
return System.Diagnostics.Process.GetCurrentProcess().Id;
#else
#error Platform not supported
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(LatestTargetFrameworks);netstandard2.0;net462</TargetFrameworks>
Expand All @@ -7,11 +7,11 @@
<Description>Provide a SemanticVersion class to parse, compare, format semantic versions</Description>
</PropertyGroup>

<ItemGroup Condition="$(TargetFramework) == 'net462'">
<ItemGroup Condition="$(TargetFramework) == 'net462' OR $(TargetFramework) == 'net472'">
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'net462' OR $(TargetFramework) == 'netstandard2.0'">
<ItemGroup Condition="$(TargetFramework) == 'net462' OR $(TargetFramework) == 'net472' OR $(TargetFramework) == 'netstandard2.0'">
<PackageReference Include="System.Memory" Version="4.6.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void EnsureCapacity(int capacity)
{
Items.EnsureCapacity(capacity);
}
#elif NET461 || NET462
#elif NET461 || NET462 || NET472
#else
#error Platform not supported
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/Meziantou.Framework.WPF/Meziantou.Framework.WPF.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<TargetFrameworks>$(LatestTargetFrameworksWindows);net462</TargetFrameworks>
Expand All @@ -12,7 +12,7 @@
<PackageReference Include="System.Collections.Immutable" Version="9.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<ItemGroup Condition="'$(TargetFramework)' == 'net462' OR '$(TargetFramework)' == 'net472'">
<Reference Include="System.ComponentModel.DataAnnotations" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(LatestTargetFrameworks);netstandard2.0;net462</TargetFrameworks>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(LatestTargetFrameworks);net462</TargetFrameworks>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(LatestTargetFrameworks);netstandard2.0;net462</TargetFrameworks>
Expand Down
3 changes: 3 additions & 0 deletions tests/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ dotnet_diagnostic.MA0036.severity = none
dotnet_diagnostic.MA0038.severity = none
dotnet_diagnostic.MA0080.severity = none

# xunit rule for CancellationToken (XunitCancellationToken)
dotnet_diagnostic.xUnit1051.severity = none

# Async suffix
dotnet_diagnostic.VSTHRD200.severity = none
1 change: 1 addition & 0 deletions tests/ArgumentsPrinter/ArgumentsPrinter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
<RollForward>LatestMajor</RollForward>
<IncludeDefaultTestReferences>false</IncludeDefaultTestReferences>
</PropertyGroup>

</Project>
15 changes: 9 additions & 6 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<PropertyGroup>
<OutputType Condition="'$(OutputType)' == ''">Exe</OutputType>
<IncludeDefaultTestReferences Condition="'$(IncludeDefaultTestReferences)' == ''">true</IncludeDefaultTestReferences>
</PropertyGroup>

<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)xunit.runner.json" CopyToOutputDirectory="PreserveNewest" Visible="false" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) != 'netstandard2.0' AND '$(IncludeDefaultTestReferences)' == 'true'">
<Compile Include="$(MSBuildThisFileDirectory)..\common\XUnitStaticHelpers.cs" Link="XUnitStaticHelpers.cs" Condition="'$(MSBuildProjectExtension)' == '.csproj'" Visible="false" />

<Using Include="Xunit.TestContext" Alias="TestContext" />
<Using Include="TestUtilities.XUnitStaticHelpers" Static="true" />

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit.v3" Version="1.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0" />
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Meziantou.FluentAssertionsAnalyzers" Version="1.0.21">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
11 changes: 6 additions & 5 deletions tests/Meziantou.AspNetCore.Components.Tests/RepeaterTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Bunit;
using Xunit;
using BunitTestContext = Bunit.TestContext;

namespace Meziantou.AspNetCore.Components.Tests;

Expand All @@ -8,7 +9,7 @@ public sealed class RepeaterTests
[Fact]
public void NullDataShowLoadingIndicator()
{
using var ctx = new TestContext();
using var ctx = new BunitTestContext();
var cut = ctx.RenderComponent<Repeater<string>>(parameter => parameter
.Add(p => p.Items, value: null)
.Add(p => p.LoadingTemplate, "<p>Loading...</p>")
Expand All @@ -20,7 +21,7 @@ public void NullDataShowLoadingIndicator()
[Fact]
public void EmptyTemplate()
{
using var ctx = new TestContext();
using var ctx = new BunitTestContext();
var cut = ctx.RenderComponent<Repeater<string>>(parameter => parameter
.Add(p => p.Items, value: new List<string>())
.Add(p => p.LoadingTemplate, "<p>loading...</p>")
Expand All @@ -32,7 +33,7 @@ public void EmptyTemplate()
[Fact]
public void ItemTemplate()
{
using var ctx = new TestContext();
using var ctx = new BunitTestContext();
var cut = ctx.RenderComponent<Repeater<string>>(parameter => parameter
.Add(p => p.Items, value: new List<string>() { "a", "b" })
.Add(p => p.EmptyTemplate, "<p>empty</p>")
Expand All @@ -44,7 +45,7 @@ public void ItemTemplate()
[Fact]
public void ItemTemplateAndSeparatorTemplate()
{
using var ctx = new TestContext();
using var ctx = new BunitTestContext();
var cut = ctx.RenderComponent<Repeater<string>>(parameter => parameter
.Add(p => p.Items, value: new List<string>() { "a", "b" })
.Add(p => p.EmptyTemplate, "<p>empty</p>")
Expand All @@ -57,7 +58,7 @@ public void ItemTemplateAndSeparatorTemplate()
[Fact]
public void ContainerTemplate()
{
using var ctx = new TestContext();
using var ctx = new BunitTestContext();
var cut = ctx.RenderComponent<Repeater<string>>(parameter => parameter
.Add(p => p.Items, value: new List<string>() { "a", "b" })
.Add(p => p.EmptyTemplate, "<p>empty</p>")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#pragma warning disable CA1848 // Use the LoggerMessage delegates
using Meziantou.Extensions.Logging.Xunit;
using Meziantou.Extensions.Logging.Xunit.v3;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Xunit;
using Xunit.Abstractions;

namespace Meziantou.Extensions.Logging.InMemory.Tests;

Expand All @@ -26,7 +25,6 @@ public void Test()
{
builder.Services.AddSingleton<ILoggerProvider>(provider);
builder.Services.AddSingleton<ILoggerProvider>(new XUnitLoggerProvider(_testOutputHelper));

})
.Build();

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

<ItemGroup>
<ProjectReference Include="..\..\src\Meziantou.Extensions.Logging.InMemory\Meziantou.Extensions.Logging.InMemory.csproj" />
<ProjectReference Include="..\..\src\Meziantou.Extensions.Logging.Xunit\Meziantou.Extensions.Logging.Xunit.csproj" />
<ProjectReference Include="..\..\src\Meziantou.Extensions.Logging.Xunit.v3\Meziantou.Extensions.Logging.Xunit.v3.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using FluentAssertions.Execution;
using TestUtilities;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;

namespace Meziantou.Framework.CommandLineTests;
Expand Down Expand Up @@ -49,7 +48,7 @@ public void WindowsQuotedArgument_Test(string value, string expected)
ValidateArguments("dotnet", "\"" + path + "\" " + args, [expected]);
}

[RunIfTheory(FactOperatingSystem.Windows)]
[Theory, RunIf(FactOperatingSystem.Windows)]
[MemberData(nameof(GetArguments))]
public void WindowsCmdArgument_Test(string value, string expected)
{
Expand Down
Loading

0 comments on commit 5a81e88

Please sign in to comment.