-
-
Notifications
You must be signed in to change notification settings - Fork 110
feat: add SharedDataSources helper for custom data source attributes #4564
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
Conversation
Add a public SharedDataSources class that allows users to implement custom data source attributes with the same sharing behavior (SharedType and Key) as ClassDataSourceAttribute. This addresses the request in discussion #4536 for a way to extend or reuse the functionality from ClassDataSources without exposing internal implementation details. The API provides multiple overloads: - Generic with new() constraint for simple default construction - Generic with factory for custom initialization - Non-generic for runtime type scenarios Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Replace ArgumentNullException.ThrowIfNull with null-coalescing throw pattern - Add null-forgiving operators to TestDataContainer return values - Add null-forgiving operators to key parameter after null check Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryAdds a new public SharedDataSources helper class for custom data source attributes with shared instance management. Critical Issues1. Missing AOT Compatibility AnnotationsThe new public API is missing [DynamicallyAccessedMembers] annotations required for Native AOT compatibility (TUnit rule #5). This violates the mandatory rules in CLAUDE.md. Problem: Non-generic overloads accept Type parameters without AOT annotations:
Required Fix: Add [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)] to all Type parameters that will be instantiated. Reference: See TUnit.Core/Attributes/TestData/ClassDataSourceAttribute.cs:18-67 and TUnit.Core/Attributes/TestData/ClassDataSources.cs:21,42,55,69,74 for the exact pattern. 2. Missing Public API SnapshotsThis PR adds a new public class to TUnit.Core but does not update the .verified.txt snapshot files (TUnit rule #2). Required Fix: Run the public API snapshot tests and commit the updated .verified.txt files in TUnit.PublicAPI/ directory. NEVER commit .received.txt files - only .verified.txt. SuggestionsLines 146, 155, 166, 175, 186, 195 use hardcoded strings in ArgumentNullException. Consider using nameof() in the message for better maintainability. VerdictREQUEST CHANGES - Critical AOT compatibility and snapshot test issues must be fixed before merge. |
Add SharedDataSources class to the public API verified files for DotNet8_0, DotNet9_0, and DotNet10_0. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryAdds a new public Critical IssuesMissing AOT Compatibility AnnotationsThe non-generic Problem locations:
Required fix: Add the annotation to all public static object? GetOrCreate(
SharedType sharedType,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors |
DynamicallyAccessedMemberTypes.NonPublicConstructors |
DynamicallyAccessedMemberTypes.PublicProperties |
DynamicallyAccessedMemberTypes.NonPublicProperties)]
Type type,
DataGeneratorMetadata dataGeneratorMetadata,
string? key,
Func<object?> factory)Reference patterns:
This is critical for Native AOT compatibility per CLAUDE.md mandatory rules. Previous Review StatusThe public API snapshot issue has been resolved ✅ - all three Verdict |
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryAdds a public SharedDataSources helper class to allow custom data source attributes with the same sharing behavior (SharedType and Key) as ClassDataSourceAttribute. Critical Issues1. Missing AOT Annotations ❌Rule #5 Violation: AOT Compatible The non-generic Location: TUnit.Core/SharedDataSources.cs:107, 128 Required fix: Add annotations matching the internal implementation in ClassDataSources.cs:74: public static object? GetOrCreate(
SharedType sharedType,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
Type type,
DataGeneratorMetadata dataGeneratorMetadata,
string? key,
Func<object?> factory)
public static object? GetOrCreate(
SharedType sharedType,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
Type type,
Type? testClassType,
string? key,
Func<object?> factory)2. Potential NullReferenceException
|
Address PR review feedback: - Add [DynamicallyAccessedMembers] attribute to Type parameters in non-generic GetOrCreate overloads for Native AOT compatibility - Update public API snapshots with the new signatures Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryAdds a new public SharedDataSources helper class that allows users to implement custom data source attributes with the same sharing behavior (SharedType and Key) as ClassDataSourceAttribute. Critical IssuesNone found ✅ Previous Review StatusAll previous issues have been addressed:
Code ReviewThe implementation looks solid:
No TUnit rule violations detected:
Verdict✅ APPROVE - All critical issues resolved, implementation follows TUnit best practices |
The PublicApiGenerator doesn't render DynamicallyAccessedMembers attributes in netstandard2.0/net472 target frameworks. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryThis PR adds a new public SharedDataSources helper class that allows users to implement custom data source attributes with the same sharing behavior as ClassDataSourceAttribute. Critical IssuesNone found ✅ Suggestions1. Consider adding a test to verify the API works as expectedThe PR description mentions testing the API, but I do not see any new test files in the diff. Consider adding a test that demonstrates a custom data source attribute using the new SharedDataSources API and verification that the sharing behavior works correctly. Example test location: TUnit.TestProject/CustomSharedDataSourceTests.cs 2. Documentation opportunityThis is a great extensibility point. Consider adding documentation in docs/docs/customization-extensibility/ showing how users can leverage this new API to create custom data source attributes with sharing behavior. AnalysisWhat This PR Does Well:
TUnit Rules Compliance:
No concerns regarding:
Verdict✅ APPROVE - No critical issues. The suggestions are optional enhancements for discoverability and verification. |
This enables cleaner API calls: - SharedDataSources.GetOrCreate<T>(SharedType.PerTestSession) - SharedDataSources.GetOrCreate<T>(SharedType.Keyed, key: "mykey") Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary
SharedDataSourcesclass that allows users to implement custom data source attributes with the same sharing behavior (SharedTypeandKey) asClassDataSourceAttributeClassDataSources,TestDataContainer)API
Usage Example
Test plan
🤖 Generated with Claude Code