1
+ using System . Net ;
2
+ using System . Net . Http ;
3
+ using System . Threading . Tasks ;
4
+ using Bogus ;
5
+ using JsonApiDotNetCoreExample ;
6
+ using JsonApiDotNetCoreExample . Data ;
7
+ using JsonApiDotNetCoreExample . Models ;
8
+ using Microsoft . AspNetCore . Hosting ;
9
+ using Newtonsoft . Json ;
10
+ using Xunit ;
11
+ using Person = JsonApiDotNetCoreExample . Models . Person ;
12
+
13
+ namespace JsonApiDotNetCoreExampleTests . Acceptance . Spec
14
+ {
15
+ [ Collection ( "WebHostCollection" ) ]
16
+ public class DeeplyNestedInclusionTests
17
+ {
18
+ private TestFixture < TestStartup > _fixture ;
19
+
20
+ public DeeplyNestedInclusionTests ( TestFixture < TestStartup > fixture )
21
+ {
22
+ _fixture = fixture ;
23
+ }
24
+
25
+ [ Fact ]
26
+ public async Task Can_Include_Nested_Relationships ( )
27
+ {
28
+ // arrange
29
+ const string route = "/api/v1/todo-items?include=collection.owner" ;
30
+
31
+ var todoItem = new TodoItem {
32
+ Collection = new TodoItemCollection {
33
+ Owner = new Person ( )
34
+ }
35
+ } ;
36
+
37
+ var context = _fixture . GetService < AppDbContext > ( ) ;
38
+ context . TodoItems . RemoveRange ( context . TodoItems ) ;
39
+ context . TodoItems . Add ( todoItem ) ;
40
+ await context . SaveChangesAsync ( ) ;
41
+
42
+ // act
43
+ var response = await _fixture . Client . GetAsync ( route ) ;
44
+
45
+ // assert
46
+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
47
+
48
+ var body = await response . Content . ReadAsStringAsync ( ) ;
49
+ var todoItems = _fixture . DeSerializer . DeserializeList < TodoItem > ( body ) ;
50
+
51
+ var responseTodoItem = Assert . Single ( todoItems ) ;
52
+ Assert . NotNull ( responseTodoItem ) ;
53
+ Assert . NotNull ( responseTodoItem . Collection ) ;
54
+ Assert . NotNull ( responseTodoItem . Collection . Owner ) ;
55
+ }
56
+ }
57
+ }
0 commit comments