6
6
using NHibernate . Transform ;
7
7
using NHibernate . Util ;
8
8
using NUnit . Framework ;
9
+ using NUnit . Framework . SyntaxHelpers ;
9
10
10
11
namespace NHibernate . Test . QueryTest
11
12
{
12
13
[ TestFixture ]
13
- public class DetachedQueryFixture : TestCase
14
+ public class DetachedQueryFixture : TestCase
14
15
{
15
16
protected override string MappingsAssembly
16
17
{
@@ -23,6 +24,8 @@ protected override IList Mappings
23
24
}
24
25
25
26
public const int totalFoo = 15 ;
27
+ private const string MyComment = "My Comment" ;
28
+
26
29
protected override void OnSetUp ( )
27
30
{
28
31
using ( ISession s = OpenSession ( ) )
@@ -50,8 +53,8 @@ public void PropertiesSet()
50
53
{
51
54
TestDetachedQuery tdq = new TestDetachedQuery ( ) ;
52
55
tdq . SetMaxResults ( 10 ) . SetFirstResult ( 5 ) . SetCacheable ( true ) . SetReadOnly ( true ) . SetTimeout ( 444 ) . SetFlushMode (
53
- FlushMode . Auto ) . SetCacheRegion ( "A_REGION" ) . SetResultTransformer ( new AliasToBeanResultTransformer ( typeof ( NoFoo ) ) ) .
54
- SetIgnoreUknownNamedParameters ( true ) ;
56
+ FlushMode . Auto ) . SetCacheRegion ( "A_REGION" ) . SetResultTransformer ( new AliasToBeanResultTransformer ( typeof ( NoFoo ) ) ) .
57
+ SetIgnoreUknownNamedParameters ( true ) . SetComment ( MyComment ) ;
55
58
Assert . AreEqual ( 10 , tdq . Selection . MaxRows ) ;
56
59
Assert . AreEqual ( 5 , tdq . Selection . FirstRow ) ;
57
60
Assert . AreEqual ( 444 , tdq . Selection . Timeout ) ;
@@ -61,6 +64,7 @@ public void PropertiesSet()
61
64
Assert . AreEqual ( "A_REGION" , tdq . CacheRegion ) ;
62
65
Assert . IsNotNull ( tdq . ResultTransformer ) ;
63
66
Assert . IsTrue ( tdq . ShouldIgnoredUnknownNamedParameters ) ;
67
+ Assert . That ( tdq . Comment , Is . EqualTo ( MyComment ) ) ;
64
68
65
69
tdq . SetLockMode ( "LM1" , LockMode . Upgrade ) ;
66
70
tdq . SetLockMode ( "LM2" , LockMode . Write ) ;
@@ -77,7 +81,7 @@ public void PropertiesSet()
77
81
Assert . IsTrue ( tdq . OptionalUntypeParams [ 1 ] . Equals ( new Foo ( "Fulano" , "De Tal" ) ) ) ;
78
82
79
83
tdq . SetAnsiString ( 1 , "" ) ;
80
- tdq . SetBinary ( 2 , new byte [ ] { } ) ;
84
+ tdq . SetBinary ( 2 , new byte [ ] { } ) ;
81
85
tdq . SetBoolean ( 3 , false ) ;
82
86
tdq . SetByte ( 4 , 255 ) ;
83
87
tdq . SetCharacter ( 5 , 'A' ) ;
@@ -158,7 +162,7 @@ public void PropertiesSet()
158
162
Assert . AreEqual ( 1 , tdq . NamedUntypeParams . Count ) ;
159
163
Assert . IsTrue ( tdq . NamedUntypeParams . ContainsKey ( "Any" ) ) ;
160
164
161
- tdq . SetParameterList ( "UntypedList" , new int [ ] { 1 , 2 , 3 } ) ;
165
+ tdq . SetParameterList ( "UntypedList" , new int [ ] { 1 , 2 , 3 } ) ;
162
166
Assert . IsTrue ( tdq . NamedUntypeListParams . ContainsKey ( "UntypedList" ) ) ;
163
167
164
168
tdq . SetParameterList ( "TypedList" , new Int64 [ ] { 1 , 2 , 3 } , NHibernateUtil . Int64 ) ;
@@ -171,18 +175,19 @@ public void CopyToTest()
171
175
{
172
176
TestDetachedQuery origin = new TestDetachedQuery ( ) ;
173
177
origin . SetMaxResults ( 10 ) . SetFirstResult ( 5 ) . SetCacheable ( true ) . SetReadOnly ( true ) . SetTimeout ( 444 ) . SetFlushMode
174
- ( FlushMode . Auto ) . SetCacheRegion ( "A_REGION" ) . SetResultTransformer ( new AliasToBeanResultTransformer ( typeof ( NoFoo ) ) ) ;
178
+ ( FlushMode . Auto ) . SetCacheRegion ( "A_REGION" ) . SetResultTransformer ( new AliasToBeanResultTransformer ( typeof ( NoFoo ) ) ) ;
179
+ origin . SetComment ( MyComment ) ;
175
180
origin . SetLockMode ( "LM1" , LockMode . Upgrade ) ;
176
181
origin . SetProperties ( new Foo ( "Pallino" , "Pinco" ) ) ;
177
182
origin . SetInt64 ( 1 , 1 ) ;
178
- origin . SetBinary ( 2 , new byte [ ] { } ) ;
183
+ origin . SetBinary ( 2 , new byte [ ] { } ) ;
179
184
origin . SetBoolean ( 3 , false ) ;
180
185
origin . SetDateTime ( 6 , DateTime . MaxValue ) ;
181
186
origin . SetCharacter ( "5" , 'A' ) ;
182
187
origin . SetDateTime ( "6" , DateTime . MaxValue ) ;
183
188
origin . SetDecimal ( "7" , 10.15m ) ;
184
- origin . SetParameterList ( "UntypedList" , new int [ ] { 1 , 2 , 3 } ) ;
185
- origin . SetParameterList ( "TypedList" , new Int64 [ ] { 1 , 2 , 3 } , NHibernateUtil . Int64 ) ;
189
+ origin . SetParameterList ( "UntypedList" , new int [ ] { 1 , 2 , 3 } ) ;
190
+ origin . SetParameterList ( "TypedList" , new Int64 [ ] { 1 , 2 , 3 } , NHibernateUtil . Int64 ) ;
186
191
187
192
TestDetachedQuery tdq = new TestDetachedQuery ( ) ;
188
193
tdq . SetLockMode ( "LM1" , LockMode . Read ) ;
@@ -195,9 +200,9 @@ public void CopyToTest()
195
200
tdq . SetDateTime ( "6" , DateTime . MinValue ) ; // will be override
196
201
tdq . SetDouble ( "8" , 8.1f ) ;
197
202
tdq . SetEntity ( "9" , new Foo ( "Fulano" , "De Tal" ) ) ;
198
- tdq . SetParameterList ( "UntypedList" , new int [ ] { 5 , 6 , 7 , 8 } ) ; // will be override
199
- tdq . SetParameterList ( "TypedList" , new Int64 [ ] { 5 , 6 , 7 , 8 } , NHibernateUtil . Int64 ) ; // will be override
200
-
203
+ tdq . SetParameterList ( "UntypedList" , new int [ ] { 5 , 6 , 7 , 8 } ) ; // will be override
204
+ tdq . SetParameterList ( "TypedList" , new Int64 [ ] { 5 , 6 , 7 , 8 } , NHibernateUtil . Int64 ) ; // will be override
205
+ tdq . SetComment ( "other comment" ) ; // will be override
201
206
origin . CopyTo ( tdq ) ;
202
207
203
208
Assert . AreEqual ( 5 , tdq . Selection . FirstRow ) ;
@@ -207,6 +212,7 @@ public void CopyToTest()
207
212
Assert . AreEqual ( FlushMode . Auto , tdq . FlushMode ) ;
208
213
Assert . AreEqual ( "A_REGION" , tdq . CacheRegion ) ;
209
214
Assert . IsNotNull ( tdq . ResultTransformer ) ;
215
+ Assert . That ( tdq . Comment , Is . EqualTo ( MyComment ) ) ;
210
216
211
217
// merge/override of LockModes
212
218
Assert . AreEqual ( 2 , tdq . LockModes . Count ) ;
@@ -235,7 +241,7 @@ public void CopyToTest()
235
241
Assert . IsTrue ( tdq . NamedParams [ "6" ] . Value . Equals ( DateTime . MaxValue ) ) ;
236
242
Assert . IsTrue ( tdq . NamedParams [ "7" ] . Type . Equals ( NHibernateUtil . Decimal ) ) ;
237
243
Assert . IsTrue ( tdq . NamedParams [ "8" ] . Type . Equals ( NHibernateUtil . Double ) ) ;
238
- Assert . IsTrue ( tdq . NamedParams [ "9" ] . Type . Equals ( NHibernateUtil . Entity ( typeof ( Foo ) ) ) ) ;
244
+ Assert . IsTrue ( tdq . NamedParams [ "9" ] . Type . Equals ( NHibernateUtil . Entity ( typeof ( Foo ) ) ) ) ;
239
245
240
246
// merge/override named parameters list
241
247
int expected = 1 ;
@@ -349,7 +355,7 @@ public void ExecutableQuery()
349
355
350
356
// With UnTyped Parameter List
351
357
dq = new DetachedQuery ( "from Foo f where f.IntValue in (:pn)" ) ;
352
- dq . SetParameterList ( "pn" , new int [ ] { 2 , 3 } ) ;
358
+ dq . SetParameterList ( "pn" , new int [ ] { 2 , 3 } ) ;
353
359
using ( ISession s = OpenSession ( ) )
354
360
{
355
361
IQuery q = dq . GetExecutableQuery ( s ) ;
@@ -454,10 +460,10 @@ public void PerformanceDiffSimplyQuery()
454
460
455
461
456
462
Console . WriteLine ( "DetachedQueryCycle={0} QueryCycl={1} Diff={2}" , sDQStop - sDQStart , sQStop - sQStart ,
457
- ( sDQStop - sDQStart ) - ( sQStop - sQStart ) ) ;
463
+ ( sDQStop - sDQStart ) - ( sQStop - sQStart ) ) ;
458
464
}
459
465
460
- private class TestDetachedQuery : AbstractDetachedQuery
466
+ private class TestDetachedQuery : AbstractDetachedQuery
461
467
{
462
468
public Dictionary < int , object > PosUntypeParams
463
469
{
@@ -548,6 +554,11 @@ public void OverrideInfoFrom(IDetachedQueryImplementor origin)
548
554
{
549
555
( this as IDetachedQueryImplementor ) . OverrideInfoFrom ( origin ) ;
550
556
}
557
+
558
+ public string Comment
559
+ {
560
+ get { return comment ; }
561
+ }
551
562
}
552
563
}
553
564
@@ -593,7 +604,7 @@ public Foo(string name, string description)
593
604
}
594
605
595
606
public Foo ( string name , string description , int intValue )
596
- : this ( name , description )
607
+ : this ( name , description )
597
608
{
598
609
this . intValue = intValue ;
599
610
}
0 commit comments