7
7
using JsonApiDotNetCoreExample ;
8
8
using JsonApiDotNetCoreExample . Data ;
9
9
using JsonApiDotNetCoreExample . Models ;
10
+ using JsonApiDotNetCoreExampleTests . Helpers . Extensions ;
10
11
using Microsoft . AspNetCore . Hosting ;
11
12
using Newtonsoft . Json ;
12
13
using Xunit ;
@@ -181,22 +182,14 @@ public async Task Included_Resources_Are_Correct()
181
182
{
182
183
// arrange
183
184
var role = new PersonRole ( ) ;
184
- var asignee = new Person { Role = role } ;
185
+ var assignee = new Person { Role = role } ;
185
186
var collectionOwner = new Person ( ) ;
186
187
var someOtherOwner = new Person ( ) ;
187
188
var collection = new TodoItemCollection { Owner = collectionOwner } ;
188
- var todoItem1 = new TodoItem { Collection = collection , Assignee = asignee } ;
189
- var todoItem2 = new TodoItem { Collection = collection , Assignee = asignee } ;
189
+ var todoItem1 = new TodoItem { Collection = collection , Assignee = assignee } ;
190
+ var todoItem2 = new TodoItem { Collection = collection , Assignee = assignee } ;
190
191
var todoItem3 = new TodoItem { Collection = collection , Owner = someOtherOwner } ;
191
- var todoItem4 = new TodoItem { Collection = collection , Owner = asignee } ;
192
-
193
-
194
- string route =
195
- "/api/v1/todo-items/" + todoItem1 . Id + "?include=" +
196
- "collection.owner," +
197
- "asignee.role," +
198
- "asignee.assigned-todo-items" ;
199
-
192
+ var todoItem4 = new TodoItem { Collection = collection , Owner = assignee } ;
200
193
201
194
var context = _fixture . GetService < AppDbContext > ( ) ;
202
195
ResetContext ( context ) ;
@@ -206,14 +199,20 @@ public async Task Included_Resources_Are_Correct()
206
199
context . TodoItems . Add ( todoItem3 ) ;
207
200
context . TodoItems . Add ( todoItem4 ) ;
208
201
context . PersonRoles . Add ( role ) ;
209
- context . People . Add ( asignee ) ;
202
+ context . People . Add ( assignee ) ;
210
203
context . People . Add ( collectionOwner ) ;
211
204
context . People . Add ( someOtherOwner ) ;
212
205
context . TodoItemCollections . Add ( collection ) ;
213
206
214
207
215
208
await context . SaveChangesAsync ( ) ;
216
209
210
+ string route =
211
+ "/api/v1/todo-items/" + todoItem1 . Id + "?include=" +
212
+ "collection.owner," +
213
+ "assignee.role," +
214
+ "assignee.assigned-todo-items" ;
215
+
217
216
// act
218
217
var response = await _fixture . Client . GetAsync ( route ) ;
219
218
@@ -225,9 +224,35 @@ public async Task Included_Resources_Are_Correct()
225
224
var included = documents . Included ;
226
225
227
226
// 1 collection, 1 owner,
228
- // 1 asignee , 1 asignee role,
229
- // 2 assigned todo items
227
+ // 1 assignee , 1 assignee role,
228
+ // 2 assigned todo items (including the primary resource)
230
229
Assert . Equal ( 6 , included . Count ) ;
230
+
231
+
232
+ var collectionDocument = included . FindResource ( "todo-item-collections" , collection . Id ) ;
233
+ var ownerDocument = included . FindResource ( "people" , collectionOwner . Id ) ;
234
+ var assigneeDocument = included . FindResource ( "people" , assignee . Id ) ;
235
+ var roleDocument = included . FindResource ( "person-roles" , role . Id ) ;
236
+ var assignedTodo1 = included . FindResource ( "todo-items" , todoItem1 . Id ) ;
237
+ var assignedTodo2 = included . FindResource ( "todo-items" , todoItem2 . Id ) ;
238
+
239
+ Assert . NotNull ( assignedTodo1 ) ;
240
+ Assert . Equal ( todoItem1 . Id . ToString ( ) , assignedTodo1 . Id ) ;
241
+
242
+ Assert . NotNull ( assignedTodo2 ) ;
243
+ Assert . Equal ( todoItem2 . Id . ToString ( ) , assignedTodo2 . Id ) ;
244
+
245
+ Assert . NotNull ( collectionDocument ) ;
246
+ Assert . Equal ( collection . Id . ToString ( ) , collectionDocument . Id ) ;
247
+
248
+ Assert . NotNull ( ownerDocument ) ;
249
+ Assert . Equal ( collectionOwner . Id . ToString ( ) , ownerDocument . Id ) ;
250
+
251
+ Assert . NotNull ( assigneeDocument ) ;
252
+ Assert . Equal ( assignee . Id . ToString ( ) , assigneeDocument . Id ) ;
253
+
254
+ Assert . NotNull ( roleDocument ) ;
255
+ Assert . Equal ( role . Id . ToString ( ) , roleDocument . Id ) ;
231
256
}
232
257
}
233
258
}
0 commit comments