@@ -23,6 +23,7 @@ public class Included
23
23
private AppDbContext _context ;
24
24
private Faker < Person > _personFaker ;
25
25
private Faker < TodoItem > _todoItemFaker ;
26
+ private Faker < TodoItemCollection > _todoItemCollectionFaker ;
26
27
27
28
public Included ( DocsFixture < Startup , JsonDocWriter > fixture )
28
29
{
@@ -35,6 +36,9 @@ public Included(DocsFixture<Startup, JsonDocWriter> fixture)
35
36
_todoItemFaker = new Faker < TodoItem > ( )
36
37
. RuleFor ( t => t . Description , f => f . Lorem . Sentence ( ) )
37
38
. RuleFor ( t => t . Ordinal , f => f . Random . Number ( ) ) ;
39
+
40
+ _todoItemCollectionFaker = new Faker < TodoItemCollection > ( )
41
+ . RuleFor ( t => t . Name , f => f . Company . CatchPhrase ( ) ) ;
38
42
}
39
43
40
44
[ Fact ]
@@ -163,5 +167,45 @@ public async Task GET_ById_Included_Contains_SideloadedData_ForOneToMany()
163
167
Assert . NotEmpty ( document . Included ) ;
164
168
Assert . Equal ( numberOfTodoItems , document . Included . Count ) ;
165
169
}
170
+
171
+ [ Fact ]
172
+ public async Task Can_Include_MultipleRelationships ( )
173
+ {
174
+ // arrange
175
+ var person = _personFaker . Generate ( ) ;
176
+ var todoItemCollection = _todoItemCollectionFaker . Generate ( ) ;
177
+ todoItemCollection . Owner = person ;
178
+
179
+ const int numberOfTodoItems = 5 ;
180
+ for ( var i = 0 ; i < numberOfTodoItems ; i ++ )
181
+ {
182
+ var todoItem = _todoItemFaker . Generate ( ) ;
183
+ todoItem . Owner = person ;
184
+ todoItem . Collection = todoItemCollection ;
185
+ _context . TodoItems . Add ( todoItem ) ;
186
+ _context . SaveChanges ( ) ;
187
+ }
188
+
189
+ var builder = new WebHostBuilder ( )
190
+ . UseStartup < Startup > ( ) ;
191
+
192
+ var httpMethod = new HttpMethod ( "GET" ) ;
193
+
194
+ var route = $ "/api/v1/people/{ person . Id } ?include=todo-items,todo-item-collections";
195
+
196
+ var server = new TestServer ( builder ) ;
197
+ var client = server . CreateClient ( ) ;
198
+ var request = new HttpRequestMessage ( httpMethod , route ) ;
199
+
200
+ // act
201
+ var response = await client . SendAsync ( request ) ;
202
+ var responseString = await response . Content . ReadAsStringAsync ( ) ;
203
+ var document = JsonConvert . DeserializeObject < Document > ( responseString ) ;
204
+
205
+ // assert
206
+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
207
+ Assert . NotEmpty ( document . Included ) ;
208
+ Assert . Equal ( numberOfTodoItems + 1 , document . Included . Count ) ;
209
+ }
166
210
}
167
211
}
0 commit comments