@@ -202,6 +202,31 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
202202 responseDocument . Should ( ) . NotContain ( toBeExcluded ) ;
203203 }
204204
205+ [ Fact ]
206+ public async Task Can_hide_secondary_resource_from_ToOne_relationship_using_OnReturn_hook ( )
207+ {
208+ // Arrange
209+ var person = _fakers . Person . Generate ( ) ;
210+ person . Passport = new Passport { IsLocked = true } ;
211+
212+ await _testContext . RunOnDatabaseAsync ( async dbContext =>
213+ {
214+ dbContext . People . Add ( person ) ;
215+ await dbContext . SaveChangesAsync ( ) ;
216+ } ) ;
217+
218+ var route = $ "/api/v1/people/{ person . Id } /passport";
219+
220+ // Act
221+ var ( httpResponse , responseDocument ) = await _testContext . ExecuteGetAsync < Document > ( route ) ;
222+
223+ // Assert
224+ httpResponse . Should ( ) . HaveStatusCode ( HttpStatusCode . OK ) ;
225+
226+ responseDocument . Data . Should ( ) . BeNull ( ) ;
227+ }
228+
229+
205230 [ Fact ]
206231 public async Task Can_hide_secondary_resource_from_ToMany_List_relationship_using_OnReturn_hook ( )
207232 {
@@ -233,24 +258,27 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
233258 public async Task Can_hide_secondary_resource_from_ToMany_Set_relationship_using_OnReturn_hook ( )
234259 {
235260 // Arrange
261+ string toBeExcluded = "This should not be included" ;
262+
236263 var person = _fakers . Person . Generate ( ) ;
237- person . Passport = new Passport { IsLocked = true } ;
264+ person . TodoItems = _fakers . TodoItem . Generate ( 3 ) . ToHashSet ( ) ;
265+ person . TodoItems . First ( ) . Description = toBeExcluded ;
238266
239267 await _testContext . RunOnDatabaseAsync ( async dbContext =>
240268 {
241269 dbContext . People . Add ( person ) ;
242270 await dbContext . SaveChangesAsync ( ) ;
243271 } ) ;
244272
245- var route = $ "/api/v1/people/{ person . Id } /passport ";
273+ var route = $ "/api/v1/people/{ person . Id } /todoItems ";
246274
247275 // Act
248- var ( httpResponse , responseDocument ) = await _testContext . ExecuteGetAsync < Document > ( route ) ;
276+ var ( httpResponse , responseDocument ) = await _testContext . ExecuteGetAsync < string > ( route ) ;
249277
250278 // Assert
251279 httpResponse . Should ( ) . HaveStatusCode ( HttpStatusCode . OK ) ;
252280
253- responseDocument . Data . Should ( ) . BeNull ( ) ;
281+ responseDocument . Should ( ) . NotContain ( toBeExcluded ) ;
254282 }
255283
256284 [ Fact ]
0 commit comments