@@ -61,5 +61,42 @@ public async Task Total_Record_Count_Included()
61
61
foreach ( var item in deserializedBody )
62
62
Assert . Equal ( person . Id , item . OwnerId ) ;
63
63
}
64
+
65
+ [ Fact ]
66
+ public async Task Sparse_Fields_Works_With_Get_Override ( )
67
+ {
68
+ // arrange
69
+ var builder = new WebHostBuilder ( )
70
+ . UseStartup < AuthorizedStartup > ( ) ;
71
+ var server = new TestServer ( builder ) ;
72
+ var client = server . CreateClient ( ) ;
73
+ var context = ( AppDbContext ) server . Host . Services . GetService ( typeof ( AppDbContext ) ) ;
74
+ var jsonApiContext = ( IJsonApiContext ) server . Host . Services . GetService ( typeof ( IJsonApiContext ) ) ;
75
+
76
+ var person = new Person ( ) ;
77
+ context . People . Add ( person ) ;
78
+ var todoItem = new TodoItem ( ) ;
79
+ todoItem . Owner = person ;
80
+ context . TodoItems . Add ( todoItem ) ;
81
+ context . SaveChanges ( ) ;
82
+
83
+ var authService = ( IAuthorizationService ) server . Host . Services . GetService ( typeof ( IAuthorizationService ) ) ;
84
+ authService . CurrentUserId = person . Id ;
85
+
86
+ var httpMethod = new HttpMethod ( "GET" ) ;
87
+ var route = $ "/api/v1/todo-items/{ todoItem . Id } ?fields[todo-items]=description";
88
+
89
+ var request = new HttpRequestMessage ( httpMethod , route ) ;
90
+
91
+ // act
92
+ var response = await client . SendAsync ( request ) ;
93
+ var responseBody = await response . Content . ReadAsStringAsync ( ) ;
94
+ var deserializedBody = _fixture . GetService < IJsonApiDeSerializer > ( ) . Deserialize < TodoItem > ( responseBody ) ;
95
+
96
+ // assert
97
+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
98
+ Assert . Equal ( todoItem . Description , deserializedBody . Description ) ;
99
+
100
+ }
64
101
}
65
102
}
0 commit comments