1+ using System ;
12using System . Collections . Generic ;
23using JsonApiDotNetCore . Builders ;
34using JsonApiDotNetCore . Internal . Query ;
@@ -23,7 +24,7 @@ public void Property_Sort_Order_Uses_NewExpression()
2324 // Assert
2425 Assert . Equal ( 2 , sorts . Count ) ;
2526
26- Assert . Equal ( nameof ( Model . Prop ) , sorts [ 0 ] . Attribute . PropertyInfo . Name ) ;
27+ Assert . Equal ( nameof ( Model . CreatedAt ) , sorts [ 0 ] . Attribute . PropertyInfo . Name ) ;
2728 Assert . Equal ( SortDirection . Ascending , sorts [ 0 ] . SortDirection ) ;
2829
2930 Assert . Equal ( nameof ( Model . Password ) , sorts [ 1 ] . Attribute . PropertyInfo . Name ) ;
@@ -62,7 +63,7 @@ public class Model : Identifiable
6263 {
6364 [ Attr ] public string AlwaysExcluded { get ; set ; }
6465 [ Attr ] public string Password { get ; set ; }
65- [ Attr ] public string Prop { get ; set ; }
66+ [ Attr ] public DateTime CreatedAt { get ; set ; }
6667 }
6768
6869 public sealed class RequestFilteredResource : ResourceDefinition < Model >
@@ -72,19 +73,21 @@ public sealed class RequestFilteredResource : ResourceDefinition<Model>
7273 public RequestFilteredResource ( bool isAdmin ) : base ( new ResourceGraphBuilder ( new JsonApiOptions ( ) , NullLoggerFactory . Instance ) . AddResource < Model > ( ) . Build ( ) )
7374 {
7475 if ( isAdmin )
75- HideFields ( m => m . AlwaysExcluded ) ;
76+ HideFields ( model => model . AlwaysExcluded ) ;
7677 else
77- HideFields ( m => new { m . AlwaysExcluded , m . Password } ) ;
78+ HideFields ( model => new { model . AlwaysExcluded , model . Password } ) ;
7879 }
7980
8081 public override QueryFilters GetQueryFilters ( )
8182 => new QueryFilters {
8283 { "is-active" , ( query , value ) => query . Select ( x => x ) }
8384 } ;
85+
8486 public override PropertySortOrder GetDefaultSortOrder ( )
85- => new PropertySortOrder {
86- ( t => t . Prop , SortDirection . Ascending ) ,
87- ( t => t . Password , SortDirection . Descending )
87+ => new PropertySortOrder
88+ {
89+ ( model => model . CreatedAt , SortDirection . Ascending ) ,
90+ ( model => model . Password , SortDirection . Descending )
8891 } ;
8992 }
9093}
0 commit comments