@@ -1198,6 +1198,113 @@ public void SortCategory_ToSortCategory(SortCategory? sortCategory, bool expectN
11981198
11991199 #endregion
12001200
1201+ #region SortDirection
1202+
1203+ /// <summary>
1204+ /// Check that every SortDirection has a long name provided
1205+ /// </summary>
1206+ /// <param name="sortDirection">SortDirection value to check</param>
1207+ /// <param name="expectNull">True to expect a null value, false otherwise</param>
1208+ [ Theory ]
1209+ [ MemberData ( nameof ( GenerateSortDirectionTestData ) ) ]
1210+ public void SortDirection_LongName ( SortDirection ? sortDirection , bool expectNull )
1211+ {
1212+ var actual = sortDirection . LongName ( ) ;
1213+
1214+ if ( expectNull )
1215+ Assert . Null ( actual ) ;
1216+ else
1217+ Assert . NotNull ( actual ) ;
1218+ }
1219+
1220+ /// <summary>
1221+ /// Check that every SortDirection has a short name provided
1222+ /// </summary>
1223+ /// <param name="sortDirection">SortDirection value to check</param>
1224+ /// <param name="expectNull">True to expect a null value, false otherwise</param>
1225+ [ Theory ]
1226+ [ MemberData ( nameof ( GenerateSortDirectionTestData ) ) ]
1227+ public void SortDirection_ShortName ( SortDirection ? sortDirection , bool expectNull )
1228+ {
1229+ var actual = sortDirection . ShortName ( ) ;
1230+
1231+ if ( expectNull )
1232+ Assert . Null ( actual ) ;
1233+ else
1234+ Assert . NotNull ( actual ) ;
1235+ }
1236+
1237+ /// <summary>
1238+ /// Ensure that every SortDirection that has a short name that is unique
1239+ /// </summary>
1240+ [ Fact ]
1241+ public void SortDirection_ShortName_NoDuplicates ( )
1242+ {
1243+ var fullSortDirections = Enum . GetValues < SortDirection > ( ) . Cast < SortDirection > ( ) . ToList ( ) ;
1244+ var filteredSortDirections = new Dictionary < string , SortDirection ? > ( ) ;
1245+
1246+ int totalCount = 0 ;
1247+ foreach ( SortDirection ? sortDirection in fullSortDirections )
1248+ {
1249+ var code = sortDirection . ShortName ( ) ;
1250+ if ( string . IsNullOrEmpty ( code ) )
1251+ continue ;
1252+
1253+ // Throw if the code already exists
1254+ if ( filteredSortDirections . ContainsKey ( code ) )
1255+ throw new DuplicateNameException ( $ "Code { code } already in dictionary") ;
1256+
1257+ filteredSortDirections [ code ] = sortDirection ;
1258+ totalCount ++ ;
1259+ }
1260+
1261+ Assert . Equal ( totalCount , filteredSortDirections . Count ) ;
1262+ }
1263+
1264+ /// <summary>
1265+ /// Check that every SortDirection can be mapped from a string
1266+ /// </summary>
1267+ /// <param name="sortDirection">SortDirection value to check</param>
1268+ /// <param name="expectNull">True to expect a null value, false otherwise</param>
1269+ [ Theory ]
1270+ [ MemberData ( nameof ( GenerateSortDirectionTestData ) ) ]
1271+ public void SortDirection_ToSortDirection ( SortDirection ? sortDirection , bool expectNull )
1272+ {
1273+ string ? longName = sortDirection . LongName ( ) ;
1274+ string ? longNameSpaceless = longName ? . Replace ( " " , string . Empty ) ;
1275+
1276+ var actualNormal = longName . ToSortDirection ( ) ;
1277+ var actualSpaceless = longNameSpaceless . ToSortDirection ( ) ;
1278+
1279+ if ( expectNull )
1280+ {
1281+ Assert . Null ( actualNormal ) ;
1282+ Assert . Null ( actualSpaceless ) ;
1283+ }
1284+ else
1285+ {
1286+ Assert . Equal ( sortDirection , actualNormal ) ;
1287+ Assert . Equal ( sortDirection , actualSpaceless ) ;
1288+ }
1289+ }
1290+
1291+ /// <summary>
1292+ /// Generate a test set of SortDirection values
1293+ /// </summary>
1294+ /// <returns>MemberData-compatible list of SortDirection values</returns>
1295+ public static TheoryData < SortDirection ? , bool > GenerateSortDirectionTestData ( )
1296+ {
1297+ var testData = new TheoryData < SortDirection ? , bool > ( ) { { null , true } } ;
1298+ foreach ( SortDirection ? sortDirection in Enum . GetValues < SortDirection > ( ) . Cast < SortDirection ? > ( ) )
1299+ {
1300+ testData . Add ( sortDirection , false ) ;
1301+ }
1302+
1303+ return testData ;
1304+ }
1305+
1306+ #endregion
1307+
12011308 #region System
12021309
12031310 /// <summary>
0 commit comments