Generate the TestContext property for record test classes - #1866
Merged
Merged
Conversation
A record is a class, so it is a legal MSTest test class, but only ClassDeclarationSyntax passed the syntax filter. A [UsesVerify] [TestClass] partial record compiled and then failed at run time with the misleading "TestContext is null. Ensure test class has a `[UsesVerify]` attribute". Records are now eligible, and since a partial declaration has to repeat the kind of the type, the emitter takes the keyword from the declaration rather than always writing `class`. The same applies to the enclosing types, so GetParentClasses also handles a record struct parent, whose kind is two tokens. Record structs stay ineligible as targets: [UsesVerify] is only valid on a class.
This was referenced Aug 26, 2026
26 tasks
tom-wolfe
pushed a commit
to nschema-org/NSchema
that referenced
this pull request
Sep 11, 2026
Updated [editorconfig](https://github.com/editorconfig/editorconfig-core-net) from 0.17.0 to 0.18.0. <details> <summary>Release notes</summary> _Sourced from [editorconfig's releases](https://github.com/editorconfig/editorconfig-core-net/releases)._ ## 0.18.0 editorconfig/editorconfig-core-net@0.17.0...0.18.0 ### [View the full list of issues and PRs](https://github.com/editorconfig/editorconfig-core-net/issues?utf8=%E2%9C%93&q=label%3Av0.18.0) Commits viewable in [compare view](editorconfig/editorconfig-core-net@0.17.0...0.18.0). </details> Updated [Microsoft.CodeAnalysis.Analyzers](https://github.com/dotnet/roslyn) from 5.6.0 to 5.9.0. <details> <summary>Release notes</summary> _Sourced from [Microsoft.CodeAnalysis.Analyzers's releases](https://github.com/dotnet/roslyn/releases)._ No release notes found for this version range. Commits viewable in [compare view](https://github.com/dotnet/roslyn/commits). </details> Updated Microsoft.CodeAnalysis.CSharp from 5.6.0 to 5.9.0. Updated [Microsoft.Testing.Extensions.CodeCoverage](https://github.com/microsoft/codecoverage) from 18.10.0 to 18.11.0. <details> <summary>Release notes</summary> _Sourced from [Microsoft.Testing.Extensions.CodeCoverage's releases](https://github.com/microsoft/codecoverage/releases)._ No release notes found for this version range. Commits viewable in [compare view](https://github.com/microsoft/codecoverage/commits). </details> Updated [Microsoft.Testing.Extensions.TrxReport](https://github.com/microsoft/testfx) from 2.3.3 to 2.4.0. <details> <summary>Release notes</summary> _Sourced from [Microsoft.Testing.Extensions.TrxReport's releases](https://github.com/microsoft/testfx/releases)._ No release notes found for this version range. Commits viewable in [compare view](https://github.com/microsoft/testfx/commits). </details> Updated [ritten](https://github.com/ritten-org/Ritten) from 0.10.0 to 0.11.0. <details> <summary>Release notes</summary> _Sourced from [ritten's releases](https://github.com/ritten-org/Ritten/releases)._ ## 0.11.0 ### Added - Added shell auto-completion support through the `completion` command. ### Fixed - **`prepare` no longer describes one version twice.** A version whose packages had shipped in part was read as one that had never shipped at all, so `prepare` staged it a second time. - **Notes written after a `prepare` join the entry they belong to.** Preparing a version the changelog already has an entry for now adds the unreleased notes to that entry rather than giving the version a second heading. Commits viewable in [compare view](ritten-org/Ritten@v0.10.0...v0.11.0). </details> Updated [Testcontainers.PostgreSql](https://github.com/testcontainers/testcontainers-dotnet) from 4.14.0 to 4.15.0. <details> <summary>Release notes</summary> _Sourced from [Testcontainers.PostgreSql's releases](https://github.com/testcontainers/testcontainers-dotnet/releases)._ ## 4.15.0 # What's Changed The NuGet packages for this release have been attested for supply chain security using [`actions/attest`](https://github.com/actions/attest). This confirms the integrity and provenance of the artifacts and helps ensure they can be trusted: [#45594466](https://github.com/testcontainers/testcontainers-dotnet/attestations/45594466). ## 🚀 Features * feat: Add options to the Docker Compose up and down command (#1759) @HofmeisterAn * feat: Add QuestDB module (#1618) @FortuneN, @HofmeisterAn * feat: Add Compose support (#1750) @HofmeisterAn * fix(Couchbase): Treat an already provisioned cluster as configured (#1736) @arnelirobles, @HofmeisterAn * feat: Retry transient Docker image pull failures (#1734) @thomhurst, @HofmeisterAn * chore(deps): Split Dependabot NuGet jobs and bump test dependencies (#1746) @HofmeisterAn * feat(MongoDb): Resolve the MongoDb shell file path once (#1745) @HofmeisterAn ## 🐛 Bug Fixes * fix: Detach from the container output before stopping or removing it (#1755) @HofmeisterAn * fix(GCloud): Bump test image version (#1752) @HofmeisterAn ## 📖 Documentation * docs: Update CONTRIBUTING.md (#1744) @HofmeisterAn ## 🧹 Housekeeping * chore: Improve null check, test typing, and IDE settings (#1757) @HofmeisterAn * fix(GCloud): Bump test image version (#1752) @HofmeisterAn * chore: Resolve Sonar findings (#1751) @HofmeisterAn * chore(deps): Revert Dependabot NuGet jobs (#1748) @HofmeisterAn * feat: Prepare next release cycle (4.15.0) (#1742) @HofmeisterAn ## 📦 Dependency Updates * chore(deps): Bump mkdocs-material from 9.7.2 to 9.7.7 (#1758) [@dependabot[bot]](https://github.com/apps/dependabot) * chore(deps): Bump the actions group with 5 updates (#1754) [@dependabot[bot]](https://github.com/apps/dependabot) * chore(deps): Bump the actions group across 1 directory with 7 updates (#1747) [@dependabot[bot]](https://github.com/apps/dependabot) * chore(deps): Revert Dependabot NuGet jobs (#1748) @HofmeisterAn * chore(deps): Split Dependabot NuGet jobs and bump test dependencies (#1746) @HofmeisterAn Commits viewable in [compare view](testcontainers/testcontainers-dotnet@4.14.0...4.15.0). </details> Updated [Verify.XunitV3](https://github.com/VerifyTests/Verify) from 31.28.0 to 32.0.0. <details> <summary>Release notes</summary> _Sourced from [Verify.XunitV3's releases](https://github.com/VerifyTests/Verify/releases)._ ## 32.0.0 - [x] [#1832](VerifyTests/Verify#1832) Add Inline snpashot support - [x] [#1835](VerifyTests/Verify#1835) Add SettingsTask.AddContext - [x] [#1847](VerifyTests/Verify#1847) Honor explicit DefaultValueHandling for bools - [x] [#1850](VerifyTests/Verify#1850) Stray extension-less snapshot file crashes every run of its test - [x] [#1851](VerifyTests/Verify#1851) Static UniqueForTargetFramework(Assembly) overloads ignore the assembly passed to them - [x] [#1852](VerifyTests/Verify#1852) Appended files skip scrubbing and newline normalization when a stream converter is registered - [x] [#1853](VerifyTests/Verify#1853) IgnoreParameters() ignore-all sentinel is lost when combined with another ignore source - [x] [#1854](VerifyTests/Verify#1854) Format UTC offsets with the invariant culture - [x] [#1855](VerifyTests/Verify#1855) Format UTC offsets with invariant culture - [x] [#1856](VerifyTests/Verify#1856) Use ticks to decide date precision - [x] [#1857](VerifyTests/Verify#1857) Clean # out of file name parameters - [x] [#1858](VerifyTests/Verify#1858) Escape one character trimmed date formats - [x] [#1859](VerifyTests/Verify#1859) Prefer the exact type when resolving a member converter - [x] [#1860](VerifyTests/Verify#1860) Keep empty collections ignored alongside instance predicates - [x] [#1861](VerifyTests/Verify#1861) Key the combinations name cache by reference - [x] [#1862](VerifyTests/Verify#1862) Match MSTest overloads against the test data - [x] [#1863](VerifyTests/Verify#1863) Report deletes as directory relative paths - [x] [#1864](VerifyTests/Verify#1864) Name the guarded API in ThrowIfVerifyHasBeenRun - [x] [#1865](VerifyTests/Verify#1865) Keep stack frames that have no parameter list - [x] [#1866](VerifyTests/Verify#1866) Generate the TestContext property for record test classes - [x] [#1867](VerifyTests/Verify#1867) Fix two CombinationResultsConverter edge cases - [x] [#1868](VerifyTests/Verify#1868) Sign sub-hour UTC offsets - [x] [#1869](VerifyTests/Verify#1869) Write the received file from the stream for handle based FileStreams - [x] [#1870](VerifyTests/Verify#1870) Compare prefixes ignoring case - [x] [#1871](VerifyTests/Verify#1871) Guard the counter value caches with a lock - [x] [#1872](VerifyTests/Verify#1872) Sign sub-hour UTC offsets ## 32.0.0-beta.16 ## 32.0.0-beta.15 ## 32.0.0-beta.14 ## 32.0.0-beta.13 ## 32.0.0-beta.12 ## 32.0.0-beta.10 ## 32.0.0-beta.8 ## 32.0.0-beta.7 ## 32.0.0-beta.6 ## 32.0.0-beta.5 ## 32.0.0-beta.4 ## 32.0.0-beta.3 ## 32.0.0-beta.2 ## 32.0.0-beta.1 Commits viewable in [compare view](VerifyTests/Verify@31.28.0...32.0.0). </details> Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore <dependency name> major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore <dependency name> minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore <dependency name>` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore <dependency name>` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore <dependency name> <ignore condition>` will remove the ignore condition of the specified dependency and ignore conditions </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This was referenced Sep 11, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A record is a class, so it is a legal MSTest test class, but
IsSyntaxEligibleForGenerationonly matchedClassDeclarationSyntax. A[UsesVerify] [TestClass] partial recordcompiled and then failed at run time with the misleading:pointing at an attribute that was already there.
Records are now eligible. Two things follow from that:
partial class— which would have been a CS0261 kind mismatch against the record.GetParentClassesalso accepts arecord structparent. Its kind is two tokens (Keywordis only therecordhalf, withstructinClassOrStructKeyword), which the newGetPartialKeywordhandles.Record structs stay ineligible as targets:
[UsesVerify]is declared forAttributeTargets.Assembly | AttributeTargets.Class, so putting it on one is CS0592 in the consuming source regardless of what the generator does.HasAttributeOnRecordStructpins that as generating nothing.Tests on both sides.
Verify.MSTest.SourceGenerator.TestsgainsRecordTests— record, explicitrecord class, record struct, and a class nested insiderecord→record structparents; that harness compiles the generated output and asserts zero diagnostics, so a kind mismatch would fail it.Verify.MSTest.Testsgains an actualpartial recordtest class as the end-to-end proof: it throws "TestContext is null" onmain.Verify.MSTest.SourceGenerator.Tests(23) andVerify.MSTest.Tests(157 across net11.0 and net48) pass.