Skip to content

Commit bc10ecf

Browse files
committed
Adjust some formatting for cancelafter attribute
1 parent a451901 commit bc10ecf

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

docs/articles/nunit/writing-tests/attributes/cancelafter.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ When used on test methods, NUnit automatically adds an extra argument to your me
3737

3838
## Example
3939

40+
The `CancelAfterAttribute` supports cancellation across a variety of ways to write tests.
41+
42+
Test
43+
4044
[!code-csharp[TestWithCancellationToken](~/snippets/Snippets.NUnit/Attributes/CancelAfterAttributeExamples.cs#TestWithCancellationToken)]
4145

42-
[!code-csharp[TestCaseSourceWithCancellationToken](~/snippets/Snippets.NUnit/Attributes/CancelAfterAttributeExamples.cs#TestCaseSourceWithCancellationToken)]
46+
TestCase
4347

4448
```csharp
4549
[CancelAfter(2000)]
@@ -55,6 +59,10 @@ public async Task PotentiallyLongRunningTest(string uri, CancellationToken token
5559
}
5660
```
5761

62+
TestCaseSource
63+
64+
[!code-csharp[TestCaseSourceWithCancellationToken](~/snippets/Snippets.NUnit/Attributes/CancelAfterAttributeExamples.cs#TestCaseSourceWithCancellationToken)]
65+
5866
> [!NOTE]
5967
> When debugging a unit test, i.e. when a debugger is attached to the process, the timeout is not enforced.
6068

docs/snippets/Snippets.NUnit/Attributes/CancelAfterAttributeExamples.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace Snippets.NUnit.Attributes
66
public class CancelAfterAttributeExamples
77
{
88
#region TestWithCancellationToken
9-
109
[Test, CancelAfter(2_000)]
1110
public void RunningTestUntilCanceled(CancellationToken cancellationToken)
1211
{
@@ -15,15 +14,13 @@ public void RunningTestUntilCanceled(CancellationToken cancellationToken)
1514
/* */
1615
}
1716
}
18-
1917
#endregion
2018

2119
#region TestCaseSourceWithCancellationToken
22-
2320
private static int[] _simpleValues = { 2, 4, 6, 8 };
2421

2522
[TestCaseSource(nameof(_simpleValues)), CancelAfter(1_000)]
26-
public async Task TestCaseSourceWithCancellationToken(int a, CancellationToken cancellationToken)
23+
public void TestCaseSourceWithCancellationToken(int a, CancellationToken cancellationToken)
2724
{
2825
Assert.That(cancellationToken, Is.Not.Default);
2926

@@ -32,7 +29,6 @@ public async Task TestCaseSourceWithCancellationToken(int a, CancellationToken c
3229
/* */
3330
}
3431
}
35-
3632
#endregion
3733
}
3834
}

0 commit comments

Comments
 (0)