Skip to content

Commit 6991044

Browse files
Work around PreenumerateTheories
1 parent 88fb58b commit 6991044

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/TestingUtils/Microsoft.AspNetCore.Testing/src/xunit/ConditionalTheoryDiscoverer.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,25 @@ public ConditionalTheoryDiscoverer(IMessageSink diagnosticMessageSink)
1414
{
1515
}
1616

17+
private sealed class OptionsWithPreEnumerationEnabled : ITestFrameworkDiscoveryOptions
18+
{
19+
private const string PreEnumerateTheories = "xunit.discovery.PreEnumerateTheories";
20+
21+
private readonly ITestFrameworkDiscoveryOptions _original;
22+
23+
public OptionsWithPreEnumerationEnabled(ITestFrameworkDiscoveryOptions original)
24+
=> _original = original;
25+
26+
public TValue GetValue<TValue>(string name)
27+
=> (name == PreEnumerateTheories) ? (TValue)(object)true : _original.GetValue<TValue>(name);
28+
29+
public void SetValue<TValue>(string name, TValue value)
30+
=> _original.SetValue(name, value);
31+
}
32+
33+
public override IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute)
34+
=> base.Discover(new OptionsWithPreEnumerationEnabled(discoveryOptions), testMethod, theoryAttribute);
35+
1736
protected override IEnumerable<IXunitTestCase> CreateTestCasesForTheory(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute)
1837
{
1938
var skipReason = testMethod.EvaluateSkipConditions();

0 commit comments

Comments
 (0)