|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
4 | 4 | using System;
|
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Linq; |
| 7 | +using Microsoft.DotNet.XUnitExtensions; |
5 | 8 | using Xunit.Sdk;
|
6 | 9 |
|
7 | 10 | namespace Xunit
|
8 | 11 | {
|
9 | 12 | /// <summary>
|
10 | 13 | /// Apply this attribute to your test method to specify an active issue.
|
11 | 14 | /// </summary>
|
| 15 | +#if !USES_XUNIT_3 |
12 | 16 | [TraitDiscoverer("Microsoft.DotNet.XUnitExtensions.ActiveIssueDiscoverer", "Microsoft.DotNet.XUnitExtensions")]
|
| 17 | +#endif |
13 | 18 | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
|
14 | 19 | public class ActiveIssueAttribute : Attribute, ITraitAttribute
|
15 | 20 | {
|
| 21 | +#if USES_XUNIT_3 |
| 22 | + private readonly IEnumerable<object> _ctorArgs; |
| 23 | +#endif |
| 24 | + |
16 | 25 | public Type CalleeType { get; private set; }
|
17 | 26 | public string[] ConditionMemberNames { get; private set; }
|
18 | 27 |
|
19 |
| - public ActiveIssueAttribute(string issue, TestPlatforms platforms) { } |
20 |
| - public ActiveIssueAttribute(string issue, TargetFrameworkMonikers framework) { } |
21 |
| - public ActiveIssueAttribute(string issue, TestRuntimes runtimes) { } |
22 |
| - public ActiveIssueAttribute(string issue, TestPlatforms platforms = TestPlatforms.Any, TargetFrameworkMonikers framework = TargetFrameworkMonikers.Any, TestRuntimes runtimes = TestRuntimes.Any) { } |
| 28 | + public ActiveIssueAttribute(string issue, TestPlatforms platforms) |
| 29 | + { |
| 30 | +#if USES_XUNIT_3 |
| 31 | + _ctorArgs = [issue, platforms]; |
| 32 | +#endif |
| 33 | + } |
| 34 | + |
| 35 | + public ActiveIssueAttribute(string issue, TargetFrameworkMonikers framework) |
| 36 | + { |
| 37 | +#if USES_XUNIT_3 |
| 38 | + _ctorArgs = [issue, framework]; |
| 39 | +#endif |
| 40 | + } |
| 41 | + |
| 42 | + public ActiveIssueAttribute(string issue, TestRuntimes runtimes) |
| 43 | + { |
| 44 | +#if USES_XUNIT_3 |
| 45 | + _ctorArgs = [issue, runtimes]; |
| 46 | +#endif |
| 47 | + } |
| 48 | + |
| 49 | + public ActiveIssueAttribute(string issue, TestPlatforms platforms = TestPlatforms.Any, TargetFrameworkMonikers framework = TargetFrameworkMonikers.Any, TestRuntimes runtimes = TestRuntimes.Any) |
| 50 | + { |
| 51 | +#if USES_XUNIT_3 |
| 52 | + _ctorArgs = [issue, platforms, framework, runtimes]; |
| 53 | +#endif |
| 54 | + } |
| 55 | + |
23 | 56 | public ActiveIssueAttribute(string issue, Type calleeType, params string[] conditionMemberNames)
|
24 | 57 | {
|
| 58 | +#if USES_XUNIT_3 |
| 59 | + _ctorArgs = [issue, calleeType, conditionMemberNames]; |
| 60 | +#endif |
25 | 61 | CalleeType = calleeType;
|
26 | 62 | ConditionMemberNames = conditionMemberNames;
|
27 | 63 | }
|
| 64 | + |
| 65 | +#if USES_XUNIT_3 |
| 66 | + public IReadOnlyCollection<KeyValuePair<string, string>> GetTraits() |
| 67 | + { |
| 68 | + return DiscovererHelpers.EvaluateArguments(_ctorArgs, XunitConstants.Failing).ToArray(); |
| 69 | + } |
| 70 | +#endif |
28 | 71 | }
|
29 | 72 | }
|
0 commit comments