@@ -401,6 +401,108 @@ void Test(ICollection<CoreBuilding> collection)
401401 }
402402 }
403403
404+ [ Fact ]
405+ public async void BuildingWithoutTopAndPageSize ( )
406+ {
407+ Test ( await Get < CoreBuilding , TBuilding > ( "/corebuilding" ) ) ;
408+
409+ void Test ( ICollection < CoreBuilding > collection )
410+ {
411+ Assert . Equal ( 5 , collection . Count ) ;
412+ }
413+ }
414+
415+ [ Fact ]
416+ public async void BuildingWithTopOnly ( )
417+ {
418+ Test ( await Get < CoreBuilding , TBuilding > ( "/corebuilding?$top=3" ) ) ;
419+
420+ void Test ( ICollection < CoreBuilding > collection )
421+ {
422+ Assert . Equal ( 3 , collection . Count ) ;
423+ }
424+ }
425+
426+ [ Fact ]
427+ public async void BuildingWithPageSizeOnly ( )
428+ {
429+ Test ( await Get < CoreBuilding , TBuilding > ( "/corebuilding" , pageSize : 2 ) ) ;
430+
431+ void Test ( ICollection < CoreBuilding > collection )
432+ {
433+ Assert . Equal ( 2 , collection . Count ) ;
434+ }
435+ }
436+
437+ [ Fact ]
438+ public async void BuildingWithTopAndSmallerPageSize ( )
439+ {
440+ Test ( await Get < CoreBuilding , TBuilding > ( "/corebuilding?$top=3" , pageSize : 2 ) ) ;
441+
442+ void Test ( ICollection < CoreBuilding > collection )
443+ {
444+ Assert . Equal ( 2 , collection . Count ) ;
445+ }
446+ }
447+
448+ [ Fact ]
449+ public async void BuildingWithTopAndLargerPageSize ( )
450+ {
451+ Test ( await Get < CoreBuilding , TBuilding > ( "/corebuilding?$top=3" , pageSize : 4 ) ) ;
452+
453+ void Test ( ICollection < CoreBuilding > collection )
454+ {
455+ Assert . Equal ( 3 , collection . Count ) ;
456+ }
457+ }
458+
459+ [ Fact ]
460+ public async void BuildingWithTopAndSmallerPageSizeNextLink ( )
461+ {
462+ int pageSize = 2 ;
463+ string query = "/corebuilding?$top=3" ;
464+ ODataQueryOptions < CoreBuilding > options = ODataHelpers . GetODataQueryOptions < CoreBuilding >
465+ (
466+ query ,
467+ serviceProvider ,
468+ serviceProvider . GetRequiredService < IRouteBuilder > ( )
469+ ) ;
470+
471+ Test ( await Get < CoreBuilding , TBuilding > ( query , options , null , pageSize ) ) ;
472+
473+ void Test ( ICollection < CoreBuilding > collection )
474+ {
475+ Assert . Equal ( 2 , collection . Count ) ;
476+
477+ Uri nextPageLink = options . Request . ODataFeature ( ) . NextLink ;
478+ Assert . NotNull ( nextPageLink ) ;
479+ Assert . Equal ( "localhost:16324/corebuilding?$top=1&$skip=2" , nextPageLink . AbsoluteUri ) ;
480+ Assert . Contains ( "$top=1" , nextPageLink . Query ) ;
481+ Assert . Contains ( "$skip=2" , nextPageLink . Query ) ;
482+ }
483+ }
484+
485+ [ Fact ]
486+ public async void BuildingWithTopAndLargerPageSizeNextLink ( )
487+ {
488+ int pageSize = 4 ;
489+ string query = "/corebuilding?$top=3" ;
490+ ODataQueryOptions < CoreBuilding > options = ODataHelpers . GetODataQueryOptions < CoreBuilding >
491+ (
492+ query ,
493+ serviceProvider ,
494+ serviceProvider . GetRequiredService < IRouteBuilder > ( )
495+ ) ;
496+
497+ Test ( await Get < CoreBuilding , TBuilding > ( query , options , null , pageSize ) ) ;
498+
499+ void Test ( ICollection < CoreBuilding > collection )
500+ {
501+ Assert . Equal ( 3 , collection . Count ) ;
502+ Assert . Null ( options . Request . ODataFeature ( ) . NextLink ) ;
503+ }
504+ }
505+
404506 [ Fact ]
405507 public async void OpsTenantOrderByCountOfReference ( )
406508 {
@@ -661,13 +763,28 @@ async Task<IQueryable<TModel>> DoGet(IMapper mapper)
661763 }
662764 }
663765
664- private async Task < ICollection < TModel > > Get < TModel , TData > ( string query , ODataQueryOptions < TModel > options = null , QuerySettings querySettings = null ) where TModel : class where TData : class
665- => await Get
766+ private async Task < ICollection < TModel > > Get < TModel , TData > ( string query , ODataQueryOptions < TModel > options = null , QuerySettings querySettings = null , int ? pageSize = null ) where TModel : class where TData : class
767+ {
768+ return await Get
666769 (
667770 query ,
668771 serviceProvider . GetRequiredService < TestDbContext > ( ) . Set < TData > ( ) ,
669772 options ,
670- querySettings
773+ GetQuerySettings ( )
671774 ) ;
775+
776+ QuerySettings GetQuerySettings ( )
777+ {
778+ if ( querySettings == null )
779+ return new QuerySettings { ODataSettings = new ODataSettings { PageSize = pageSize } } ;
780+
781+ if ( querySettings . ODataSettings == null )
782+ querySettings . ODataSettings = new ODataSettings { PageSize = pageSize } ;
783+ else
784+ querySettings . ODataSettings . PageSize = pageSize ;
785+
786+ return querySettings ;
787+ }
788+ }
672789 }
673790}
0 commit comments