Fix ConditionalFact and ConditionalTheory (dotnet/extensions#2241)
\n\nCommit migrated from ae9d51ffeb
This commit is contained in:
parent
e1974283f0
commit
72dc1409d6
|
|
@ -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
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<TTestCase> OrderTestCases<TTestCase>(IEnumerable<TTestCase> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<ConditionalFactTest.ConditionalFactAsserter>
|
||||
{
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<ConditionalTheoryTest.ConditionalTheoryAsserter>
|
||||
{
|
||||
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<Func<int, int>> GetActionTestData
|
||||
=> new TheoryData<Func<int, int>>
|
||||
{
|
||||
|
|
@ -113,7 +120,6 @@ namespace Microsoft.AspNetCore.Testing
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
Assert.True(TestRan, "If this assertion fails, a conditional theory wasn't discovered.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue