@@ -349,6 +349,59 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
349349 responseDocument . Included [ 1 ] . Attributes [ "archivedAt" ] . Should ( ) . BeNull ( ) ;
350350 }
351351
352+ [ Fact ]
353+ public async Task Get_ToMany_relationship_excludes_archived ( )
354+ {
355+ // Arrange
356+ TelevisionStation station = _fakers . TelevisionStation . Generate ( ) ;
357+ station . Broadcasts = _fakers . TelevisionBroadcast . Generate ( 2 ) . ToHashSet ( ) ;
358+ station . Broadcasts . ElementAt ( 1 ) . ArchivedAt = null ;
359+
360+ await _testContext . RunOnDatabaseAsync ( async dbContext =>
361+ {
362+ dbContext . Stations . Add ( station ) ;
363+ await dbContext . SaveChangesAsync ( ) ;
364+ } ) ;
365+
366+ string route = $ "/televisionStations/{ station . StringId } /relationships/broadcasts";
367+
368+ // Act
369+ ( HttpResponseMessage httpResponse , Document responseDocument ) = await _testContext . ExecuteGetAsync < Document > ( route ) ;
370+
371+ // Assert
372+ httpResponse . Should ( ) . HaveStatusCode ( HttpStatusCode . OK ) ;
373+
374+ responseDocument . ManyData . Should ( ) . HaveCount ( 1 ) ;
375+ responseDocument . ManyData [ 0 ] . Id . Should ( ) . Be ( station . Broadcasts . ElementAt ( 1 ) . StringId ) ;
376+ }
377+
378+ [ Fact ]
379+ public async Task Get_ToMany_relationship_with_filter_includes_archived ( )
380+ {
381+ // Arrange
382+ TelevisionStation station = _fakers . TelevisionStation . Generate ( ) ;
383+ station . Broadcasts = _fakers . TelevisionBroadcast . Generate ( 2 ) . ToHashSet ( ) ;
384+ station . Broadcasts . ElementAt ( 1 ) . ArchivedAt = null ;
385+
386+ await _testContext . RunOnDatabaseAsync ( async dbContext =>
387+ {
388+ dbContext . Stations . Add ( station ) ;
389+ await dbContext . SaveChangesAsync ( ) ;
390+ } ) ;
391+
392+ string route = $ "/televisionStations/{ station . StringId } /relationships/broadcasts?filter=or(equals(archivedAt,null),not(equals(archivedAt,null)))";
393+
394+ // Act
395+ ( HttpResponseMessage httpResponse , Document responseDocument ) = await _testContext . ExecuteGetAsync < Document > ( route ) ;
396+
397+ // Assert
398+ httpResponse . Should ( ) . HaveStatusCode ( HttpStatusCode . OK ) ;
399+
400+ responseDocument . ManyData . Should ( ) . HaveCount ( 2 ) ;
401+ responseDocument . ManyData [ 0 ] . Id . Should ( ) . Be ( station . Broadcasts . ElementAt ( 0 ) . StringId ) ;
402+ responseDocument . ManyData [ 1 ] . Id . Should ( ) . Be ( station . Broadcasts . ElementAt ( 1 ) . StringId ) ;
403+ }
404+
352405 [ Fact ]
353406 public async Task Can_create_unarchived_resource ( )
354407 {
0 commit comments