Skip to content

Commit 7ad964c

Browse files
authored
Merge pull request #297 from ChrisDoernen/xunit-version-3
Update to xunit 3
2 parents a1fa952 + f6edbe0 commit 7ad964c

File tree

8 files changed

+48
-33
lines changed

8 files changed

+48
-33
lines changed

azure-pipeline-PR.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ steps:
1717
displayName: 'Use .NET 9.0 sdk'
1818
inputs:
1919
packageType: sdk
20-
version: 9.0.300
20+
version: 9.0.301
2121
installationPath: $(Agent.ToolsDirectory)/dotnet
2222
- script: echo Started restoring the source code
2323
- task: DotNetCoreCLI@2

azure-pipelines.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
variables:
22
Major: 9
33
Minor: 0
4-
Revision: 5
4+
Revision: 6
55
BuildConfiguration: Release
66

77
name: $(Major).$(Minor).$(Revision)
@@ -25,7 +25,7 @@ steps:
2525
displayName: 'Use .NET 9.0 sdk'
2626
inputs:
2727
packageType: sdk
28-
version: 9.0.300
28+
version: 9.0.301
2929
installationPath: $(Agent.ToolsDirectory)/dotnet
3030
- script: echo Started restoring the source code
3131
- task: DotNetCoreCLI@2

examples/Xunit.Microsoft.DependencyInjection.ExampleTests/GlobalUsings.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
global using Microsoft.Extensions.DependencyInjection;
33
global using System.Collections.Generic;
44
global using System.Threading.Tasks;
5-
global using Xunit.Abstractions;
65
global using Xunit.Microsoft.DependencyInjection.Abstracts;
76
global using Xunit.Microsoft.DependencyInjection.Attributes;
87
global using Xunit.Microsoft.DependencyInjection.ExampleTests.Fixtures;

examples/Xunit.Microsoft.DependencyInjection.ExampleTests/UnitTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
using Xunit.Microsoft.DependencyInjection.TestsOrder;
2+
13
namespace Xunit.Microsoft.DependencyInjection.ExampleTests;
24

3-
[TestCaseOrderer("Xunit.Microsoft.DependencyInjection.TestsOrder.TestPriorityOrderer", "Xunit.Microsoft.DependencyInjection")]
5+
[TestCaseOrderer(typeof(TestPriorityOrderer))]
46
public class UnitTests
57
{
68
[Fact, TestOrder(1)]
@@ -14,14 +16,14 @@ public void Test2()
1416
[Fact, TestOrder(3)]
1517
public async Task Test3()
1618
{
17-
await Task.Delay(3000);
19+
await Task.Delay(3000, TestContext.Current.CancellationToken);
1820
Assert.Equal(1, 1);
1921
}
2022

2123
[Fact, TestOrder(4)]
2224
public async Task Test4()
2325
{
24-
await Task.Delay(5000);
26+
await Task.Delay(5000, TestContext.Current.CancellationToken);
2527
Assert.True(1 > 0);
2628
}
2729
}

examples/Xunit.Microsoft.DependencyInjection.ExampleTests/Xunit.Microsoft.DependencyInjection.ExampleTests.csproj

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,28 @@
77
<Nullable>enable</Nullable>
88
<ImplicitUsings>enable</ImplicitUsings>
99
<UserSecretsId>59bdc82c-5628-47c8-a5ec-3630c3a2bc45</UserSecretsId>
10+
<OutputType>Exe</OutputType>
1011
</PropertyGroup>
1112

1213
<ItemGroup>
13-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.5" />
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
15-
<PackageReference Include="xunit" Version="2.9.3" />
16-
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0">
14+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.6" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
16+
<PackageReference Include="xunit.v3" Version="2.0.3" />
17+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.1">
1718
<PrivateAssets>all</PrivateAssets>
1819
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1920
</PackageReference>
2021
<PackageReference Include="coverlet.collector" Version="6.0.4">
2122
<PrivateAssets>all</PrivateAssets>
2223
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2324
</PackageReference>
24-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.5" />
25-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.5" />
26-
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.5" />
27-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.5" />
28-
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.5" />
29-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.5" />
30-
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.5" />
25+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.6" />
26+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.6" />
27+
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.6" />
28+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.6" />
29+
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.6" />
30+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.6" />
31+
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.6" />
3132
</ItemGroup>
3233
<ItemGroup>
3334
<None Remove="appsettings.json" />

src/GlobalUsings.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
global using Microsoft.Extensions.Configuration;
22
global using Microsoft.Extensions.DependencyInjection;
33
global using Microsoft.Extensions.Logging;
4-
global using Xunit.Abstractions;
54
global using Xunit.Microsoft.DependencyInjection.Attributes;
65
global using Xunit.Microsoft.DependencyInjection.Logging;
76
global using Xunit.Sdk;

src/TestsOrder/TestPriorityOrderer.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,47 @@
1-
namespace Xunit.Microsoft.DependencyInjection.TestsOrder;
1+
using System.Reflection;
2+
using Xunit.v3;
3+
4+
namespace Xunit.Microsoft.DependencyInjection.TestsOrder;
25

36
public class TestPriorityOrderer : ITestCaseOrderer
47
{
5-
public IEnumerable<TTestCase> OrderTestCases<TTestCase>(IEnumerable<TTestCase> testCases)
8+
public IReadOnlyCollection<TTestCase> OrderTestCases<TTestCase>(IReadOnlyCollection<TTestCase> testCases)
69
where TTestCase : ITestCase
710
{
811
var sortedMethods = new SortedDictionary<int, List<TTestCase>>();
912

1013
foreach (var testCase in testCases)
1114
{
1215
var priority = 0;
13-
14-
foreach (var attr in testCase.TestMethod.Method.GetCustomAttributes(typeof(TestOrderAttribute).AssemblyQualifiedName))
16+
var testMethod = testCase.TestMethod;
17+
var type = Type.GetType(testMethod?.TestClass.TestClassNamespace ?? string.Empty) ?? AppDomain.CurrentDomain
18+
.GetAssemblies()
19+
.Select(a => a.GetType(testMethod?.TestClass?.TestClassName ?? string.Empty))
20+
.FirstOrDefault(t => t != null);
21+
var method = type?.GetMethod(testMethod?.MethodName ?? string.Empty);
22+
var attributes = method?.GetCustomAttributes(typeof(TestOrderAttribute));
23+
foreach (var attr in attributes!)
1524
{
16-
priority = attr.GetNamedArgument<int>("Priority");
25+
if (attr is TestOrderAttribute orderAttr)
26+
{
27+
priority = orderAttr.Priority;
28+
}
1729
}
1830

1931
GetOrCreate(sortedMethods, priority).Add(testCase);
2032
}
2133

34+
var testCaseCollection = new List<TTestCase>();
2235
foreach (var list in sortedMethods.Keys.Select(priority => sortedMethods[priority]))
2336
{
24-
list.Sort((x, y) => StringComparer.OrdinalIgnoreCase.Compare(x.TestMethod.Method.Name, y.TestMethod.Method.Name));
37+
list.Sort((x, y) => StringComparer.OrdinalIgnoreCase.Compare(x.TestMethod?.MethodName, y.TestMethod?.MethodName));
2538
foreach (var testCase in list)
2639
{
27-
yield return testCase;
40+
testCaseCollection.Add(testCase);
2841
}
2942
}
43+
44+
return testCaseCollection.AsReadOnly();
3045
}
3146

3247
private TValue GetOrCreate<TKey, TValue>(IDictionary<TKey, TValue> dictionary, TKey key)

src/Xunit.Microsoft.DependencyInjection.csproj

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
<PackageReadmeFile>README.md</PackageReadmeFile>
88
</PropertyGroup>
99
<ItemGroup>
10-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.5" />
11-
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.5" />
12-
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
13-
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.5" />
14-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.5" />
15-
<PackageReference Include="xunit.core" Version="2.9.3" />
16-
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.5" />
10+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.6" />
11+
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.6" />
12+
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.6" />
13+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.6" />
14+
<PackageReference Include="xunit.v3.extensibility.core" Version="2.0.3" />
15+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.6" />
1716
</ItemGroup>
1817
<ItemGroup>
1918
<None Include="..\README.md" Pack="true" PackagePath="\" />

0 commit comments

Comments
 (0)