4
4
using NHibernate . Criterion ;
5
5
using NHibernate . Envers . Query ;
6
6
using NHibernate . Envers . Tests . Entities ;
7
+ using NHibernate . Envers . Tests . Entities . Ids ;
7
8
using NUnit . Framework ;
8
9
using SharpTestsEx ;
9
10
@@ -14,25 +15,22 @@ public class SimpleQueryTest : TestBase
14
15
private int id1 ;
15
16
private int id2 ;
16
17
private int id3 ;
18
+ private EmbId embId ;
17
19
18
20
public SimpleQueryTest ( AuditStrategyForTest strategyType ) : base ( strategyType )
19
21
{
20
22
}
21
23
22
- protected override IEnumerable < string > Mappings
23
- {
24
- get
25
- {
26
- return new [ ] { "Entities.Mapping.hbm.xml" } ;
27
- }
28
- }
24
+ protected override IEnumerable < string > Mappings =>
25
+ new [ ] { "Entities.Mapping.hbm.xml" , "Entities.Ids.Mapping.hbm.xml" } ;
29
26
30
27
protected override void Initialize ( )
31
28
{
32
29
var site1 = new StrIntTestEntity { Str = "a" , Number = 10 } ;
33
30
var site2 = new StrIntTestEntity { Str = "a" , Number = 10 } ;
34
31
var site3 = new StrIntTestEntity { Str = "b" , Number = 5 } ;
35
-
32
+ embId = new EmbId { X = 3 , Y = 4 } ;
33
+
36
34
using ( var tx = Session . BeginTransaction ( ) )
37
35
{
38
36
id1 = ( int ) Session . Save ( site1 ) ;
@@ -42,6 +40,7 @@ protected override void Initialize()
42
40
}
43
41
using ( var tx = Session . BeginTransaction ( ) )
44
42
{
43
+ Session . Save ( new EmbIdTestEntity { Id = embId , Str1 = "something" } ) ;
45
44
site1 . Str = "aBc" ;
46
45
site2 . Number = 20 ;
47
46
tx . Commit ( ) ;
@@ -374,5 +373,27 @@ public void VerifyInsensitiveLikeWithMatchMode()
374
373
. Single ( )
375
374
. Should ( ) . Be . EqualTo ( site1 ) ;
376
375
}
376
+
377
+ [ Test ]
378
+ public void VerifyIdPropertyRestriction ( )
379
+ {
380
+ var ver2 = AuditReader ( ) . CreateQuery ( )
381
+ . ForEntitiesAtRevision < StrIntTestEntity > ( 2 )
382
+ . Add ( AuditEntity . Property ( "Id" ) . Eq ( id2 ) )
383
+ . Single ( ) ;
384
+ ver2 . Number . Should ( ) . Be . EqualTo ( 20 ) ;
385
+ ver2 . Str . Should ( ) . Be . EqualTo ( "a" ) ;
386
+ }
387
+
388
+ [ Test ]
389
+ public void VerifyEmbeddedIdPropertyRestriction ( )
390
+ {
391
+ var ver2 = AuditReader ( ) . CreateQuery ( )
392
+ . ForEntitiesAtRevision < EmbIdTestEntity > ( 2 )
393
+ . Add ( AuditEntity . Property ( "Id.X" ) . Eq ( embId . X ) )
394
+ . Add ( AuditEntity . Property ( "Id.Y" ) . Eq ( embId . Y ) )
395
+ . Single ( ) ;
396
+ ver2 . Str1 . Should ( ) . Be . EqualTo ( "something" ) ;
397
+ }
377
398
}
378
399
}
0 commit comments