diff --git a/src/Testing/src/xunit/ConditionalFactAttribute.cs b/src/Testing/src/xunit/ConditionalFactAttribute.cs index fdc108190a..538a055792 100644 --- a/src/Testing/src/xunit/ConditionalFactAttribute.cs +++ b/src/Testing/src/xunit/ConditionalFactAttribute.cs @@ -8,7 +8,7 @@ using Xunit.Sdk; namespace Microsoft.AspNetCore.Testing { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] - [XunitTestCaseDiscoverer("Microsoft.AspNetCore.Testing.xunit." + nameof(ConditionalFactDiscoverer), "Microsoft.AspNetCore.Testing")] + [XunitTestCaseDiscoverer("Microsoft.AspNetCore.Testing." + nameof(ConditionalFactDiscoverer), "Microsoft.AspNetCore.Testing")] public class ConditionalFactAttribute : FactAttribute { } diff --git a/src/Testing/src/xunit/ConditionalTheoryAttribute.cs b/src/Testing/src/xunit/ConditionalTheoryAttribute.cs index 58b460e96e..2fbac5d90c 100644 --- a/src/Testing/src/xunit/ConditionalTheoryAttribute.cs +++ b/src/Testing/src/xunit/ConditionalTheoryAttribute.cs @@ -8,7 +8,7 @@ using Xunit.Sdk; namespace Microsoft.AspNetCore.Testing { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] - [XunitTestCaseDiscoverer("Microsoft.AspNetCore.Testing.xunit." + nameof(ConditionalTheoryDiscoverer), "Microsoft.AspNetCore.Testing")] + [XunitTestCaseDiscoverer("Microsoft.AspNetCore.Testing." + nameof(ConditionalTheoryDiscoverer), "Microsoft.AspNetCore.Testing")] public class ConditionalTheoryAttribute : TheoryAttribute { } diff --git a/src/Testing/test/AlphabeticalOrderer.cs b/src/Testing/test/AlphabeticalOrderer.cs new file mode 100644 index 0000000000..24970cc281 --- /dev/null +++ b/src/Testing/test/AlphabeticalOrderer.cs @@ -0,0 +1,22 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using Xunit.Abstractions; +using Xunit.Sdk; + +namespace Microsoft.AspNetCore.Testing +{ + public class AlphabeticalOrderer : ITestCaseOrderer + { + public IEnumerable OrderTestCases(IEnumerable testCases) + where TTestCase : ITestCase + { + var result = testCases.ToList(); + result.Sort((x, y) => StringComparer.OrdinalIgnoreCase.Compare(x.TestMethod.Method.Name, y.TestMethod.Method.Name)); + return result; + } + } +} diff --git a/src/Testing/test/ConditionalFactTest.cs b/src/Testing/test/ConditionalFactTest.cs index efc3a16dea..0f1c6ada46 100644 --- a/src/Testing/test/ConditionalFactTest.cs +++ b/src/Testing/test/ConditionalFactTest.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Testing { + [TestCaseOrderer("Microsoft.AspNetCore.Testing.AlphabeticalOrderer", "Microsoft.AspNetCore.Testing.Tests")] public class ConditionalFactTest : IClassFixture { public ConditionalFactTest(ConditionalFactAsserter collector) @@ -47,13 +47,19 @@ namespace Microsoft.AspNetCore.Testing #error Target frameworks need to be updated. #endif + // Test is named this way to be the lowest test in the alphabet, it relies on test ordering + [Fact] + public void ZzzzzzzEnsureThisIsTheLastTest() + { + Assert.True(Asserter.TestRan); + } + public class ConditionalFactAsserter : IDisposable { public bool TestRan { get; set; } public void Dispose() { - Assert.True(TestRan, "If this assertion fails, a conditional fact wasn't discovered."); } } } diff --git a/src/Testing/test/ConditionalTheoryTest.cs b/src/Testing/test/ConditionalTheoryTest.cs index 07cf6a968f..12deaba4f9 100644 --- a/src/Testing/test/ConditionalTheoryTest.cs +++ b/src/Testing/test/ConditionalTheoryTest.cs @@ -2,12 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Testing; using Xunit; using Xunit.Abstractions; namespace Microsoft.AspNetCore.Testing { + [TestCaseOrderer("Microsoft.AspNetCore.Testing.AlphabeticalOrderer", "Microsoft.AspNetCore.Testing.Tests")] public class ConditionalTheoryTest : IClassFixture { public ConditionalTheoryTest(ConditionalTheoryAsserter asserter) @@ -101,6 +101,13 @@ namespace Microsoft.AspNetCore.Testing #error Target frameworks need to be updated. #endif + // Test is named this way to be the lowest test in the alphabet, it relies on test ordering + [Fact] + public void ZzzzzzzEnsureThisIsTheLastTest() + { + Assert.True(Asserter.TestRan); + } + public static TheoryData> GetActionTestData => new TheoryData> { @@ -113,7 +120,6 @@ namespace Microsoft.AspNetCore.Testing public void Dispose() { - Assert.True(TestRan, "If this assertion fails, a conditional theory wasn't discovered."); } }