File tree Expand file tree Collapse file tree 3 files changed +139
-0
lines changed
Src/NHibernate.Envers.Tests/NetSpecific/Integration/ComponentAsId Expand file tree Collapse file tree 3 files changed +139
-0
lines changed Original file line number Diff line number Diff line change
1
+ using NUnit . Framework ;
2
+
3
+ namespace NHibernate . Envers . Tests . NetSpecific . Integration . ComponentAsId
4
+ {
5
+ public class ComponentAsIdTest : TestBase
6
+ {
7
+ public ComponentAsIdTest ( AuditStrategyForTest strategyType ) : base ( strategyType )
8
+ {
9
+ }
10
+
11
+ [ Test ]
12
+ public void ComponentAsIdTestMethod ( )
13
+ {
14
+ Assert . DoesNotThrow ( ( ) =>
15
+ {
16
+ var ent1 = new Entity1
17
+ {
18
+ Id = 1
19
+ } ;
20
+
21
+ Save ( ent1 ) ;
22
+
23
+ var ent2 = new Entity2 ( )
24
+ {
25
+ Id = 1
26
+ } ;
27
+
28
+ Save ( ent2 ) ;
29
+
30
+ var udf = new SomeEntUDF
31
+ {
32
+ Id = new ComponentAsId
33
+ {
34
+ Key1 = ent1 ,
35
+ Key2 = ent2
36
+ }
37
+ } ;
38
+
39
+ Save ( udf ) ;
40
+
41
+ Del ( udf ) ;
42
+ Del ( ent1 ) ;
43
+ } ) ;
44
+ }
45
+
46
+ void Save ( object o )
47
+ {
48
+ using ( var tran = Session . BeginTransaction ( ) )
49
+ {
50
+ Session . Save ( o ) ;
51
+ tran . Commit ( ) ;
52
+ }
53
+ }
54
+
55
+ void Del ( object o )
56
+ {
57
+ using ( var tran = Session . BeginTransaction ( ) )
58
+ {
59
+ Session . Delete ( o ) ;
60
+ tran . Commit ( ) ;
61
+ }
62
+ }
63
+
64
+ protected override void Initialize ( )
65
+ {
66
+ }
67
+ }
68
+ }
Original file line number Diff line number Diff line change
1
+ using NHibernate . Envers . Configuration . Attributes ;
2
+
3
+ namespace NHibernate . Envers . Tests . NetSpecific . Integration . ComponentAsId
4
+ {
5
+ public class ComponentAsId
6
+ {
7
+ public Entity2 Key2 { get ; set ; }
8
+ public Entity1 Key1 { get ; set ; }
9
+
10
+ public override bool Equals ( object obj )
11
+ {
12
+ if ( obj == null )
13
+ return false ;
14
+
15
+ if ( ! ( obj is ComponentAsId ) )
16
+ return false ;
17
+
18
+ if ( ! ReferenceEquals ( this , obj ) )
19
+ return false ;
20
+
21
+ var other = obj as ComponentAsId ;
22
+
23
+ return Key1 . Id == other . Key1 . Id && Key2 . Id == other . Key2 . Id ;
24
+ }
25
+
26
+ public override int GetHashCode ( )
27
+ {
28
+ return 1 ;
29
+ }
30
+ }
31
+
32
+ [ Audited ]
33
+ public class Entity1
34
+ {
35
+ public virtual int Id { get ; set ; }
36
+ }
37
+
38
+ [ Audited ]
39
+ public class Entity2
40
+ {
41
+ public virtual int Id { get ; set ; }
42
+ }
43
+
44
+ [ Audited ]
45
+ public class SomeEntUDF
46
+ {
47
+ public virtual ComponentAsId Id { get ; set ; }
48
+ }
49
+ }
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" utf-8" ?>
2
+ <hibernate-mapping
3
+ namespace =" NHibernate.Envers.Tests.NetSpecific.Integration.ComponentAsId"
4
+ assembly =" NHibernate.Envers.Tests"
5
+ xmlns =" urn:nhibernate-mapping-2.2" >
6
+
7
+ <class name =" Entity1" >
8
+ <id name =" Id" type =" Int32" />
9
+ </class >
10
+
11
+ <class name =" Entity2" >
12
+ <id name =" Id" type =" Int32" />
13
+ </class >
14
+
15
+ <class name =" SomeEntUDF" >
16
+ <composite-id class =" ComponentAsId" name =" Id" >
17
+ <key-many-to-one name =" Key1" />
18
+ <key-many-to-one name =" Key2" />
19
+ </composite-id >
20
+ </class >
21
+
22
+ </hibernate-mapping >
You can’t perform that action at this time.
0 commit comments