@@ -22,6 +22,8 @@ public ApiTests(TodoAppFixture fixture, ITestOutputHelper outputHelper)
2222        Fixture . SetOutputHelper ( OutputHelper ) ; 
2323    } 
2424
25+     public  virtual  CancellationToken  CancellationToken  =>  TestContext . Current . CancellationToken ; 
26+ 
2527    private  TodoAppFixture  Fixture  {  get ;  } 
2628
2729    private  ITestOutputHelper  OutputHelper  {  get ;  } 
@@ -33,7 +35,7 @@ public async Task Can_Manage_Todo_Items_With_Api()
3335        using  var  client  =  Fixture . CreateDefaultClient ( ) ; 
3436
3537        // Act - Get all the items 
36-         var  items  =  await  client . GetFromJsonAsync < TodoListViewModel > ( "/api/items" ) ; 
38+         var  items  =  await  client . GetFromJsonAsync < TodoListViewModel > ( "/api/items" ,   CancellationToken ) ; 
3739
3840        // Assert - There should be no items 
3941        Assert . NotNull ( items ) ; 
@@ -46,20 +48,20 @@ public async Task Can_Manage_Todo_Items_With_Api()
4648        var  newItem  =  new  CreateTodoItemModel  {  Text  =  text  } ; 
4749
4850        // Act - Add a new item 
49-         using  var  createdResponse  =  await  client . PostAsJsonAsync ( "/api/items" ,  newItem ) ; 
51+         using  var  createdResponse  =  await  client . PostAsJsonAsync ( "/api/items" ,  newItem ,   CancellationToken ) ; 
5052
5153        // Assert - An item was created 
5254        Assert . Equal ( HttpStatusCode . Created ,  createdResponse . StatusCode ) ; 
5355        Assert . NotNull ( createdResponse . Headers . Location ) ; 
5456
55-         using  var  createdJson  =  await  createdResponse . Content . ReadFromJsonAsync < JsonDocument > ( ) ; 
57+         using  var  createdJson  =  await  createdResponse . Content . ReadFromJsonAsync < JsonDocument > ( CancellationToken ) ; 
5658
5759        // Arrange - Get the new item's URL and Id 
5860        var  itemUri  =  createdResponse . Headers . Location ; 
5961        var  itemId  =  createdJson ! . RootElement . GetProperty ( "id" ) . GetString ( ) ; 
6062
6163        // Act - Get the item 
62-         var  item  =  await  client . GetFromJsonAsync < TodoItemModel > ( itemUri ) ; 
64+         var  item  =  await  client . GetFromJsonAsync < TodoItemModel > ( itemUri ,   CancellationToken ) ; 
6365
6466        // Assert - Verify the item was created correctly 
6567        Assert . NotNull ( item ) ; 
@@ -69,20 +71,20 @@ public async Task Can_Manage_Todo_Items_With_Api()
6971        Assert . Equal ( text ,  item . Text ) ; 
7072
7173        // Act - Mark the item as being completed 
72-         using  var  completedResponse  =  await  client . PostAsJsonAsync ( itemUri  +  "/complete" ,  new  {  } ) ; 
74+         using  var  completedResponse  =  await  client . PostAsJsonAsync ( itemUri  +  "/complete" ,  new  {  } ,   CancellationToken ) ; 
7375
7476        // Assert - The item was completed 
7577        Assert . Equal ( HttpStatusCode . NoContent ,  completedResponse . StatusCode ) ; 
7678
77-         item  =  await  client . GetFromJsonAsync < TodoItemModel > ( itemUri ) ; 
79+         item  =  await  client . GetFromJsonAsync < TodoItemModel > ( itemUri ,   CancellationToken ) ; 
7880
7981        Assert . NotNull ( item ) ; 
8082        Assert . Equal ( itemId ,  item . Id ) ; 
8183        Assert . Equal ( text ,  item . Text ) ; 
8284        Assert . True ( item . IsCompleted ) ; 
8385
8486        // Act - Get all the items 
85-         items  =  await  client . GetFromJsonAsync < TodoListViewModel > ( "/api/items" ) ; 
87+         items  =  await  client . GetFromJsonAsync < TodoListViewModel > ( "/api/items" ,   CancellationToken ) ; 
8688
8789        // Assert - The item was completed 
8890        Assert . NotNull ( items ) ; 
@@ -97,25 +99,25 @@ public async Task Can_Manage_Todo_Items_With_Api()
9799        Assert . NotNull ( item . LastUpdated ) ; 
98100
99101        // Act - Delete the item 
100-         using  var  deletedResponse  =  await  client . DeleteAsync ( itemUri ) ; 
102+         using  var  deletedResponse  =  await  client . DeleteAsync ( itemUri ,   CancellationToken ) ; 
101103
102104        // Assert - The item no longer exists 
103105        Assert . Equal ( HttpStatusCode . NoContent ,  deletedResponse . StatusCode ) ; 
104106
105-         items  =  await  client . GetFromJsonAsync < TodoListViewModel > ( "/api/items" ) ; 
107+         items  =  await  client . GetFromJsonAsync < TodoListViewModel > ( "/api/items" ,   CancellationToken ) ; 
106108
107109        Assert . NotNull ( items ) ; 
108110        Assert . NotNull ( items . Items ) ; 
109111        Assert . Equal ( beforeCount ,  items . Items . Count ) ; 
110112        Assert . DoesNotContain ( items . Items ,  x =>  x . Id  ==  itemId ) ; 
111113
112114        // Act 
113-         using  var  getResponse  =  await  client . GetAsync ( itemUri ) ; 
115+         using  var  getResponse  =  await  client . GetAsync ( itemUri ,   CancellationToken ) ; 
114116
115117        // Assert 
116118        Assert . Equal ( HttpStatusCode . NotFound ,  getResponse . StatusCode ) ; 
117119
118-         var  problem  =  await  getResponse . Content . ReadFromJsonAsync < ProblemDetails > ( ) ; 
120+         var  problem  =  await  getResponse . Content . ReadFromJsonAsync < ProblemDetails > ( CancellationToken ) ; 
119121
120122        Assert . NotNull ( problem ) ; 
121123        Assert . Equal ( StatusCodes . Status404NotFound ,  problem . Status ) ; 
@@ -133,12 +135,12 @@ public async Task Cannot_Create_Todo_Item_With_No_Text()
133135        var  item  =  new  CreateTodoItemModel  {  Text  =  string . Empty  } ; 
134136
135137        // Act 
136-         var  response  =  await  client . PostAsJsonAsync ( "/api/items" ,  item ) ; 
138+         var  response  =  await  client . PostAsJsonAsync ( "/api/items" ,  item ,   CancellationToken ) ; 
137139
138140        // Assert 
139141        Assert . Equal ( HttpStatusCode . BadRequest ,  response . StatusCode ) ; 
140142
141-         var  problem  =  await  response . Content . ReadFromJsonAsync < ProblemDetails > ( ) ; 
143+         var  problem  =  await  response . Content . ReadFromJsonAsync < ProblemDetails > ( CancellationToken ) ; 
142144
143145        Assert . NotNull ( problem ) ; 
144146        Assert . Equal ( StatusCodes . Status400BadRequest ,  problem . Status ) ; 
@@ -155,24 +157,24 @@ public async Task Cannot_Complete_Todo_Item_Multiple_Times()
155157        using  var  client  =  Fixture . CreateDefaultClient ( ) ; 
156158        var  item  =  new  CreateTodoItemModel  {  Text  =  "Something"  } ; 
157159
158-         using  var  createdResponse  =  await  client . PostAsJsonAsync ( "/api/items" ,  item ) ; 
160+         using  var  createdResponse  =  await  client . PostAsJsonAsync ( "/api/items" ,  item ,   CancellationToken ) ; 
159161
160162        Assert . Equal ( HttpStatusCode . Created ,  createdResponse . StatusCode ) ; 
161163        Assert . NotNull ( createdResponse . Headers . Location ) ; 
162164
163165        var  itemUri  =  createdResponse . Headers . Location ; 
164166
165-         using  var  completedResponse  =  await  client . PostAsJsonAsync ( itemUri  +  "/complete" ,  new  {  } ) ; 
167+         using  var  completedResponse  =  await  client . PostAsJsonAsync ( itemUri  +  "/complete" ,  new  {  } ,   CancellationToken ) ; 
166168
167169        Assert . Equal ( HttpStatusCode . NoContent ,  completedResponse . StatusCode ) ; 
168170
169171        // Act 
170-         using  var  response  =  await  client . PostAsJsonAsync ( itemUri  +  "/complete" ,  new  {  } ) ; 
172+         using  var  response  =  await  client . PostAsJsonAsync ( itemUri  +  "/complete" ,  new  {  } ,   CancellationToken ) ; 
171173
172174        // Assert 
173175        Assert . Equal ( HttpStatusCode . BadRequest ,  response . StatusCode ) ; 
174176
175-         var  problem  =  await  response . Content . ReadFromJsonAsync < ProblemDetails > ( ) ; 
177+         var  problem  =  await  response . Content . ReadFromJsonAsync < ProblemDetails > ( CancellationToken ) ; 
176178
177179        Assert . NotNull ( problem ) ; 
178180        Assert . Equal ( StatusCodes . Status400BadRequest ,  problem . Status ) ; 
@@ -189,24 +191,24 @@ public async Task Cannot_Complete_Deleted_Todo_Item()
189191        using  var  client  =  Fixture . CreateDefaultClient ( ) ; 
190192        var  item  =  new  CreateTodoItemModel  {  Text  =  "Something"  } ; 
191193
192-         using  var  createdResponse  =  await  client . PostAsJsonAsync ( "/api/items" ,  item ) ; 
194+         using  var  createdResponse  =  await  client . PostAsJsonAsync ( "/api/items" ,  item ,   CancellationToken ) ; 
193195
194196        Assert . Equal ( HttpStatusCode . Created ,  createdResponse . StatusCode ) ; 
195197        Assert . NotNull ( createdResponse . Headers . Location ) ; 
196198
197199        var  itemUri  =  createdResponse . Headers . Location ; 
198200
199-         using  var  deletedResponse  =  await  client . DeleteAsync ( itemUri ) ; 
201+         using  var  deletedResponse  =  await  client . DeleteAsync ( itemUri ,   CancellationToken ) ; 
200202
201203        Assert . Equal ( HttpStatusCode . NoContent ,  deletedResponse . StatusCode ) ; 
202204
203205        // Act 
204-         using  var  response  =  await  client . PostAsJsonAsync ( itemUri  +  "/complete" ,  new  {  } ) ; 
206+         using  var  response  =  await  client . PostAsJsonAsync ( itemUri  +  "/complete" ,  new  {  } ,   CancellationToken ) ; 
205207
206208        // Assert 
207209        Assert . Equal ( HttpStatusCode . NotFound ,  response . StatusCode ) ; 
208210
209-         var  problem  =  await  response . Content . ReadFromJsonAsync < ProblemDetails > ( ) ; 
211+         var  problem  =  await  response . Content . ReadFromJsonAsync < ProblemDetails > ( CancellationToken ) ; 
210212
211213        Assert . NotNull ( problem ) ; 
212214        Assert . Equal ( StatusCodes . Status404NotFound ,  problem . Status ) ; 
@@ -223,24 +225,24 @@ public async Task Cannot_Delete_Todo_Item_Multiple_Times()
223225        using  var  client  =  Fixture . CreateDefaultClient ( ) ; 
224226        var  item  =  new  CreateTodoItemModel  {  Text  =  "Something"  } ; 
225227
226-         using  var  createdResponse  =  await  client . PostAsJsonAsync ( "/api/items" ,  item ) ; 
228+         using  var  createdResponse  =  await  client . PostAsJsonAsync ( "/api/items" ,  item ,   CancellationToken ) ; 
227229
228230        Assert . Equal ( HttpStatusCode . Created ,  createdResponse . StatusCode ) ; 
229231        Assert . NotNull ( createdResponse . Headers . Location ) ; 
230232
231233        var  itemUri  =  createdResponse . Headers . Location ; 
232234
233-         using  var  deletedResponse  =  await  client . DeleteAsync ( itemUri ) ; 
235+         using  var  deletedResponse  =  await  client . DeleteAsync ( itemUri ,   CancellationToken ) ; 
234236
235237        Assert . Equal ( HttpStatusCode . NoContent ,  deletedResponse . StatusCode ) ; 
236238
237239        // Act 
238-         using  var  response  =  await  client . DeleteAsync ( itemUri ) ; 
240+         using  var  response  =  await  client . DeleteAsync ( itemUri ,   CancellationToken ) ; 
239241
240242        // Assert 
241243        Assert . Equal ( HttpStatusCode . NotFound ,  response . StatusCode ) ; 
242244
243-         var  problem  =  await  response . Content . ReadFromJsonAsync < ProblemDetails > ( ) ; 
245+         var  problem  =  await  response . Content . ReadFromJsonAsync < ProblemDetails > ( CancellationToken ) ; 
244246
245247        Assert . NotNull ( problem ) ; 
246248        Assert . Equal ( StatusCodes . Status404NotFound ,  problem . Status ) ; 
0 commit comments