diff --git a/azure-pipeline-PR.yml b/azure-pipeline-PR.yml index db08c7e..a7634c9 100644 --- a/azure-pipeline-PR.yml +++ b/azure-pipeline-PR.yml @@ -17,7 +17,7 @@ steps: displayName: 'Use .NET 9.0 sdk' inputs: packageType: sdk - version: 9.0.300 + version: 9.0.301 installationPath: $(Agent.ToolsDirectory)/dotnet - script: echo Started restoring the source code - task: DotNetCoreCLI@2 diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 99e34ba..d2caaa1 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,7 +1,7 @@ variables: Major: 9 Minor: 0 - Revision: 5 + Revision: 6 BuildConfiguration: Release name: $(Major).$(Minor).$(Revision) @@ -25,7 +25,7 @@ steps: displayName: 'Use .NET 9.0 sdk' inputs: packageType: sdk - version: 9.0.300 + version: 9.0.301 installationPath: $(Agent.ToolsDirectory)/dotnet - script: echo Started restoring the source code - task: DotNetCoreCLI@2 diff --git a/examples/Xunit.Microsoft.DependencyInjection.ExampleTests/GlobalUsings.cs b/examples/Xunit.Microsoft.DependencyInjection.ExampleTests/GlobalUsings.cs index 88048b1..0386e15 100644 --- a/examples/Xunit.Microsoft.DependencyInjection.ExampleTests/GlobalUsings.cs +++ b/examples/Xunit.Microsoft.DependencyInjection.ExampleTests/GlobalUsings.cs @@ -2,7 +2,6 @@ global using Microsoft.Extensions.DependencyInjection; global using System.Collections.Generic; global using System.Threading.Tasks; -global using Xunit.Abstractions; global using Xunit.Microsoft.DependencyInjection.Abstracts; global using Xunit.Microsoft.DependencyInjection.Attributes; global using Xunit.Microsoft.DependencyInjection.ExampleTests.Fixtures; diff --git a/examples/Xunit.Microsoft.DependencyInjection.ExampleTests/UnitTests.cs b/examples/Xunit.Microsoft.DependencyInjection.ExampleTests/UnitTests.cs index e6bd000..e58545f 100644 --- a/examples/Xunit.Microsoft.DependencyInjection.ExampleTests/UnitTests.cs +++ b/examples/Xunit.Microsoft.DependencyInjection.ExampleTests/UnitTests.cs @@ -1,6 +1,8 @@ +using Xunit.Microsoft.DependencyInjection.TestsOrder; + namespace Xunit.Microsoft.DependencyInjection.ExampleTests; -[TestCaseOrderer("Xunit.Microsoft.DependencyInjection.TestsOrder.TestPriorityOrderer", "Xunit.Microsoft.DependencyInjection")] +[TestCaseOrderer(typeof(TestPriorityOrderer))] public class UnitTests { [Fact, TestOrder(1)] @@ -14,14 +16,14 @@ public void Test2() [Fact, TestOrder(3)] public async Task Test3() { - await Task.Delay(3000); + await Task.Delay(3000, TestContext.Current.CancellationToken); Assert.Equal(1, 1); } [Fact, TestOrder(4)] public async Task Test4() { - await Task.Delay(5000); + await Task.Delay(5000, TestContext.Current.CancellationToken); Assert.True(1 > 0); } } diff --git a/examples/Xunit.Microsoft.DependencyInjection.ExampleTests/Xunit.Microsoft.DependencyInjection.ExampleTests.csproj b/examples/Xunit.Microsoft.DependencyInjection.ExampleTests/Xunit.Microsoft.DependencyInjection.ExampleTests.csproj index 9097b30..a16e5c0 100644 --- a/examples/Xunit.Microsoft.DependencyInjection.ExampleTests/Xunit.Microsoft.DependencyInjection.ExampleTests.csproj +++ b/examples/Xunit.Microsoft.DependencyInjection.ExampleTests/Xunit.Microsoft.DependencyInjection.ExampleTests.csproj @@ -7,13 +7,14 @@ enable enable 59bdc82c-5628-47c8-a5ec-3630c3a2bc45 + Exe - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -21,13 +22,13 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - + + + + + + + diff --git a/src/GlobalUsings.cs b/src/GlobalUsings.cs index 6c0ebd4..22f9f4b 100644 --- a/src/GlobalUsings.cs +++ b/src/GlobalUsings.cs @@ -1,7 +1,6 @@ global using Microsoft.Extensions.Configuration; global using Microsoft.Extensions.DependencyInjection; global using Microsoft.Extensions.Logging; -global using Xunit.Abstractions; global using Xunit.Microsoft.DependencyInjection.Attributes; global using Xunit.Microsoft.DependencyInjection.Logging; global using Xunit.Sdk; \ No newline at end of file diff --git a/src/TestsOrder/TestPriorityOrderer.cs b/src/TestsOrder/TestPriorityOrderer.cs index 40f3036..6b3bdaf 100644 --- a/src/TestsOrder/TestPriorityOrderer.cs +++ b/src/TestsOrder/TestPriorityOrderer.cs @@ -1,8 +1,11 @@ -namespace Xunit.Microsoft.DependencyInjection.TestsOrder; +using System.Reflection; +using Xunit.v3; + +namespace Xunit.Microsoft.DependencyInjection.TestsOrder; public class TestPriorityOrderer : ITestCaseOrderer { - public IEnumerable OrderTestCases(IEnumerable testCases) + public IReadOnlyCollection OrderTestCases(IReadOnlyCollection testCases) where TTestCase : ITestCase { var sortedMethods = new SortedDictionary>(); @@ -10,23 +13,35 @@ public IEnumerable OrderTestCases(IEnumerable t foreach (var testCase in testCases) { var priority = 0; - - foreach (var attr in testCase.TestMethod.Method.GetCustomAttributes(typeof(TestOrderAttribute).AssemblyQualifiedName)) + var testMethod = testCase.TestMethod; + var type = Type.GetType(testMethod?.TestClass.TestClassNamespace ?? string.Empty) ?? AppDomain.CurrentDomain + .GetAssemblies() + .Select(a => a.GetType(testMethod?.TestClass?.TestClassName ?? string.Empty)) + .FirstOrDefault(t => t != null); + var method = type?.GetMethod(testMethod?.MethodName ?? string.Empty); + var attributes = method?.GetCustomAttributes(typeof(TestOrderAttribute)); + foreach (var attr in attributes!) { - priority = attr.GetNamedArgument("Priority"); + if (attr is TestOrderAttribute orderAttr) + { + priority = orderAttr.Priority; + } } GetOrCreate(sortedMethods, priority).Add(testCase); } + var testCaseCollection = new List(); foreach (var list in sortedMethods.Keys.Select(priority => sortedMethods[priority])) { - list.Sort((x, y) => StringComparer.OrdinalIgnoreCase.Compare(x.TestMethod.Method.Name, y.TestMethod.Method.Name)); + list.Sort((x, y) => StringComparer.OrdinalIgnoreCase.Compare(x.TestMethod?.MethodName, y.TestMethod?.MethodName)); foreach (var testCase in list) { - yield return testCase; + testCaseCollection.Add(testCase); } } + + return testCaseCollection.AsReadOnly(); } private TValue GetOrCreate(IDictionary dictionary, TKey key) diff --git a/src/Xunit.Microsoft.DependencyInjection.csproj b/src/Xunit.Microsoft.DependencyInjection.csproj index 5a18242..51261e8 100644 --- a/src/Xunit.Microsoft.DependencyInjection.csproj +++ b/src/Xunit.Microsoft.DependencyInjection.csproj @@ -7,13 +7,12 @@ README.md - - - - - - - + + + + + +