@@ -228,7 +228,6 @@ public async Task Included_Resources_Are_Correct()
228
228
// 2 assigned todo items (including the primary resource)
229
229
Assert . Equal ( 6 , included . Count ) ;
230
230
231
-
232
231
var collectionDocument = included . FindResource ( "todo-collections" , collection . Id ) ;
233
232
var ownerDocument = included . FindResource ( "people" , collectionOwner . Id ) ;
234
233
var assigneeDocument = included . FindResource ( "people" , assignee . Id ) ;
@@ -254,5 +253,52 @@ public async Task Included_Resources_Are_Correct()
254
253
Assert . NotNull ( roleDocument ) ;
255
254
Assert . Equal ( role . Id . ToString ( ) , roleDocument . Id ) ;
256
255
}
256
+
257
+ [ Fact ]
258
+ public async Task Can_Include_Doubly_HasMany_Relationships ( )
259
+ {
260
+ // arrange
261
+ var person = new Person {
262
+ TodoItemCollections = new List < TodoItemCollection > {
263
+ new TodoItemCollection {
264
+ TodoItems = new List < TodoItem > {
265
+ new TodoItem ( ) ,
266
+ new TodoItem ( )
267
+ }
268
+ } ,
269
+ new TodoItemCollection {
270
+ TodoItems = new List < TodoItem > {
271
+ new TodoItem ( ) ,
272
+ new TodoItem ( ) ,
273
+ new TodoItem ( )
274
+ }
275
+ }
276
+ }
277
+ } ;
278
+
279
+ var context = _fixture . GetService < AppDbContext > ( ) ;
280
+ ResetContext ( context ) ;
281
+
282
+ context . People . Add ( person ) ;
283
+
284
+ await context . SaveChangesAsync ( ) ;
285
+
286
+ string route = "/api/v1/people/" + person . Id + "?include=todo-collections.todo-items" ;
287
+
288
+ // act
289
+ var response = await _fixture . Client . GetAsync ( route ) ;
290
+
291
+ // assert
292
+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
293
+
294
+ var body = await response . Content . ReadAsStringAsync ( ) ;
295
+ var documents = JsonConvert . DeserializeObject < Document > ( body ) ;
296
+ var included = documents . Included ;
297
+
298
+ Assert . Equal ( 7 , included . Count ) ;
299
+
300
+ Assert . Equal ( 5 , included . CountOfType ( "todo-items" ) ) ;
301
+ Assert . Equal ( 2 , included . CountOfType ( "todo-collections" ) ) ;
302
+ }
257
303
}
258
304
}
0 commit comments