Repository navigation
Document params array support with TestCaseSource - #1276
Conversation
Optional parameters and `CancellationToken` injection with `TestCaseSource` were already documented, but `params` arrays (the third feature from nunit/nunit#5057, released in 4.5) were not. Adds a short "Params arrays" section explaining how extra source arguments are gathered into the array, what happens with no extra arguments, and that an array of the right type as the last argument is passed through. Backed by a new tested snippet with all four cases. Fixes #1095 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
📖 Docs preview removed because this PR was closed. |
stevenaw
left a comment
There was a problem hiding this comment.
Thanks for drafting this @SeanKilleen
This looks good to me, but I'm also going to request review from @manfred-brands for secondary perspective as I think we both changed things in this area in that release
manfred-brands
left a comment
There was a problem hiding this comment.
Could be add a note for the below?
| parameters are gathered into that array, just as they are for [TestCase](xref:attribute-testcase). A test case that | ||
| supplies no extra arguments gives an empty array, and a test case whose last argument is already an array of the right | ||
| type passes it through unchanged. (_NUnit 4.5+_) | ||
|
|
There was a problem hiding this comment.
Maybe we should say something here or in the CancellationToken section below that these two don't mix.
We cannot declare a CancellationToken parameter after a params array.
Therefore if [CancelAfter] is used with a params array, the user needs to use TestContext.CurrentContext.CancellationToken instead.
There was a problem hiding this comment.
I think I've captured this in the latest commit. Let me know if you agree.
…ection A params array must be the last parameter, so a test method cannot also declare the CancellationToken parameter that [CancelAfter] injects. Add a note to the Params arrays section and a cross-reference in the CancellationToken section pointing to TestContext.CurrentContext.CancellationToken as the alternative, backed by a tested snippet. Addresses review feedback from @manfred-brands. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
manfred-brands
left a comment
There was a problem hiding this comment.
Thanks @SeanKilleen
One small change suggestion.
Co-authored-by: Manfred Brands <manfred-brands@users.noreply.github.com>
* Document params array support with TestCaseSource Optional parameters and `CancellationToken` injection with `TestCaseSource` were already documented, but `params` arrays (the third feature from nunit/nunit#5057, released in 4.5) were not. Adds a short "Params arrays" section explaining how extra source arguments are gathered into the array, what happens with no extra arguments, and that an array of the right type as the last argument is passed through. Backed by a new tested snippet with all four cases. Fixes #1095 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Note that params arrays cannot be combined with CancellationToken injection A params array must be the last parameter, so a test method cannot also declare the CancellationToken parameter that [CancelAfter] injects. Add a note to the Params arrays section and a cross-reference in the CancellationToken section pointing to TestContext.CurrentContext.CancellationToken as the alternative, backed by a tested snippet. Addresses review feedback from @manfred-brands. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Update docs/snippets/Snippets.NUnit/TestCaseSourceExamples.cs Co-authored-by: Manfred Brands <manfred-brands@users.noreply.github.com> --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: Manfred Brands <manfred-brands@users.noreply.github.com> 3a359db
Optional parameters and
CancellationTokeninjection withTestCaseSourcewere already documented, butparamsarrays (the third feature from nunit/nunit#5057, released in 4.5) were not. Adds a short "Params arrays" section explaining how extra source arguments are gathered into the array, what happens with no extra arguments, and that an array of the right type as the last argument is passed through. Backed by a new tested snippet with all four cases.Fixes #1095
🤖 Generated with Claude Code