Skip to content

Commit 9a95d9a

Browse files
committed
Update null comparison and update usage on CancellationTokens in tests
1 parent bca0c06 commit 9a95d9a

8 files changed

Lines changed: 42 additions & 42 deletions

File tree

.claude/skills/csharp-coding-standards/SKILL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: csharp-coding-standards
33
description: Defines the C# coding standards, patterns, and conventions to be applied consistently across all C# projects. Rules cover naming, structure, async patterns, null handling, dependency injection, logging, result patterns, and formatting. Apply these rules uniformly in all production code.
44
metadata:
5-
version: 1.0.0
5+
version: 1.1.0
66
---
77

88
# C# Coding Standards
@@ -128,7 +128,7 @@ Mark classes `sealed` by default unless inheritance is explicitly required. This
128128

129129
```csharp
130130
// ✅ Early return guard
131-
if (id == null || id.Length == 0)
131+
if (id is null || id.Length == 0)
132132
{
133133
return null;
134134
}

.claude/skills/csharp-testing-standards/SKILL.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: csharp-testing-standards
33
description: Defines the testing standards, patterns, and conventions for all C# unit and integration test projects. Rules cover test framework usage, naming, structure, mocking, assertions, and parameterization. Apply these rules uniformly across all test projects.
44
metadata:
5-
version: 1.0.0
5+
version: 1.1.0
66
---
77

88
# C# Testing Standards
@@ -73,7 +73,7 @@ public void Setup()
7373
{
7474
_orderRepositoryMock = new Mock<IOrderRepository>();
7575
_orderRepositoryMock
76-
.Setup(r => r.GetByIdAsync(It.IsAny<Guid>(), CancellationToken.None))
76+
.Setup(r => r.GetByIdAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
7777
.ReturnsAsync((Order?)null);
7878

7979
_sut = new OrderService(
@@ -133,11 +133,11 @@ public async Task GetByIdAsync_WhenOrderExists_ThenReturnsOrder()
133133
var orderId = Guid.NewGuid();
134134
var order = new Order { Id = orderId, CustomerName = "Alice" };
135135
_orderRepositoryMock
136-
.Setup(r => r.GetByIdAsync(orderId, CancellationToken.None))
136+
.Setup(r => r.GetByIdAsync(orderId, It.IsAny<CancellationToken>()))
137137
.ReturnsAsync(order);
138138

139139
// Act
140-
var result = await _sut.GetByIdAsync(orderId, CancellationToken.None);
140+
var result = await _sut.GetByIdAsync(orderId, It.IsAny<CancellationToken>());
141141

142142
// Assert
143143
Assert.That(result, Is.Not.Null);
@@ -173,7 +173,7 @@ Use `Assert.ThrowsAsync<T>` for async methods that are expected to throw:
173173

174174
```csharp
175175
Assert.ThrowsAsync<ArgumentNullException>(
176-
() => _sut.CreateAsync(null!, CancellationToken.None));
176+
() => _sut.CreateAsync(null!, It.IsAny<CancellationToken>()));
177177
```
178178

179179
### 5.3 Mock Verification
@@ -183,12 +183,12 @@ Use `.Verify()` only when asserting that a side-effecting call was (or was not)
183183
```csharp
184184
// ✅ Correct – asserting a save was triggered exactly once
185185
_orderRepositoryMock.Verify(
186-
r => r.SaveAsync(It.IsAny<Order>(), CancellationToken.None),
186+
r => r.SaveAsync(It.IsAny<Order>(), It.IsAny<CancellationToken>()),
187187
Times.Once);
188188

189189
// ✅ Correct – asserting a call was never made
190190
_orderRepositoryMock.Verify(
191-
r => r.DeleteAsync(It.IsAny<Guid>(), CancellationToken.None),
191+
r => r.DeleteAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()),
192192
Times.Never);
193193
```
194194

@@ -208,7 +208,7 @@ public async Task CreateAsync_WhenCustomerNameIsEmpty_ThenReturnsFailure(string
208208
var request = new CreateOrderRequest { CustomerName = customerName };
209209

210210
// Act
211-
var result = await _sut.CreateAsync(request, CancellationToken.None);
211+
var result = await _sut.CreateAsync(request, It.IsAny<CancellationToken>());
212212

213213
// Assert
214214
Assert.That(result.IsValid, Is.False);
@@ -248,12 +248,12 @@ Configure broad default behaviours in `[SetUp]` using `It.IsAny<T>()`. Narrow do
248248
```csharp
249249
// SetUp – broad default
250250
_repositoryMock
251-
.Setup(r => r.GetByIdAsync(It.IsAny<Guid>(), CancellationToken.None))
251+
.Setup(r => r.GetByIdAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
252252
.ReturnsAsync((Order?)null);
253253

254254
// Individual test – specific input
255255
_repositoryMock
256-
.Setup(r => r.GetByIdAsync(specificId, CancellationToken.None))
256+
.Setup(r => r.GetByIdAsync(specificId, It.IsAny<CancellationToken>()))
257257
.ReturnsAsync(specificOrder);
258258
```
259259

.cursor/rules/csharp-coding-standards.mdc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Mark classes `sealed` by default unless inheritance is explicitly required. This
126126

127127
```csharp
128128
// ✅ Early return guard
129-
if (id == null || id.Length == 0)
129+
if (id is null || id.Length == 0)
130130
{
131131
return null;
132132
}

.cursor/rules/csharp-testing-standards.mdc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void Setup()
7171
{
7272
_orderRepositoryMock = new Mock<IOrderRepository>();
7373
_orderRepositoryMock
74-
.Setup(r => r.GetByIdAsync(It.IsAny<Guid>(), CancellationToken.None))
74+
.Setup(r => r.GetByIdAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
7575
.ReturnsAsync((Order?)null);
7676

7777
_sut = new OrderService(
@@ -131,11 +131,11 @@ public async Task GetByIdAsync_WhenOrderExists_ThenReturnsOrder()
131131
var orderId = Guid.NewGuid();
132132
var order = new Order { Id = orderId, CustomerName = "Alice" };
133133
_orderRepositoryMock
134-
.Setup(r => r.GetByIdAsync(orderId, CancellationToken.None))
134+
.Setup(r => r.GetByIdAsync(orderId, It.IsAny<CancellationToken>()))
135135
.ReturnsAsync(order);
136136

137137
// Act
138-
var result = await _sut.GetByIdAsync(orderId, CancellationToken.None);
138+
var result = await _sut.GetByIdAsync(orderId, It.IsAny<CancellationToken>());
139139

140140
// Assert
141141
Assert.That(result, Is.Not.Null);
@@ -171,7 +171,7 @@ Use `Assert.ThrowsAsync<T>` for async methods that are expected to throw:
171171

172172
```csharp
173173
Assert.ThrowsAsync<ArgumentNullException>(
174-
() => _sut.CreateAsync(null!, CancellationToken.None));
174+
() => _sut.CreateAsync(null!, It.IsAny<CancellationToken>()));
175175
```
176176

177177
### 5.3 Mock Verification
@@ -181,12 +181,12 @@ Use `.Verify()` only when asserting that a side-effecting call was (or was not)
181181
```csharp
182182
// ✅ Correct – asserting a save was triggered exactly once
183183
_orderRepositoryMock.Verify(
184-
r => r.SaveAsync(It.IsAny<Order>(), CancellationToken.None),
184+
r => r.SaveAsync(It.IsAny<Order>(), It.IsAny<CancellationToken>()),
185185
Times.Once);
186186

187187
// ✅ Correct – asserting a call was never made
188188
_orderRepositoryMock.Verify(
189-
r => r.DeleteAsync(It.IsAny<Guid>(), CancellationToken.None),
189+
r => r.DeleteAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()),
190190
Times.Never);
191191
```
192192

@@ -206,7 +206,7 @@ public async Task CreateAsync_WhenCustomerNameIsEmpty_ThenReturnsFailure(string
206206
var request = new CreateOrderRequest { CustomerName = customerName };
207207

208208
// Act
209-
var result = await _sut.CreateAsync(request, CancellationToken.None);
209+
var result = await _sut.CreateAsync(request, It.IsAny<CancellationToken>());
210210

211211
// Assert
212212
Assert.That(result.IsValid, Is.False);
@@ -246,12 +246,12 @@ Configure broad default behaviours in `[SetUp]` using `It.IsAny<T>()`. Narrow do
246246
```csharp
247247
// SetUp – broad default
248248
_repositoryMock
249-
.Setup(r => r.GetByIdAsync(It.IsAny<Guid>(), CancellationToken.None))
249+
.Setup(r => r.GetByIdAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
250250
.ReturnsAsync((Order?)null);
251251

252252
// Individual test – specific input
253253
_repositoryMock
254-
.Setup(r => r.GetByIdAsync(specificId, CancellationToken.None))
254+
.Setup(r => r.GetByIdAsync(specificId, It.IsAny<CancellationToken>()))
255255
.ReturnsAsync(specificOrder);
256256
```
257257

.gemini/skills/csharp-coding-standards/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Mark classes `sealed` by default unless inheritance is explicitly required. This
126126

127127
```csharp
128128
// ✅ Early return guard
129-
if (id == null || id.Length == 0)
129+
if (id is null || id.Length == 0)
130130
{
131131
return null;
132132
}

.gemini/skills/csharp-testing-standards/SKILL.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void Setup()
7171
{
7272
_orderRepositoryMock = new Mock<IOrderRepository>();
7373
_orderRepositoryMock
74-
.Setup(r => r.GetByIdAsync(It.IsAny<Guid>(), CancellationToken.None))
74+
.Setup(r => r.GetByIdAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
7575
.ReturnsAsync((Order?)null);
7676

7777
_sut = new OrderService(
@@ -131,11 +131,11 @@ public async Task GetByIdAsync_WhenOrderExists_ThenReturnsOrder()
131131
var orderId = Guid.NewGuid();
132132
var order = new Order { Id = orderId, CustomerName = "Alice" };
133133
_orderRepositoryMock
134-
.Setup(r => r.GetByIdAsync(orderId, CancellationToken.None))
134+
.Setup(r => r.GetByIdAsync(orderId, It.IsAny<CancellationToken>()))
135135
.ReturnsAsync(order);
136136

137137
// Act
138-
var result = await _sut.GetByIdAsync(orderId, CancellationToken.None);
138+
var result = await _sut.GetByIdAsync(orderId, It.IsAny<CancellationToken>());
139139

140140
// Assert
141141
Assert.That(result, Is.Not.Null);
@@ -171,7 +171,7 @@ Use `Assert.ThrowsAsync<T>` for async methods that are expected to throw:
171171

172172
```csharp
173173
Assert.ThrowsAsync<ArgumentNullException>(
174-
() => _sut.CreateAsync(null!, CancellationToken.None));
174+
() => _sut.CreateAsync(null!, It.IsAny<CancellationToken>()));
175175
```
176176

177177
### 5.3 Mock Verification
@@ -181,12 +181,12 @@ Use `.Verify()` only when asserting that a side-effecting call was (or was not)
181181
```csharp
182182
// ✅ Correct – asserting a save was triggered exactly once
183183
_orderRepositoryMock.Verify(
184-
r => r.SaveAsync(It.IsAny<Order>(), CancellationToken.None),
184+
r => r.SaveAsync(It.IsAny<Order>(), It.IsAny<CancellationToken>()),
185185
Times.Once);
186186

187187
// ✅ Correct – asserting a call was never made
188188
_orderRepositoryMock.Verify(
189-
r => r.DeleteAsync(It.IsAny<Guid>(), CancellationToken.None),
189+
r => r.DeleteAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()),
190190
Times.Never);
191191
```
192192

@@ -206,7 +206,7 @@ public async Task CreateAsync_WhenCustomerNameIsEmpty_ThenReturnsFailure(string
206206
var request = new CreateOrderRequest { CustomerName = customerName };
207207

208208
// Act
209-
var result = await _sut.CreateAsync(request, CancellationToken.None);
209+
var result = await _sut.CreateAsync(request, It.IsAny<CancellationToken>());
210210

211211
// Assert
212212
Assert.That(result.IsValid, Is.False);
@@ -246,12 +246,12 @@ Configure broad default behaviours in `[SetUp]` using `It.IsAny<T>()`. Narrow do
246246
```csharp
247247
// SetUp – broad default
248248
_repositoryMock
249-
.Setup(r => r.GetByIdAsync(It.IsAny<Guid>(), CancellationToken.None))
249+
.Setup(r => r.GetByIdAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
250250
.ReturnsAsync((Order?)null);
251251

252252
// Individual test – specific input
253253
_repositoryMock
254-
.Setup(r => r.GetByIdAsync(specificId, CancellationToken.None))
254+
.Setup(r => r.GetByIdAsync(specificId, It.IsAny<CancellationToken>()))
255255
.ReturnsAsync(specificOrder);
256256
```
257257

content/csharp-coding-standards.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Mark classes `sealed` by default unless inheritance is explicitly required. This
121121

122122
```csharp
123123
// ✅ Early return guard
124-
if (id == null || id.Length == 0)
124+
if (id is null || id.Length == 0)
125125
{
126126
return null;
127127
}

content/csharp-testing-standards.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void Setup()
6666
{
6767
_orderRepositoryMock = new Mock<IOrderRepository>();
6868
_orderRepositoryMock
69-
.Setup(r => r.GetByIdAsync(It.IsAny<Guid>(), CancellationToken.None))
69+
.Setup(r => r.GetByIdAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
7070
.ReturnsAsync((Order?)null);
7171

7272
_sut = new OrderService(
@@ -126,11 +126,11 @@ public async Task GetByIdAsync_WhenOrderExists_ThenReturnsOrder()
126126
var orderId = Guid.NewGuid();
127127
var order = new Order { Id = orderId, CustomerName = "Alice" };
128128
_orderRepositoryMock
129-
.Setup(r => r.GetByIdAsync(orderId, CancellationToken.None))
129+
.Setup(r => r.GetByIdAsync(orderId, It.IsAny<CancellationToken>()))
130130
.ReturnsAsync(order);
131131

132132
// Act
133-
var result = await _sut.GetByIdAsync(orderId, CancellationToken.None);
133+
var result = await _sut.GetByIdAsync(orderId, It.IsAny<CancellationToken>());
134134

135135
// Assert
136136
Assert.That(result, Is.Not.Null);
@@ -166,7 +166,7 @@ Use `Assert.ThrowsAsync<T>` for async methods that are expected to throw:
166166

167167
```csharp
168168
Assert.ThrowsAsync<ArgumentNullException>(
169-
() => _sut.CreateAsync(null!, CancellationToken.None));
169+
() => _sut.CreateAsync(null!, It.IsAny<CancellationToken>()));
170170
```
171171

172172
### 5.3 Mock Verification
@@ -176,12 +176,12 @@ Use `.Verify()` only when asserting that a side-effecting call was (or was not)
176176
```csharp
177177
// ✅ Correct – asserting a save was triggered exactly once
178178
_orderRepositoryMock.Verify(
179-
r => r.SaveAsync(It.IsAny<Order>(), CancellationToken.None),
179+
r => r.SaveAsync(It.IsAny<Order>(), It.IsAny<CancellationToken>()),
180180
Times.Once);
181181

182182
// ✅ Correct – asserting a call was never made
183183
_orderRepositoryMock.Verify(
184-
r => r.DeleteAsync(It.IsAny<Guid>(), CancellationToken.None),
184+
r => r.DeleteAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()),
185185
Times.Never);
186186
```
187187

@@ -201,7 +201,7 @@ public async Task CreateAsync_WhenCustomerNameIsEmpty_ThenReturnsFailure(string
201201
var request = new CreateOrderRequest { CustomerName = customerName };
202202

203203
// Act
204-
var result = await _sut.CreateAsync(request, CancellationToken.None);
204+
var result = await _sut.CreateAsync(request, It.IsAny<CancellationToken>());
205205

206206
// Assert
207207
Assert.That(result.IsValid, Is.False);
@@ -241,12 +241,12 @@ Configure broad default behaviours in `[SetUp]` using `It.IsAny<T>()`. Narrow do
241241
```csharp
242242
// SetUp – broad default
243243
_repositoryMock
244-
.Setup(r => r.GetByIdAsync(It.IsAny<Guid>(), CancellationToken.None))
244+
.Setup(r => r.GetByIdAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
245245
.ReturnsAsync((Order?)null);
246246

247247
// Individual test – specific input
248248
_repositoryMock
249-
.Setup(r => r.GetByIdAsync(specificId, CancellationToken.None))
249+
.Setup(r => r.GetByIdAsync(specificId, It.IsAny<CancellationToken>()))
250250
.ReturnsAsync(specificOrder);
251251
```
252252

0 commit comments

Comments
 (0)