Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register Traits Properly #1181

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TUnit.Core/Attributes/TestMetadata/CategoryAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public class CategoryAttribute(string category) : TUnitAttribute, ITestDiscovery

public void OnTestDiscovery(DiscoveredTestContext discoveredTestContext)
{
discoveredTestContext.TestDetails.MutableCategories.Add(Category);
discoveredTestContext.AddCategory(Category);
}
}
17 changes: 0 additions & 17 deletions TUnit.Core/BeforeTestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,6 @@

namespace TUnit.Core;

public class TestRegisteredContext : BeforeTestContext
{
internal TestRegisteredContext(DiscoveredTest discoveredTest) : base(discoveredTest)
{
}

public void SetParallelLimiter(IParallelLimit parallelLimit)
{
DiscoveredTest.TestDetails.ParallelLimit = parallelLimit;
}

public void SkipTest(string reason)
{
DiscoveredTest.TestContext.SkipReason = reason;
}
}

public class BeforeTestContext
{
internal readonly DiscoveredTest DiscoveredTest;
Expand Down
5 changes: 5 additions & 0 deletions TUnit.Core/DiscoveredTestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public void AddProperty(string key, string value)
TestContext.TestDetails.InternalCustomProperties.Add(key, value);
}

public void AddCategory(string category)
{
TestContext.TestDetails.MutableCategories.Add(category);
}

public void SetDisplayName(string displayName)
{
TestContext.TestDetails.DisplayName = displayName;
Expand Down
20 changes: 20 additions & 0 deletions TUnit.Core/TestRegisteredContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using TUnit.Core.Interfaces;

namespace TUnit.Core;

public class TestRegisteredContext : BeforeTestContext
{
internal TestRegisteredContext(DiscoveredTest discoveredTest) : base(discoveredTest)
{
}

public void SetParallelLimiter(IParallelLimit parallelLimit)
{
DiscoveredTest.TestDetails.ParallelLimit = parallelLimit;
}

public void SkipTest(string reason)
{
DiscoveredTest.TestContext.SkipReason = reason;
}
}
4 changes: 2 additions & 2 deletions TUnit.Engine/Extensions/TestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ internal static TestNode ToTestNode(this TestContext testContext)
),

// Custom TUnit Properties
..testDetails.Categories.Select(x => new KeyValuePairStringProperty("Category", x)),
..testDetails.CustomProperties.Select(x => new KeyValuePairStringProperty(x.Key, x.Value)),
..testDetails.Categories.Select(category => new TestMetadataProperty(category, string.Empty)),
..testDetails.CustomProperties.Select(x => new TestMetadataProperty(x.Key, x.Value)),

// TRX Report Properties
new TrxFullyQualifiedTypeNameProperty(testDetails.ClassType.FullName!),
Expand Down
Loading