@@ -855,6 +855,127 @@ public async Task GetArticles_PageSizeLargerThanDataset_ReturnsAllAsync()
855855
856856 #endregion
857857
858+ #region Filtered Includes with Pagination Tests
859+
860+ [ Fact ]
861+ public async Task GetArticles_FilteredIncludesWithPagination_ReturnsCorrectDataAsync ( )
862+ {
863+ // Filter on included resource + pagination
864+ var response = await _client . GetAsync (
865+ "/api/articles?filter[author.name]=Alice&include=author&page[number]=1&page[size]=2&sort=id"
866+ ) ;
867+
868+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
869+
870+ var content = await response . Content . ReadAsStringAsync ( ) ;
871+ var document = JsonSerializer . Deserialize < JsonApiCollectionDocument < ResourceObject > > (
872+ content ,
873+ _jsonOptions
874+ ) ;
875+
876+ Assert . NotNull ( document ? . Data ) ;
877+ // Alice has 2 articles (ids 1 and 2), page size 2 should return both
878+ Assert . Equal ( 2 , document . Data . Count ( ) ) ;
879+
880+ // Verify pagination metadata reflects filtered count
881+ Assert . NotNull ( document . Meta ) ;
882+ Assert . Equal ( 2 , GetPaginationValue < int > ( document . Meta , "totalResources" ) ) ;
883+ Assert . Equal ( 1 , GetPaginationValue < int > ( document . Meta , "totalPages" ) ) ;
884+
885+ // Verify included author is Alice
886+ Assert . NotNull ( document . Included ) ;
887+ Assert . Single ( document . Included ) ;
888+ Assert . Equal ( "Alice" , document . Included . First ( ) . Attributes ? [ "name" ] ? . ToString ( ) ) ;
889+ }
890+
891+ [ Fact ]
892+ public async Task GetArticles_FilteredIncludesWithPaginationSecondPage_ReturnsCorrectDataAsync ( )
893+ {
894+ // Filter to published articles, include author, get second page
895+ var response = await _client . GetAsync (
896+ "/api/articles?filter[isPublished]=true&include=author&page[number]=2&page[size]=2&sort=id"
897+ ) ;
898+
899+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
900+
901+ var content = await response . Content . ReadAsStringAsync ( ) ;
902+ var document = JsonSerializer . Deserialize < JsonApiCollectionDocument < ResourceObject > > (
903+ content ,
904+ _jsonOptions
905+ ) ;
906+
907+ Assert . NotNull ( document ? . Data ) ;
908+ // 4 published articles, page 2 with size 2 should return 2 articles
909+ Assert . Equal ( 2 , document . Data . Count ( ) ) ;
910+
911+ // Verify pagination
912+ Assert . NotNull ( document . Meta ) ;
913+ Assert . Equal ( 4 , GetPaginationValue < int > ( document . Meta , "totalResources" ) ) ;
914+ Assert . Equal ( 2 , GetPaginationValue < int > ( document . Meta , "totalPages" ) ) ;
915+ Assert . Equal ( 2 , GetPaginationValue < int > ( document . Meta , "currentPage" ) ) ;
916+
917+ // Verify includes are present
918+ Assert . NotNull ( document . Included ) ;
919+ Assert . NotEmpty ( document . Included ) ;
920+ }
921+
922+ [ Fact ]
923+ public async Task GetArticles_MultipleIncludesWithFilterAndPagination_ReturnsAllIncludedAsync ( )
924+ {
925+ // Complex query: filter + multiple includes + pagination
926+ var response = await _client . GetAsync (
927+ "/api/articles?filter[viewCount][ge]=50&include=author,comments&page[number]=1&page[size]=3&sort=-viewCount"
928+ ) ;
929+
930+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
931+
932+ var content = await response . Content . ReadAsStringAsync ( ) ;
933+ var document = JsonSerializer . Deserialize < JsonApiCollectionDocument < ResourceObject > > (
934+ content ,
935+ _jsonOptions
936+ ) ;
937+
938+ Assert . NotNull ( document ? . Data ) ;
939+ // viewCount >= 50: articles with 50, 75, 100, 200 = 4 articles, page size 3
940+ Assert . Equal ( 3 , document . Data . Count ( ) ) ;
941+
942+ // Verify sorted by viewCount descending
943+ var ids = document . Data . Select ( r => r . Id ) . ToList ( ) ;
944+ Assert . Equal ( "4" , ids [ 0 ] ) ; // viewCount: 200
945+ Assert . Equal ( "1" , ids [ 1 ] ) ; // viewCount: 100
946+ Assert . Equal ( "5" , ids [ 2 ] ) ; // viewCount: 75
947+
948+ // Verify includes contain both authors and comments
949+ Assert . NotNull ( document . Included ) ;
950+ Assert . Contains ( document . Included , r => r . Type == "queryTestAuthor" ) ;
951+ }
952+
953+ [ Fact ]
954+ public async Task GetArticles_FilterOnIncludedResourceWithEmptyResult_ReturnsEmptyAsync ( )
955+ {
956+ // Filter on included resource that matches nothing
957+ var response = await _client . GetAsync (
958+ "/api/articles?filter[author.name]=NonexistentAuthor&include=author&page[number]=1&page[size]=10"
959+ ) ;
960+
961+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
962+
963+ var content = await response . Content . ReadAsStringAsync ( ) ;
964+ var document = JsonSerializer . Deserialize < JsonApiCollectionDocument < ResourceObject > > (
965+ content ,
966+ _jsonOptions
967+ ) ;
968+
969+ Assert . NotNull ( document ? . Data ) ;
970+ Assert . Empty ( document . Data ) ;
971+
972+ // Pagination should reflect zero results
973+ Assert . NotNull ( document . Meta ) ;
974+ Assert . Equal ( 0 , GetPaginationValue < int > ( document . Meta , "totalResources" ) ) ;
975+ }
976+
977+ #endregion
978+
858979 public void Dispose ( )
859980 {
860981 _client ? . Dispose ( ) ;
0 commit comments