@@ -6,19 +6,34 @@ namespace System.Linq.Dynamic.Core.Tests
6
6
{
7
7
public partial class QueryableTests
8
8
{
9
+ [ Fact ]
10
+ public void OrderBy_Dynamic_IComparer ( )
11
+ {
12
+ // Arrange
13
+ var testList = User . GenerateSampleModels ( 2 ) ;
14
+ var qry = testList . AsQueryable ( ) ;
15
+
16
+ // Act
17
+ var orderBy = testList . OrderBy ( x => x . UserName , StringComparer . OrdinalIgnoreCase ) . ToArray ( ) ;
18
+ var orderByDynamic = qry . OrderBy ( "UserName" , StringComparer . OrdinalIgnoreCase ) . ToArray ( ) ;
19
+
20
+ // Assert
21
+ Assert . Equal ( orderBy , orderByDynamic ) ;
22
+ }
23
+
9
24
[ Fact ]
10
25
public void OrderBy_Dynamic ( )
11
26
{
12
- //Arrange
27
+ // Arrange
13
28
var testList = User . GenerateSampleModels ( 100 ) ;
14
29
var qry = testList . AsQueryable ( ) ;
15
30
16
- //Act
31
+ // Act
17
32
var orderById = qry . OrderBy ( "Id" ) ;
18
33
var orderByAge = qry . OrderBy ( "Profile.Age" ) ;
19
34
var orderByComplex1 = qry . OrderBy ( "Profile.Age, Id" ) ;
20
35
21
- //Assert
36
+ // Assert
22
37
Assert . Equal ( testList . OrderBy ( x => x . Id ) . ToArray ( ) , orderById . ToArray ( ) ) ;
23
38
Assert . Equal ( testList . OrderBy ( x => x . Profile . Age ) . ToArray ( ) , orderByAge . ToArray ( ) ) ;
24
39
Assert . Equal ( testList . OrderBy ( x => x . Profile . Age ) . ThenBy ( x => x . Id ) . ToArray ( ) , orderByComplex1 . ToArray ( ) ) ;
@@ -27,26 +42,26 @@ public void OrderBy_Dynamic()
27
42
[ Fact ]
28
43
public void OrderBy_Dynamic_AsStringExpression ( )
29
44
{
30
- //Arrange
45
+ // Arrange
31
46
var testList = User . GenerateSampleModels ( 100 ) ;
32
47
var qry = testList . AsQueryable ( ) ;
33
48
34
- //Act
49
+ // Act
35
50
var expected = qry . SelectMany ( x => x . Roles . OrderBy ( y => y . Name ) ) . Select ( x => x . Name ) ;
36
51
var orderById = qry . SelectMany ( "Roles.OrderBy(Name)" ) . Select ( "Name" ) ;
37
52
38
- //Assert
53
+ // Assert
39
54
Assert . Equal ( expected . ToArray ( ) , orderById . Cast < string > ( ) . ToArray ( ) ) ;
40
55
}
41
56
42
57
[ Fact ]
43
58
public void OrderBy_Dynamic_Exceptions ( )
44
59
{
45
- //Arrange
60
+ // Arrange
46
61
var testList = User . GenerateSampleModels ( 100 , allowNullableProfiles : true ) ;
47
62
var qry = testList . AsQueryable ( ) ;
48
63
49
- //Act
64
+ // Act
50
65
Assert . Throws < ParseException > ( ( ) => qry . OrderBy ( "Bad=3" ) ) ;
51
66
Assert . Throws < ParseException > ( ( ) => qry . Where ( "Id=123" ) ) ;
52
67
@@ -56,4 +71,4 @@ public void OrderBy_Dynamic_Exceptions()
56
71
Assert . Throws < ArgumentException > ( ( ) => qry . OrderBy ( " " ) ) ;
57
72
}
58
73
}
59
- }
74
+ }
0 commit comments