Skip to content

Commit 8793881

Browse files
committed
Merge branch 'cancellation'
2 parents cd700ea + 70334e2 commit 8793881

File tree

61 files changed

+1019
-440
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1019
-440
lines changed

src/Buttercup.Application.Tests/CommentManagerTests.cs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public async Task CreateComment_InsertsCommentAndRevisionAndReturnsId()
3131
await this.DatabaseFixture.InsertEntities(recipe, currentUser);
3232

3333
var attributes = this.BuildCommentAttributes();
34-
var id = await this.commentManager.CreateComment(recipe.Id, attributes, currentUser.Id);
34+
var id = await this.commentManager.CreateComment(
35+
recipe.Id, attributes, currentUser.Id, TestContext.Current.CancellationToken);
3536

3637
using var dbContext = this.DatabaseFixture.CreateDbContext();
3738

@@ -77,7 +78,10 @@ public async Task CreateComment_ThrowsIfRecipeNotFound()
7778

7879
var exception = await Assert.ThrowsAsync<NotFoundException>(
7980
() => this.commentManager.CreateComment(
80-
recipeId, this.BuildCommentAttributes(), currentUser.Id));
81+
recipeId,
82+
this.BuildCommentAttributes(),
83+
currentUser.Id,
84+
TestContext.Current.CancellationToken));
8185

8286
Assert.Equal($"Recipe/{recipeId} not found", exception.Message);
8387
}
@@ -91,7 +95,10 @@ public async Task CreateComment_ThrowsIfRecipeSoftDeleted()
9195

9296
var exception = await Assert.ThrowsAsync<SoftDeletedException>(
9397
() => this.commentManager.CreateComment(
94-
recipe.Id, this.BuildCommentAttributes(), currentUser.Id));
98+
recipe.Id,
99+
this.BuildCommentAttributes(),
100+
currentUser.Id,
101+
TestContext.Current.CancellationToken));
95102

96103
Assert.Equal($"Cannot add comment to soft-deleted recipe {recipe.Id}", exception.Message);
97104
}
@@ -107,7 +114,8 @@ public async Task DeleteComment_SetsSoftDeleteAttributesAndReturnsTrue()
107114
var currentUser = this.modelFactory.BuildUser();
108115
await this.DatabaseFixture.InsertEntities(original, currentUser);
109116

110-
Assert.True(await this.commentManager.DeleteComment(original.Id, currentUser.Id));
117+
Assert.True(await this.commentManager.DeleteComment(
118+
original.Id, currentUser.Id, TestContext.Current.CancellationToken));
111119

112120
using var dbContext = this.DatabaseFixture.CreateDbContext();
113121

@@ -129,7 +137,8 @@ public async Task DeleteComment_DoesNotUpdateAttributesAndReturnsFalseIfAlreadyS
129137
var currentUser = this.modelFactory.BuildUser();
130138
await this.DatabaseFixture.InsertEntities(original, currentUser);
131139

132-
Assert.False(await this.commentManager.DeleteComment(original.Id, currentUser.Id));
140+
Assert.False(await this.commentManager.DeleteComment(
141+
original.Id, currentUser.Id, TestContext.Current.CancellationToken));
133142

134143
using var dbContext = this.DatabaseFixture.CreateDbContext();
135144

@@ -146,7 +155,10 @@ await this.DatabaseFixture.InsertEntities(
146155
this.modelFactory.BuildComment(setRecipe: true), currentUser);
147156

148157
Assert.False(
149-
await this.commentManager.DeleteComment(this.modelFactory.NextInt(), currentUser.Id));
158+
await this.commentManager.DeleteComment(
159+
this.modelFactory.NextInt(),
160+
currentUser.Id,
161+
TestContext.Current.CancellationToken));
150162
}
151163

152164
#endregion
@@ -159,7 +171,8 @@ public async Task HardDeleteComment_HardDeletesCommentAndReturnsTrue()
159171
var comment = this.modelFactory.BuildComment(setRecipe: true);
160172
await this.DatabaseFixture.InsertEntities(comment);
161173

162-
Assert.True(await this.commentManager.HardDeleteComment(comment.Id));
174+
Assert.True(await this.commentManager.HardDeleteComment(
175+
comment.Id, TestContext.Current.CancellationToken));
163176

164177
using var dbContext = this.DatabaseFixture.CreateDbContext();
165178

@@ -171,7 +184,8 @@ public async Task HardDeleteComment_ReturnsFalseIfRecordNotFound()
171184
{
172185
await this.DatabaseFixture.InsertEntities(this.modelFactory.BuildComment(setRecipe: true));
173186

174-
Assert.False(await this.commentManager.HardDeleteComment(this.modelFactory.NextInt()));
187+
Assert.False(await this.commentManager.HardDeleteComment(
188+
this.modelFactory.NextInt(), TestContext.Current.CancellationToken));
175189
}
176190

177191
#endregion

src/Buttercup.Application.Tests/RecipeManagerTests.cs

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public async Task CreateRecipe_InsertsRecipeAndRevisionAndReturnsId()
3131
this.modelFactory.BuildRecipe(setOptionalAttributes: true));
3232
await this.DatabaseFixture.InsertEntities(currentUser);
3333

34-
var id = await this.recipeManager.CreateRecipe(attributes, currentUser.Id);
34+
var id = await this.recipeManager.CreateRecipe(
35+
attributes, currentUser.Id, TestContext.Current.CancellationToken);
3536

3637
using var dbContext = this.DatabaseFixture.CreateDbContext();
3738

@@ -86,7 +87,8 @@ public async Task CreateRecipe_AcceptsNullForOptionalAttributes()
8687
this.modelFactory.BuildRecipe(setOptionalAttributes: false));
8788
await this.DatabaseFixture.InsertEntities(currentUser);
8889

89-
var id = await this.recipeManager.CreateRecipe(attributes, currentUser.Id);
90+
var id = await this.recipeManager.CreateRecipe(
91+
attributes, currentUser.Id, TestContext.Current.CancellationToken);
9092

9193
using var dbContext = this.DatabaseFixture.CreateDbContext();
9294

@@ -112,7 +114,8 @@ public async Task DeleteRecipe_SetsSoftDeleteAttributesAndReturnsTrue()
112114
var currentUser = this.modelFactory.BuildUser();
113115
await this.DatabaseFixture.InsertEntities(original, currentUser);
114116

115-
Assert.True(await this.recipeManager.DeleteRecipe(original.Id, currentUser.Id));
117+
Assert.True(await this.recipeManager.DeleteRecipe(
118+
original.Id, currentUser.Id, TestContext.Current.CancellationToken));
116119

117120
using var dbContext = this.DatabaseFixture.CreateDbContext();
118121

@@ -133,7 +136,8 @@ public async Task DeleteRecipe_DoesNotUpdateAttributesAndReturnsFalseIfAlreadySo
133136
var currentUser = this.modelFactory.BuildUser();
134137
await this.DatabaseFixture.InsertEntities(original, currentUser);
135138

136-
Assert.False(await this.recipeManager.DeleteRecipe(original.Id, currentUser.Id));
139+
Assert.False(await this.recipeManager.DeleteRecipe(
140+
original.Id, currentUser.Id, TestContext.Current.CancellationToken));
137141

138142
using var dbContext = this.DatabaseFixture.CreateDbContext();
139143

@@ -148,8 +152,8 @@ public async Task DeleteRecipe_ReturnsFalseIfRecordNotFound()
148152
var currentUser = this.modelFactory.BuildUser();
149153
await this.DatabaseFixture.InsertEntities(this.modelFactory.BuildRecipe(), currentUser);
150154

151-
Assert.False(
152-
await this.recipeManager.DeleteRecipe(this.modelFactory.NextInt(), currentUser.Id));
155+
Assert.False(await this.recipeManager.DeleteRecipe(
156+
this.modelFactory.NextInt(), currentUser.Id, TestContext.Current.CancellationToken));
153157
}
154158

155159
#endregion
@@ -162,7 +166,8 @@ public async Task HardDeleteRecipe_HardDeletesRecipeAndReturnsTrue()
162166
var recipe = this.modelFactory.BuildRecipe();
163167
await this.DatabaseFixture.InsertEntities(recipe);
164168

165-
Assert.True(await this.recipeManager.HardDeleteRecipe(recipe.Id));
169+
Assert.True(await this.recipeManager.HardDeleteRecipe(
170+
recipe.Id, TestContext.Current.CancellationToken));
166171

167172
using var dbContext = this.DatabaseFixture.CreateDbContext();
168173

@@ -174,7 +179,8 @@ public async Task HardDeleteRecipe_ReturnsFalseIfRecordNotFound()
174179
{
175180
await this.DatabaseFixture.InsertEntities(this.modelFactory.BuildRecipe());
176181

177-
Assert.False(await this.recipeManager.HardDeleteRecipe(this.modelFactory.NextInt()));
182+
Assert.False(await this.recipeManager.HardDeleteRecipe(
183+
this.modelFactory.NextInt(), TestContext.Current.CancellationToken));
178184
}
179185

180186
#endregion
@@ -192,7 +198,11 @@ public async Task UpdateRecipe_UpdatesRecipeInsertsRevisionAndReturnsTrue()
192198
this.modelFactory.BuildRecipe(setOptionalAttributes: true));
193199

194200
Assert.True(await this.recipeManager.UpdateRecipe(
195-
original.Id, newAttributes, original.Revision, currentUser.Id));
201+
original.Id,
202+
newAttributes,
203+
original.Revision,
204+
currentUser.Id,
205+
TestContext.Current.CancellationToken));
196206

197207
using var dbContext = this.DatabaseFixture.CreateDbContext();
198208

@@ -250,7 +260,11 @@ public async Task UpdateRecipe_AcceptsNullForOptionalAttributes()
250260
this.modelFactory.BuildRecipe(setOptionalAttributes: false));
251261

252262
Assert.True(await this.recipeManager.UpdateRecipe(
253-
original.Id, newAttributes, original.Revision, currentUser.Id));
263+
original.Id,
264+
newAttributes,
265+
original.Revision,
266+
currentUser.Id,
267+
TestContext.Current.CancellationToken));
254268

255269
using var dbContext = this.DatabaseFixture.CreateDbContext();
256270
var actual = await dbContext.Recipes.FindAsync(
@@ -273,7 +287,11 @@ public async Task UpdateRecipe_ReturnsFalseAndDoesNotUpdateIfAttributesAlreadyMa
273287
await this.DatabaseFixture.InsertEntities(original, currentUser);
274288

275289
Assert.False(await this.recipeManager.UpdateRecipe(
276-
original.Id, new(original), original.Revision, currentUser.Id));
290+
original.Id,
291+
new(original),
292+
original.Revision,
293+
currentUser.Id,
294+
TestContext.Current.CancellationToken));
277295

278296
using var dbContext = this.DatabaseFixture.CreateDbContext();
279297
var expected = original with { CreatedByUser = null, ModifiedByUser = null };
@@ -293,7 +311,11 @@ public async Task UpdateRecipe_ThrowsIfRecordNotFound()
293311
var id = this.modelFactory.NextInt();
294312
var exception = await Assert.ThrowsAsync<NotFoundException>(
295313
() => this.recipeManager.UpdateRecipe(
296-
id, new(this.modelFactory.BuildRecipe()), 0, currentUser.Id));
314+
id,
315+
new(this.modelFactory.BuildRecipe()),
316+
0,
317+
currentUser.Id,
318+
TestContext.Current.CancellationToken));
297319

298320
Assert.Equal($"Recipe/{id} not found", exception.Message);
299321
}
@@ -307,7 +329,11 @@ public async Task UpdateRecipe_ThrowsIfRecipeSoftDeleted()
307329

308330
var exception = await Assert.ThrowsAsync<SoftDeletedException>(
309331
() => this.recipeManager.UpdateRecipe(
310-
recipe.Id, new(this.modelFactory.BuildRecipe()), recipe.Revision, currentUser.Id));
332+
recipe.Id,
333+
new(this.modelFactory.BuildRecipe()),
334+
recipe.Revision,
335+
currentUser.Id,
336+
TestContext.Current.CancellationToken));
311337

312338
Assert.Equal($"Cannot update soft-deleted recipe {recipe.Id}", exception.Message);
313339
}
@@ -322,7 +348,11 @@ public async Task UpdateRecipe_ThrowsIfRevisionOutOfSync()
322348
var staleRevision = recipe.Revision - 1;
323349
var exception = await Assert.ThrowsAsync<ConcurrencyException>(
324350
() => this.recipeManager.UpdateRecipe(
325-
recipe.Id, new(this.modelFactory.BuildRecipe()), staleRevision, currentUser.Id));
351+
recipe.Id,
352+
new(this.modelFactory.BuildRecipe()),
353+
staleRevision,
354+
currentUser.Id,
355+
TestContext.Current.CancellationToken));
326356

327357
Assert.Equal(
328358
$"Revision {staleRevision} does not match current revision {recipe.Revision}",

0 commit comments

Comments
 (0)