Skip to content

Commit 00c1d66

Browse files
authored
feat: Added Feature TestGroup (#692)
* feat: Added Feature `TestGroup` * fix(style): Formatting updated
1 parent 1047ec0 commit 00c1d66

File tree

37 files changed

+344
-14
lines changed

37 files changed

+344
-14
lines changed

src/NetEvolve.Extensions.MSTest/Internals.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,9 @@ internal static class Internals
9999
/// CodedUITests
100100
/// </summary>
101101
public const string CodedUITest = nameof(CodedUITest);
102+
103+
/// <summary>
104+
/// TestGroup
105+
/// </summary>
106+
public const string TestGroup = nameof(TestGroup);
102107
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace NetEvolve.Extensions.MSTest;
2+
3+
using System;
4+
using NetEvolve.Extensions.MSTest.Internal;
5+
6+
/// <summary>
7+
/// Attribute used to decorate a test class or method as <b>TestGroup</b>, with explicit Id.
8+
/// </summary>
9+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
10+
public sealed class TestGroupAttribute : TestCategoryWithIdBaseAttribute
11+
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="UserStoryAttribute"/> class.
14+
/// </summary>
15+
/// <param name="id">UserStory Id</param>
16+
public TestGroupAttribute(string id)
17+
: base(Internals.TestGroup, id) { }
18+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace NetEvolve.Extensions.NUnit.Internal;
22

3+
using System.Xml.Linq;
34
using global::NUnit.Framework;
45
using global::NUnit.Framework.Interfaces;
56
using global::NUnit.Framework.Internal;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
namespace NetEvolve.Extensions.NUnit.Internal;
2+
3+
using global::NUnit.Framework;
4+
using global::NUnit.Framework.Interfaces;
5+
using global::NUnit.Framework.Internal;
6+
7+
/// <summary>
8+
/// Abstract class implementation.
9+
/// </summary>
10+
public abstract class NamedCategoryBaseAttribute : NUnitAttribute, IApplyToTest
11+
{
12+
/// <summary>
13+
/// Gets the category value of the trait.
14+
/// </summary>
15+
public string Category { get; }
16+
17+
/// <summary>
18+
/// Gets the Id
19+
/// </summary>
20+
public string Id { get; }
21+
22+
/// <summary>
23+
/// Initializes a new instance of the <see cref="CategoryIdBaseAttribute"/> class.
24+
/// </summary>
25+
/// <param name="category">Category</param>
26+
/// <param name="id">Id</param>
27+
protected NamedCategoryBaseAttribute(string category, string id)
28+
{
29+
Category = category;
30+
Id = id;
31+
}
32+
33+
/// <inheritdoc/>
34+
public void ApplyToTest(Test test)
35+
{
36+
if (test is null)
37+
{
38+
return;
39+
}
40+
41+
if (!string.IsNullOrEmpty(Id))
42+
{
43+
test.Properties.Add(Category, Id!);
44+
}
45+
}
46+
}

src/NetEvolve.Extensions.NUnit/Internals.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,9 @@ internal static class Internals
9999
/// CodedUITests
100100
/// </summary>
101101
public const string CodedUITest = nameof(CodedUITest);
102+
103+
/// <summary>
104+
/// TestGroup
105+
/// </summary>
106+
public const string TestGroup = nameof(TestGroup);
102107
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace NetEvolve.Extensions.NUnit;
2+
3+
using System;
4+
using NetEvolve.Extensions.NUnit.Internal;
5+
6+
/// <summary>
7+
/// Attribute used to decorate a test class or method as <b>TestGroup</b>, with explicit id
8+
/// </summary>
9+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
10+
public sealed class TestGroupAttribute : NamedCategoryBaseAttribute
11+
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="TestGroupAttribute"/> class.
14+
/// </summary>
15+
/// <param name="id">TestGroup Name</param>
16+
public TestGroupAttribute(string id)
17+
: base(Internals.TestGroup, id) { }
18+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
namespace NetEvolve.Extensions.TUnit.Internal;
2+
3+
using global::TUnit.Core.Interfaces;
4+
5+
/// <summary>
6+
/// Abstract implementation.
7+
/// </summary>
8+
public abstract class NamedCategoryTraitBaseAttribute : Attribute, ITestDiscoveryEventReceiver
9+
{
10+
/// <summary>
11+
/// Gets the category value of the trait.
12+
/// </summary>
13+
public string Category { get; }
14+
15+
/// <summary>
16+
/// Gets the Id
17+
/// </summary>
18+
public string Id { get; }
19+
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="NamedCategoryTraitBaseAttribute"/> class.
22+
/// </summary>
23+
/// <param name="category">Category</param>
24+
/// <param name="id">Id</param>
25+
protected NamedCategoryTraitBaseAttribute(string category, string id)
26+
{
27+
Category = category;
28+
Id = id;
29+
}
30+
31+
/// <inheritdoc/>
32+
public void OnTestDiscovery(DiscoveredTestContext discoveredTestContext)
33+
{
34+
if (discoveredTestContext is null)
35+
{
36+
return;
37+
}
38+
39+
if (!string.IsNullOrWhiteSpace(Id))
40+
{
41+
discoveredTestContext.AddProperty(Category, Id);
42+
}
43+
}
44+
}

src/NetEvolve.Extensions.TUnit/Internals.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,9 @@ internal static class Internals
8484
/// CodedUITest
8585
/// </summary>
8686
public const string CodedUITest = nameof(CodedUITest);
87+
88+
/// <summary>
89+
/// TestGroup
90+
/// </summary>
91+
public const string TestGroup = nameof(TestGroup);
8792
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace NetEvolve.Extensions.TUnit;
2+
3+
using System;
4+
using NetEvolve.Extensions.TUnit.Internal;
5+
6+
/// <summary>
7+
/// Attribute used to decorate a test class or method as <b>TestGroup</b>, with explicit id
8+
/// </summary>
9+
[AttributeUsage(
10+
AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method,
11+
AllowMultiple = true
12+
)]
13+
public sealed class TestGroupAttribute : NamedCategoryTraitBaseAttribute
14+
{
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="TestGroupAttribute"/> class.
17+
/// </summary>
18+
/// <param id="id">TestGroup Name</param>
19+
public TestGroupAttribute(string id)
20+
: base(Internals.TestGroup, id) { }
21+
}

src/NetEvolve.Extensions.XUnit.V3/Internals.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,9 @@ internal static class Internals
109109
/// CodedUITest
110110
/// </summary>
111111
public const string CodedUITest = nameof(CodedUITest);
112+
113+
/// <summary>
114+
/// TestGroup
115+
/// </summary>
116+
public const string TestGroup = nameof(TestGroup);
112117
}

0 commit comments

Comments
 (0)