Skip to content

feat: add IKeyedDataSource interface for keyed shared fixtures#4799

Merged
thomhurst merged 2 commits intomainfrom
feat/ikeyed-data-source
Feb 14, 2026
Merged

feat: add IKeyedDataSource interface for keyed shared fixtures#4799
thomhurst merged 2 commits intomainfrom
feat/ikeyed-data-source

Conversation

@thomhurst
Copy link
Owner

Summary

  • Adds IKeyedDataSource interface to TUnit.Core.Interfaces with a string Key { get; set; } property
  • Sets the key inside the factory lambda in both ClassDataSources and SharedDataSources — after Activator.CreateInstance() but before IAsyncInitializer.InitializeAsync() runs
  • Eliminates the need for per-key boilerplate subclasses when using SharedType.Keyed

Closes #4764

Test plan

  • TUnit.Core builds with 0 errors
  • TUnit.TestProject builds with 0 errors (new KeyedDataSourceTests with 4 tests)
  • TUnit.Engine.Tests builds with 0 errors (new KeyedDataSourceTests engine test)
  • CI: unit tests pass
  • CI: engine tests pass (verifies key is set to "alpha"/"beta", key available during InitializeAsync, same key returns same instance)

🤖 Generated with Claude Code

Allow ClassDataSource fixtures using SharedType.Keyed to discover their
sharing key at runtime. The Key property is set after construction but
before IAsyncInitializer.InitializeAsync(), eliminating the need for
per-key boilerplate subclasses.

Closes #4764

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude
Copy link
Contributor

claude bot commented Feb 14, 2026

Code Review

I found one issue that needs attention:

Issues Found

  1. Missing PublicAPI Snapshot Tests - The PR adds a new public interface IKeyedDataSource but doesn't include the required .verified.txt files from running dotnet test TUnit.PublicAPI. This is required by CLAUDE.md Rule 2.

What I Checked

CLAUDE.md Compliance - Reviewed against all mandatory rules
Bug Detection - Scanned for logic errors, compilation issues, and security vulnerabilities
Code Quality - The implementation is clean and straightforward

Overall Assessment

The feature implementation looks solid. The IKeyedDataSource interface is well-designed with clear XML documentation, and the integration into ClassDataSources and SharedDataSources is implemented correctly. The key-setting happens at the right time (after instantiation but before InitializeAsync), and the code properly handles both generic and non-generic paths.

Once the snapshot tests are run and the .verified.txt files are committed, this will be good to merge.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@thomhurst thomhurst merged commit 2da2ac3 into main Feb 14, 2026
12 of 14 checks passed
@thomhurst thomhurst deleted the feat/ikeyed-data-source branch February 14, 2026 20:40
This was referenced Feb 16, 2026
This was referenced Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: key-aware ClassDataSource via IKeyedClassDataSource interface

1 participant