|
1 | 1 | using ConsoleTemplate.Infrastructure; |
2 | 2 |
|
3 | | -namespace ConsoleTemplate.Tests.Infrastructure |
| 3 | +namespace ConsoleTemplate.Tests.Infrastructure; |
| 4 | + |
| 5 | +[TestFixture] |
| 6 | +public class ConsoleAppCancellationTokenSourceTests |
4 | 7 | { |
5 | | - [TestFixture] |
6 | | - public class ConsoleAppCancellationTokenSourceTests |
7 | | - { |
8 | | - private ConsoleAppCancellationTokenSource _sut = null!; // System Under Test |
| 8 | + private ConsoleAppCancellationTokenSource _sut = null!; // System Under Test |
9 | 9 |
|
10 | | - [SetUp] |
11 | | - public void Setup() |
12 | | - { |
13 | | - // Create a new instance before each test |
14 | | - _sut = new ConsoleAppCancellationTokenSource(); |
15 | | - } |
| 10 | + [SetUp] |
| 11 | + public void Setup() |
| 12 | + { |
| 13 | + // Create a new instance before each test |
| 14 | + _sut = new ConsoleAppCancellationTokenSource(); |
| 15 | + } |
16 | 16 |
|
17 | | - [TearDown] |
18 | | - public void Teardown() |
19 | | - { |
20 | | - // Ensure disposal after each test |
21 | | - _sut?.Dispose(); |
22 | | - } |
| 17 | + [TearDown] |
| 18 | + public void Teardown() |
| 19 | + { |
| 20 | + // Ensure disposal after each test |
| 21 | + _sut?.Dispose(); |
| 22 | + } |
23 | 23 |
|
24 | | - [Test] |
25 | | - public void Constructor_ShouldInitializeToken_WhichIsNotCancelled() |
26 | | - { |
27 | | - // Act |
28 | | - var token = _sut.Token; |
| 24 | + [Test] |
| 25 | + public void Constructor_ShouldInitializeToken_WhichIsNotCancelled() |
| 26 | + { |
| 27 | + // Act |
| 28 | + var token = _sut.Token; |
29 | 29 |
|
30 | | - // Assert |
31 | | - token.IsCancellationRequested.Should().BeFalse(); |
32 | | - token.CanBeCanceled.Should().BeTrue(); |
33 | | - } |
| 30 | + // Assert |
| 31 | + token.IsCancellationRequested.Should().BeFalse(); |
| 32 | + token.CanBeCanceled.Should().BeTrue(); |
| 33 | + } |
34 | 34 |
|
35 | | - [Test] |
36 | | - public void Dispose_ShouldCancelTheToken() |
37 | | - { |
38 | | - // Arrange |
39 | | - var token = _sut.Token; |
40 | | - token.IsCancellationRequested.Should().BeFalse(); // Pre-condition |
| 35 | + [Test] |
| 36 | + public void Dispose_ShouldCancelTheToken() |
| 37 | + { |
| 38 | + // Arrange |
| 39 | + var token = _sut.Token; |
| 40 | + token.IsCancellationRequested.Should().BeFalse(); // Pre-condition |
41 | 41 |
|
42 | | - // Act |
43 | | - _sut.Dispose(); |
| 42 | + // Act |
| 43 | + _sut.Dispose(); |
44 | 44 |
|
45 | | - // Assert |
46 | | - // Give a brief moment for potential background operations triggered by Dispose/Cancel |
47 | | - Thread.Sleep(50); // Small delay might be needed depending on thread scheduling |
48 | | - token.IsCancellationRequested.Should().BeTrue(); |
49 | | - } |
| 45 | + // Assert |
| 46 | + // Give a brief moment for potential background operations triggered by Dispose/Cancel |
| 47 | + Thread.Sleep(50); // Small delay might be needed depending on thread scheduling |
| 48 | + token.IsCancellationRequested.Should().BeTrue(); |
| 49 | + } |
50 | 50 |
|
51 | | - [Test] |
52 | | - public void Dispose_CanBeCalledMultipleTimes_WithoutThrowing() |
53 | | - { |
54 | | - // Arrange |
55 | | - _sut.Dispose(); // First call |
| 51 | + [Test] |
| 52 | + public void Dispose_CanBeCalledMultipleTimes_WithoutThrowing() |
| 53 | + { |
| 54 | + // Arrange |
| 55 | + _sut.Dispose(); // First call |
56 | 56 |
|
57 | | - // Act & Assert |
58 | | - Action secondDispose = () => _sut.Dispose(); |
59 | | - secondDispose.Should().NotThrow(); |
60 | | - } |
| 57 | + // Act & Assert |
| 58 | + Action secondDispose = () => _sut.Dispose(); |
| 59 | + secondDispose.Should().NotThrow(); |
| 60 | + } |
61 | 61 |
|
62 | | - [Test] |
63 | | - public void Token_ShouldReturnSameInstance() |
64 | | - { |
65 | | - // Act |
66 | | - var token1 = _sut.Token; |
67 | | - var token2 = _sut.Token; |
| 62 | + [Test] |
| 63 | + public void Token_ShouldReturnSameInstance() |
| 64 | + { |
| 65 | + // Act |
| 66 | + var token1 = _sut.Token; |
| 67 | + var token2 = _sut.Token; |
68 | 68 |
|
69 | | - // Assert |
70 | | - // CancellationToken is a struct, so we compare properties or rely on reference equality of the source |
71 | | - // For simplicity, we check CanBeCanceled as an indicator it's from the same source. |
72 | | - // A more robust check might involve reflection or modifying the SUT, but this is sufficient for basic validation. |
73 | | - token1.CanBeCanceled.Should().Be(token2.CanBeCanceled); |
74 | | - token1.IsCancellationRequested.Should().Be(token2.IsCancellationRequested); |
75 | | - } |
| 69 | + // Assert |
| 70 | + // CancellationToken is a struct, so we compare properties or rely on reference equality of the source |
| 71 | + // For simplicity, we check CanBeCanceled as an indicator it's from the same source. |
| 72 | + // A more robust check might involve reflection or modifying the SUT, but this is sufficient for basic validation. |
| 73 | + token1.CanBeCanceled.Should().Be(token2.CanBeCanceled); |
| 74 | + token1.IsCancellationRequested.Should().Be(token2.IsCancellationRequested); |
76 | 75 | } |
77 | 76 | } |
0 commit comments