@@ -18,24 +18,31 @@ public void ArbitraryCriterion()
18
18
ICriteria expected =
19
19
CreateTestCriteria ( typeof ( Person ) , "personAlias" )
20
20
. Add ( Restrictions . Lt ( "Age" , 65 ) )
21
- . Add ( Restrictions . Ge ( "personAlias.Age" , 18 ) ) ;
21
+ . Add ( Restrictions . Ge ( "personAlias.Age" , 18 ) )
22
+ . Add ( Restrictions . Not ( Restrictions . Ge ( "Age" , 65 ) ) )
23
+ . Add ( Restrictions . Not ( Restrictions . Lt ( "personAlias.Age" , 18 ) ) ) ;
22
24
23
25
Person personAlias = null ;
24
26
var actual =
25
27
CreateTestQueryOver < Person > ( ( ) => personAlias )
26
28
. Where ( Restrictions . Where < Person > ( p => p . Age < 65 ) )
27
- . And ( Restrictions . Where ( ( ) => personAlias . Age >= 18 ) ) ;
29
+ . And ( Restrictions . Where ( ( ) => personAlias . Age >= 18 ) )
30
+ . And ( Restrictions . WhereNot < Person > ( p => p . Age >= 65 ) )
31
+ . And ( Restrictions . WhereNot ( ( ) => personAlias . Age < 18 ) ) ;
28
32
29
33
AssertCriteriaAreEqual ( expected , actual ) ;
30
34
}
31
35
32
36
[ Test ]
33
- public void SqlFunctions ( )
37
+ public void SqlOperators ( )
34
38
{
35
39
ICriteria expected =
36
40
CreateTestCriteria ( typeof ( Person ) , "personAlias" )
37
41
. Add ( Restrictions . Between ( "Age" , 18 , 65 ) )
38
42
. Add ( Restrictions . Between ( "personAlias.Age" , 18 , 65 ) )
43
+ . Add ( Restrictions . In ( "Name" , new string [ ] { "name1" , "name2" , "name3" } ) )
44
+ . Add ( Restrictions . In ( "Name" , new ArrayList ( ) { "name1" , "name2" , "name3" } ) )
45
+ . Add ( Restrictions . InG < int > ( "Age" , new int [ ] { 1 , 2 , 3 } ) )
39
46
. Add ( Restrictions . InsensitiveLike ( "Name" , "test" ) )
40
47
. Add ( Restrictions . InsensitiveLike ( "Name" , "tEsT" , MatchMode . Anywhere ) )
41
48
. Add ( Restrictions . IsEmpty ( "Children" ) )
@@ -44,22 +51,56 @@ public void SqlFunctions()
44
51
. Add ( Restrictions . IsNull ( "Name" ) )
45
52
. Add ( Restrictions . Like ( "Name" , "%test%" ) )
46
53
. Add ( Restrictions . Like ( "Name" , "test" , MatchMode . Anywhere ) )
47
- . Add ( Restrictions . Like ( "Name" , "test" , MatchMode . Anywhere , '?' ) ) ;
54
+ . Add ( Restrictions . Like ( "Name" , "test" , MatchMode . Anywhere , '?' ) )
55
+ . Add ( Restrictions . NaturalId ( )
56
+ . Set ( "Name" , "my name" )
57
+ . Set ( "personAlias.Age" , 18 ) ) ;
48
58
49
59
Person personAlias = null ;
50
60
var actual =
51
61
CreateTestQueryOver < Person > ( ( ) => personAlias )
52
- . Where ( Restrictions . WhereProperty < Person > ( p => p . Age ) . IsBetween ( 18 ) . And ( 65 ) )
53
- . And ( Restrictions . WhereProperty ( ( ) => personAlias . Age ) . IsBetween ( 18 ) . And ( 65 ) )
54
- . And ( Restrictions . WhereProperty < Person > ( p => p . Name ) . IsInsensitiveLike ( "test" ) )
55
- . And ( Restrictions . WhereProperty < Person > ( p => p . Name ) . IsInsensitiveLike ( "tEsT" , MatchMode . Anywhere ) )
56
- . And ( Restrictions . WhereProperty < Person > ( p => p . Children ) . IsEmpty )
57
- . And ( Restrictions . WhereProperty < Person > ( p => p . Children ) . IsNotEmpty )
58
- . And ( Restrictions . WhereProperty < Person > ( p => p . Name ) . IsNotNull )
59
- . And ( Restrictions . WhereProperty < Person > ( p => p . Name ) . IsNull )
60
- . And ( Restrictions . WhereProperty < Person > ( p => p . Name ) . IsLike ( "%test%" ) )
61
- . And ( Restrictions . WhereProperty < Person > ( p => p . Name ) . IsLike ( "test" , MatchMode . Anywhere ) )
62
- . And ( Restrictions . WhereProperty < Person > ( p => p . Name ) . IsLike ( "test" , MatchMode . Anywhere , '?' ) ) ;
62
+ . Where ( Restrictions . On < Person > ( p => p . Age ) . IsBetween ( 18 ) . And ( 65 ) )
63
+ . And ( Restrictions . On ( ( ) => personAlias . Age ) . IsBetween ( 18 ) . And ( 65 ) )
64
+ . And ( Restrictions . On < Person > ( p => p . Name ) . IsIn ( new string [ ] { "name1" , "name2" , "name3" } ) )
65
+ . And ( Restrictions . On < Person > ( p => p . Name ) . IsIn ( new ArrayList ( ) { "name1" , "name2" , "name3" } ) )
66
+ . And ( Restrictions . On < Person > ( p => p . Age ) . IsInG < int > ( new int [ ] { 1 , 2 , 3 } ) )
67
+ . And ( Restrictions . On < Person > ( p => p . Name ) . IsInsensitiveLike ( "test" ) )
68
+ . And ( Restrictions . On < Person > ( p => p . Name ) . IsInsensitiveLike ( "tEsT" , MatchMode . Anywhere ) )
69
+ . And ( Restrictions . On < Person > ( p => p . Children ) . IsEmpty )
70
+ . And ( Restrictions . On < Person > ( p => p . Children ) . IsNotEmpty )
71
+ . And ( Restrictions . On < Person > ( p => p . Name ) . IsNotNull )
72
+ . And ( Restrictions . On < Person > ( p => p . Name ) . IsNull )
73
+ . And ( Restrictions . On < Person > ( p => p . Name ) . IsLike ( "%test%" ) )
74
+ . And ( Restrictions . On < Person > ( p => p . Name ) . IsLike ( "test" , MatchMode . Anywhere ) )
75
+ . And ( Restrictions . On < Person > ( p => p . Name ) . IsLike ( "test" , MatchMode . Anywhere , '?' ) )
76
+ . And ( Restrictions . NaturalId ( )
77
+ . Set < Person > ( p => p . Name ) . Is ( "my name" )
78
+ . Set ( ( ) => personAlias . Age ) . Is ( 18 ) ) ;
79
+
80
+ AssertCriteriaAreEqual ( expected , actual ) ;
81
+ }
82
+
83
+ [ Test ]
84
+ public void Junction ( )
85
+ {
86
+ ICriteria expected =
87
+ CreateTestCriteria ( typeof ( Person ) , "personAlias" )
88
+ . Add ( Restrictions . Conjunction ( )
89
+ . Add ( Restrictions . Eq ( "Name" , "test" ) )
90
+ . Add ( Restrictions . Eq ( "personAlias.Name" , "test" ) ) )
91
+ . Add ( Restrictions . Disjunction ( )
92
+ . Add ( Restrictions . Eq ( "Name" , "test" ) )
93
+ . Add ( Restrictions . Eq ( "personAlias.Name" , "test" ) ) ) ;
94
+
95
+ Person personAlias = null ;
96
+ var actual =
97
+ CreateTestQueryOver < Person > ( ( ) => personAlias )
98
+ . Where ( Restrictions . Conjunction ( )
99
+ . Add < Person > ( p => p . Name == "test" )
100
+ . Add ( ( ) => personAlias . Name == "test" ) )
101
+ . And ( Restrictions . Disjunction ( )
102
+ . Add < Person > ( p => p . Name == "test" )
103
+ . Add ( ( ) => personAlias . Name == "test" ) ) ;
63
104
64
105
AssertCriteriaAreEqual ( expected , actual ) ;
65
106
}
0 commit comments