@@ -24,6 +24,14 @@ public DeeplyNestedInclusionTests(TestFixture<TestStartup> fixture)
2424 _fixture = fixture ;
2525 }
2626
27+ private void ResetContext ( AppDbContext context )
28+ {
29+ context . TodoItems . RemoveRange ( context . TodoItems ) ;
30+ context . TodoItemCollections . RemoveRange ( context . TodoItemCollections ) ;
31+ context . People . RemoveRange ( context . People ) ;
32+ context . PersonRoles . RemoveRange ( context . PersonRoles ) ;
33+ }
34+
2735 [ Fact ]
2836 public async Task Can_Include_Nested_Relationships ( )
2937 {
@@ -72,8 +80,10 @@ public async Task Can_Include_Nested_HasMany_Relationships()
7280 }
7381 } ;
7482
83+
7584 var context = _fixture . GetService < AppDbContext > ( ) ;
76- context . TodoItems . RemoveRange ( context . TodoItems ) ;
85+ ResetContext ( context ) ;
86+
7787 context . TodoItems . Add ( todoItem ) ;
7888 await context . SaveChangesAsync ( ) ;
7989
@@ -109,7 +119,8 @@ public async Task Can_Include_Nested_HasMany_Relationships_BelongsTo()
109119 } ;
110120
111121 var context = _fixture . GetService < AppDbContext > ( ) ;
112- context . TodoItems . RemoveRange ( context . TodoItems ) ;
122+ ResetContext ( context ) ;
123+
113124 context . TodoItems . Add ( todoItem ) ;
114125 await context . SaveChangesAsync ( ) ;
115126
@@ -147,7 +158,8 @@ public async Task Can_Include_Nested_Relationships_With_Multiple_Paths()
147158 } ;
148159
149160 var context = _fixture . GetService < AppDbContext > ( ) ;
150- context . TodoItems . RemoveRange ( context . TodoItems ) ;
161+ ResetContext ( context ) ;
162+
151163 context . TodoItems . Add ( todoItem ) ;
152164 await context . SaveChangesAsync ( ) ;
153165
@@ -163,5 +175,59 @@ public async Task Can_Include_Nested_Relationships_With_Multiple_Paths()
163175
164176 Assert . Equal ( 7 , included . Count ) ; // 1 collection, 3 todos, 2 owners, 1 role
165177 }
178+
179+ [ Fact ]
180+ public async Task Included_Resources_Are_Correct ( )
181+ {
182+ // arrange
183+ var role = new PersonRole ( ) ;
184+ var asignee = new Person { Role = role } ;
185+ var collectionOwner = new Person ( ) ;
186+ var someOtherOwner = new Person ( ) ;
187+ var collection = new TodoItemCollection { Owner = collectionOwner } ;
188+ var todoItem1 = new TodoItem { Collection = collection , Assignee = asignee } ;
189+ var todoItem2 = new TodoItem { Collection = collection , Assignee = asignee } ;
190+ 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+
200+
201+ var context = _fixture . GetService < AppDbContext > ( ) ;
202+ ResetContext ( context ) ;
203+
204+ context . TodoItems . Add ( todoItem1 ) ;
205+ context . TodoItems . Add ( todoItem2 ) ;
206+ context . TodoItems . Add ( todoItem3 ) ;
207+ context . TodoItems . Add ( todoItem4 ) ;
208+ context . PersonRoles . Add ( role ) ;
209+ context . People . Add ( asignee ) ;
210+ context . People . Add ( collectionOwner ) ;
211+ context . People . Add ( someOtherOwner ) ;
212+ context . TodoItemCollections . Add ( collection ) ;
213+
214+
215+ await context . SaveChangesAsync ( ) ;
216+
217+ // act
218+ var response = await _fixture . Client . GetAsync ( route ) ;
219+
220+ // assert
221+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
222+
223+ var body = await response . Content . ReadAsStringAsync ( ) ;
224+ var documents = JsonConvert . DeserializeObject < Document > ( body ) ;
225+ var included = documents . Included ;
226+
227+ // 1 collection, 1 owner,
228+ // 1 asignee, 1 asignee role,
229+ // 2 assigned todo items
230+ Assert . Equal ( 6 , included . Count ) ;
231+ }
166232 }
167233}
0 commit comments