| | | 1 | | using Xunit.Abstractions; |
| | | 2 | | using Xunit.Sdk; |
| | | 3 | | |
| | | 4 | | namespace ArturRios.Util.Test.Attributes; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Trait discoverer that reads the <see cref="CustomFactAttribute.TestType"/> carried by a custom test attribute |
| | | 8 | | /// and exposes it as the <c>Category</c> trait, enabling filters such as <c>dotnet test --filter "Category=Unit"</c>. |
| | | 9 | | /// </summary> |
| | | 10 | | public class TestTypeTraitDiscoverer : ITraitDiscoverer |
| | | 11 | | { |
| | | 12 | | /// <summary>The trait key under which the test type is published.</summary> |
| | | 13 | | public const string TraitName = "Category"; |
| | | 14 | | |
| | | 15 | | /// <inheritdoc /> |
| | | 16 | | public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute) |
| | 4 | 17 | | { |
| | 4 | 18 | | var testType = traitAttribute.GetNamedArgument<TestType>(nameof(CustomFactAttribute.TestType)); |
| | | 19 | | |
| | 4 | 20 | | yield return new KeyValuePair<string, string>(TraitName, testType.ToString()); |
| | 4 | 21 | | } |
| | | 22 | | } |