Skip to content

Commit f142731

Browse files
authored
feat: Hide SetCulture as Category (#558)
1 parent d048367 commit f142731

File tree

11 files changed

+52
-31
lines changed

11 files changed

+52
-31
lines changed

src/NetEvolve.Extensions.NUnit/Internal/CategoryIdBaseAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void IApplyToTest.ApplyToTest(Test test)
4343
return;
4444
}
4545

46-
base.ApplyToTest(test);
46+
ApplyToTest(test);
4747

4848
if (!string.IsNullOrEmpty(Id))
4949
{

src/NetEvolve.Extensions.XUnit/Internal/CategoryTraitDiscoverer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ IAttributeInfo traitAttribute
1919
yield break;
2020
}
2121

22-
var category = GetNamedArgument(traitAttribute, Internals.Category);
22+
var category = GetNamedArgument<string>(traitAttribute, Internals.Category);
2323
if (string.IsNullOrWhiteSpace(category))
2424
{
2525
yield break;
2626
}
2727

2828
yield return new KeyValuePair<string, string>(Internals.TestCategory, category!);
2929

30-
var id = GetNamedArgument(traitAttribute, Internals.Id);
30+
var id = GetNamedArgument<string>(traitAttribute, Internals.Id);
3131

3232
if (!string.IsNullOrWhiteSpace(id))
3333
{

src/NetEvolve.Extensions.XUnit/Internal/CultureAttributeBase.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,17 @@ public abstract class CultureAttributeBase : BeforeAfterTestAttribute, ITraitAtt
3434
/// </summary>
3535
public string Culture { get; }
3636

37+
/// <summary>
38+
/// As hidden category
39+
/// </summary>
40+
public bool AsHiddenCategory { get; }
41+
3742
/// <inheritdoc/>
38-
protected CultureAttributeBase(string category, string culture)
43+
protected CultureAttributeBase(string category, string culture, bool asHiddenCategory)
3944
{
4045
Category = category;
4146
Culture = culture;
47+
AsHiddenCategory = asHiddenCategory;
4248
_culture = CreateCultureInfo(culture);
4349
}
4450

src/NetEvolve.Extensions.XUnit/Internal/CultureTraitDiscoverer.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,25 @@ IAttributeInfo traitAttribute
1919
yield break;
2020
}
2121

22-
var category = GetNamedArgument(traitAttribute, Internals.Category);
22+
var asHiddenCategory = GetNamedArgument<bool>(
23+
traitAttribute,
24+
nameof(CultureAttributeBase.AsHiddenCategory)
25+
);
26+
if (asHiddenCategory)
27+
{
28+
yield break;
29+
}
30+
31+
var category = GetNamedArgument<string>(traitAttribute, Internals.Category);
2332
if (string.IsNullOrWhiteSpace(category))
2433
{
2534
yield break;
2635
}
2736

28-
var culture = GetNamedArgument(traitAttribute, Internals.Culture);
37+
var culture = GetNamedArgument<string>(traitAttribute, Internals.Culture);
2938
yield return new KeyValuePair<string, string>(category!, culture!);
3039

31-
if (category!.Equals("SetCulture", System.StringComparison.Ordinal))
40+
if (category!.Equals("SetCulture", StringComparison.Ordinal))
3241
{
3342
yield return new KeyValuePair<string, string>("SetUICulture", culture!);
3443
}

src/NetEvolve.Extensions.XUnit/Internal/DiscovererBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ public abstract IEnumerable<KeyValuePair<string, string>> GetTraits(
1616
IAttributeInfo traitAttribute
1717
);
1818

19-
private protected static string? GetNamedArgument(
19+
private protected static TValue? GetNamedArgument<TValue>(
2020
IAttributeInfo traitAttribute,
2121
string argumentName
2222
)
2323
{
2424
try
2525
{
26-
return traitAttribute.GetNamedArgument<string>(argumentName);
26+
return traitAttribute.GetNamedArgument<TValue>(argumentName);
2727
}
2828
catch (ArgumentException)
2929
{
3030
// Ignore
3131
}
32-
return null;
32+
return default;
3333
}
3434
}

src/NetEvolve.Extensions.XUnit/SetCultureAttribute.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,24 @@ public sealed class SetCultureAttribute : CultureAttributeBase
2727
/// Initializes a new instance of the <see cref="SetCultureAttribute"/> class.
2828
/// </summary>
2929
public SetCultureAttribute()
30-
: this(string.Empty, string.Empty) { }
30+
: this(string.Empty, string.Empty, false) { }
3131

3232
/// <summary>
3333
/// Initializes a new instance of the <see cref="SetCultureAttribute"/> class.
3434
/// </summary>
3535
/// <param name="culture">Culture to use.</param>
36-
public SetCultureAttribute(string culture)
37-
: this(culture, culture) { }
36+
/// <param name="asHiddenCategory">If <see langword="true"/>, this test will be hidden from test explorer.</param>
37+
public SetCultureAttribute(string culture, bool asHiddenCategory = false)
38+
: this(culture, culture, asHiddenCategory) { }
3839

3940
/// <summary>
4041
/// Initializes a new instance of the <see cref="SetCultureAttribute"/> class.
4142
/// </summary>
4243
/// <param name="culture">Culture to use.</param>
4344
/// <param name="uiCulture">UI culture to use.</param>
44-
public SetCultureAttribute(string culture, string? uiCulture)
45-
: base("SetCulture", culture)
45+
/// <param name="asHiddenCategory">If <see langword="true"/>, this test will be hidden from test explorer.</param>
46+
public SetCultureAttribute(string culture, string? uiCulture, bool asHiddenCategory = false)
47+
: base("SetCulture", culture, asHiddenCategory)
4648
{
4749
if (string.IsNullOrWhiteSpace(uiCulture))
4850
{

src/NetEvolve.Extensions.XUnit/SetUICultureAttribute.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ public sealed class SetUICultureAttribute : CultureAttributeBase
1717
/// Initializes a new instance of the <see cref="SetUICultureAttribute"/> class.
1818
/// </summary>
1919
public SetUICultureAttribute()
20-
: base("SetUICulture", string.Empty) { }
20+
: base("SetUICulture", string.Empty, false) { }
2121

2222
/// <summary>
2323
/// Initializes a new instance of the <see cref="SetUICultureAttribute"/> class.
2424
/// </summary>
2525
/// <param name="culture">UI culture to use.</param>
26-
public SetUICultureAttribute(string culture)
27-
: base("SetUICulture", culture) { }
26+
/// <param name="asHiddenCategory">If <see langword="true"/>, this test will be hidden from test explorer.</param>
27+
public SetUICultureAttribute(string culture, bool asHiddenCategory = false)
28+
: base("SetUICulture", culture, asHiddenCategory) { }
2829

2930
private protected override bool SetCulture(CultureInfo culture)
3031
{

tests/NetEvolve.Extensions.TUnit.Tests.Unit/AttributeTestsBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public abstract class AttributeTestsBase
1010
/// </summary>
1111
/// <param name="methodName">Name of the caller Method</param>
1212
/// <returns>List of <see cref="KeyValuePair{TKey,TValue}"/></returns>
13-
protected IEnumerable<KeyValuePair<string, string>> GetTraits(
13+
protected static IEnumerable<KeyValuePair<string, string>> GetTraits(
1414
[CallerMemberName] string? methodName = null
1515
)
1616
{

tests/NetEvolve.Extensions.XUnit.Tests.PublicApi/_snapshots/DotNet6_0/PublicApiTests.PublicApi_HasNotChanged_Expected.verified.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@
6363
public sealed class SetCultureAttribute : NetEvolve.Extensions.XUnit.Internal.CultureAttributeBase
6464
{
6565
public SetCultureAttribute() { }
66-
public SetCultureAttribute(string culture) { }
67-
public SetCultureAttribute(string culture, string? uiCulture) { }
66+
public SetCultureAttribute(string culture, bool asHiddenCategory = false) { }
67+
public SetCultureAttribute(string culture, string? uiCulture, bool asHiddenCategory = false) { }
6868
public string? UICulture { get; }
6969
public override void After(System.Reflection.MethodInfo methodUnderTest) { }
7070
public override void Before(System.Reflection.MethodInfo methodUnderTest) { }
7171
}
7272
public sealed class SetUICultureAttribute : NetEvolve.Extensions.XUnit.Internal.CultureAttributeBase
7373
{
7474
public SetUICultureAttribute() { }
75-
public SetUICultureAttribute(string culture) { }
75+
public SetUICultureAttribute(string culture, bool asHiddenCategory = false) { }
7676
}
7777
public sealed class UnitTestAttribute : NetEvolve.Extensions.XUnit.Internal.CategoryTraitBaseAttribute
7878
{
@@ -115,7 +115,8 @@ namespace NetEvolve.Extensions.XUnit.Internal
115115
[Xunit.Sdk.TraitDiscoverer("NetEvolve.Extensions.XUnit.Internal.CultureTraitDiscoverer", "NetEvolve.Extensions.XUnit")]
116116
public abstract class CultureAttributeBase : Xunit.Sdk.BeforeAfterTestAttribute, Xunit.Sdk.ITraitAttribute
117117
{
118-
protected CultureAttributeBase(string category, string culture) { }
118+
protected CultureAttributeBase(string category, string culture, bool asHiddenCategory) { }
119+
public bool AsHiddenCategory { get; }
119120
public string Category { get; }
120121
public string Culture { get; }
121122
public override void After(System.Reflection.MethodInfo methodUnderTest) { }

tests/NetEvolve.Extensions.XUnit.Tests.PublicApi/_snapshots/DotNet8_0/PublicApiTests.PublicApi_HasNotChanged_Expected.verified.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@
6363
public sealed class SetCultureAttribute : NetEvolve.Extensions.XUnit.Internal.CultureAttributeBase
6464
{
6565
public SetCultureAttribute() { }
66-
public SetCultureAttribute(string culture) { }
67-
public SetCultureAttribute(string culture, string? uiCulture) { }
66+
public SetCultureAttribute(string culture, bool asHiddenCategory = false) { }
67+
public SetCultureAttribute(string culture, string? uiCulture, bool asHiddenCategory = false) { }
6868
public string? UICulture { get; }
6969
public override void After(System.Reflection.MethodInfo methodUnderTest) { }
7070
public override void Before(System.Reflection.MethodInfo methodUnderTest) { }
7171
}
7272
public sealed class SetUICultureAttribute : NetEvolve.Extensions.XUnit.Internal.CultureAttributeBase
7373
{
7474
public SetUICultureAttribute() { }
75-
public SetUICultureAttribute(string culture) { }
75+
public SetUICultureAttribute(string culture, bool asHiddenCategory = false) { }
7676
}
7777
public sealed class UnitTestAttribute : NetEvolve.Extensions.XUnit.Internal.CategoryTraitBaseAttribute
7878
{
@@ -115,7 +115,8 @@ namespace NetEvolve.Extensions.XUnit.Internal
115115
[Xunit.Sdk.TraitDiscoverer("NetEvolve.Extensions.XUnit.Internal.CultureTraitDiscoverer", "NetEvolve.Extensions.XUnit")]
116116
public abstract class CultureAttributeBase : Xunit.Sdk.BeforeAfterTestAttribute, Xunit.Sdk.ITraitAttribute
117117
{
118-
protected CultureAttributeBase(string category, string culture) { }
118+
protected CultureAttributeBase(string category, string culture, bool asHiddenCategory) { }
119+
public bool AsHiddenCategory { get; }
119120
public string Category { get; }
120121
public string Culture { get; }
121122
public override void After(System.Reflection.MethodInfo methodUnderTest) { }

0 commit comments

Comments
 (0)