File tree 3 files changed +100
-0
lines changed
Src/NHibernate.Envers.Tests/NetSpecific/Integration/Tree
3 files changed +100
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" utf-8" ?>
2
+ <hibernate-mapping xmlns =" urn:nhibernate-mapping-2.2"
3
+ assembly =" NHibernate.Envers.Tests"
4
+ namespace =" NHibernate.Envers.Tests.NetSpecific.Integration.Tree" >
5
+ <class name =" TreeEntity" >
6
+ <id name =" Id" >
7
+ <generator class =" native" />
8
+ </id >
9
+ <property name =" Name" not-null =" true" />
10
+ <many-to-one name =" Parent" class =" TreeEntity" column =" parentKey" />
11
+ <list name =" Children" cascade =" all-delete-orphan" >
12
+ <key column =" parentKey" />
13
+ <index column =" parentInd" />
14
+ <one-to-many class =" TreeEntity" />
15
+ </list >
16
+ </class >
17
+ </hibernate-mapping >
Original file line number Diff line number Diff line change
1
+ using System . Collections . Generic ;
2
+ using NHibernate . Envers . Configuration . Attributes ;
3
+
4
+ namespace NHibernate . Envers . Tests . NetSpecific . Integration . Tree
5
+ {
6
+ [ Audited ]
7
+ public class TreeEntity
8
+ {
9
+ public virtual long Id { get ; set ; }
10
+ public virtual string Name { get ; set ; }
11
+ public virtual TreeEntity Parent { get ; set ; }
12
+ public virtual IList < TreeEntity > Children { get ; protected set ; } = new List < TreeEntity > ( ) ;
13
+
14
+ public override bool Equals ( object obj )
15
+ {
16
+ if ( ! ( obj is TreeEntity other ) )
17
+ return false ;
18
+ return Id == other . Id ;
19
+ }
20
+
21
+ public override int GetHashCode ( )
22
+ {
23
+ return Id . GetHashCode ( ) ;
24
+ }
25
+ }
26
+ }
Original file line number Diff line number Diff line change
1
+ using System . Collections . Generic ;
2
+ using NUnit . Framework ;
3
+
4
+ namespace NHibernate . Envers . Tests . NetSpecific . Integration . Tree
5
+ {
6
+ public class TreeTest : TestBase
7
+ {
8
+ private long parentId ;
9
+ private long childId ;
10
+
11
+ public TreeTest ( AuditStrategyForTest strategyType ) : base ( strategyType )
12
+ {
13
+ }
14
+
15
+ protected override IEnumerable < string > Mappings => new [ ] { "NetSpecific.Integration.Tree.Mapping.hbm.xml" } ;
16
+
17
+ protected override void Initialize ( )
18
+ {
19
+ var parent = new TreeEntity { Name = "Parent" } ;
20
+
21
+ using ( var tx = Session . BeginTransaction ( ) )
22
+ {
23
+ parentId = ( long ) Session . Save ( parent ) ;
24
+ tx . Commit ( ) ;
25
+ }
26
+
27
+ var child = new TreeEntity
28
+ {
29
+ Name = "Child" ,
30
+ Parent = new TreeEntity { Id = parentId }
31
+ } ;
32
+
33
+ using ( var tx = Session . BeginTransaction ( ) )
34
+ {
35
+ childId = ( long ) Session . Save ( child ) ;
36
+ tx . Commit ( ) ;
37
+ }
38
+ }
39
+
40
+ [ Test ]
41
+ public void VerifyRevisionCount ( )
42
+ {
43
+ CollectionAssert . AreEquivalent ( new [ ] { 1 } , AuditReader ( ) . GetRevisions ( typeof ( TreeEntity ) , parentId ) ) ;
44
+ CollectionAssert . AreEquivalent ( new [ ] { 2 } , AuditReader ( ) . GetRevisions ( typeof ( TreeEntity ) , childId ) ) ;
45
+ }
46
+
47
+ [ Test ]
48
+ public void VerifyHistory ( )
49
+ {
50
+ var rev1 = AuditReader ( ) . Find < TreeEntity > ( parentId , 1 ) ;
51
+ var rev2 = AuditReader ( ) . Find < TreeEntity > ( parentId , 2 ) ;
52
+
53
+ Assert . IsNotNull ( rev1 . Name ) ;
54
+ Assert . IsNotNull ( rev2 . Name ) ;
55
+ }
56
+ }
57
+ }
You can’t perform that action at this time.
0 commit comments