Skip to content

Commit d01ded7

Browse files
committed
Fixing NHE-164: Mainly a port of HHH-7940
1 parent 2f3180e commit d01ded7

21 files changed

+674
-86
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
2+
assembly="NHibernate.Envers.Tests"
3+
namespace="NHibernate.Envers.Tests.Integration.Collection">
4+
<class name="IndexColumnListTestParent">
5+
<id name="Id">
6+
<generator class="assigned"/>
7+
</id>
8+
<list name="Children">
9+
<key column ="parentId" />
10+
<index column="stringIndex"/>
11+
<element column="string" type="string" />
12+
</list>
13+
</class>
14+
</hibernate-mapping>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using System.Collections.Generic;
2+
using NHibernate.Envers.Configuration.Attributes;
3+
using NUnit.Framework;
4+
using SharpTestsEx;
5+
6+
namespace NHibernate.Envers.Tests.Integration.Collection
7+
{
8+
public class IndexColumnListTest :TestBase
9+
{
10+
public IndexColumnListTest(string strategyType) : base(strategyType)
11+
{
12+
}
13+
14+
protected override void Initialize()
15+
{
16+
var parent = new IndexColumnListTestParent(1);
17+
using(var tx = Session.BeginTransaction())
18+
{
19+
parent.Children.Add("child1");
20+
parent.Children.Add("child2");
21+
Session.Save(parent);
22+
tx.Commit();
23+
}
24+
using(var tx = Session.BeginTransaction())
25+
{
26+
parent.Children.RemoveAt(0);
27+
Session.Merge(parent);
28+
tx.Commit();
29+
}
30+
using(var tx = Session.BeginTransaction())
31+
{
32+
parent.Children.Insert(0, "child3");
33+
Session.Merge(parent);
34+
tx.Commit();
35+
}
36+
using(var tx = Session.BeginTransaction())
37+
{
38+
parent.Children.Clear();
39+
Session.Merge(parent);
40+
tx.Commit();
41+
}
42+
}
43+
44+
[Test]
45+
public void VerifyRevisionCount()
46+
{
47+
CollectionAssert.AreEquivalent(new[] { 1, 2, 3, 4 }, AuditReader().GetRevisions(typeof(IndexColumnListTestParent), 1));
48+
}
49+
50+
[Test]
51+
public void VerifyIndexCollectionRev1()
52+
{
53+
var parent = AuditReader().Find<IndexColumnListTestParent>(1, 1);
54+
parent.Children.Should().Have.SameSequenceAs("child1", "child2");
55+
}
56+
57+
[Test]
58+
public void VerifyIndexCollectionRev2()
59+
{
60+
var parent = AuditReader().Find<IndexColumnListTestParent>(1, 2);
61+
parent.Children.Should().Have.SameSequenceAs("child2");
62+
}
63+
64+
[Test]
65+
public void VerifyIndexCollectionRev3()
66+
{
67+
var parent = AuditReader().Find<IndexColumnListTestParent>(1, 3);
68+
parent.Children.Should().Have.SameSequenceAs("child3", "child2");
69+
}
70+
71+
[Test]
72+
public void VerifyIndexCollectionRev4()
73+
{
74+
var parent = AuditReader().Find<IndexColumnListTestParent>(1, 4);
75+
parent.Children.Should().Be.Empty();
76+
}
77+
78+
protected override IEnumerable<string> Mappings => new[] { "Integration.Collection.IndexColumnList.hbm.xml" };
79+
}
80+
81+
[Audited]
82+
public class IndexColumnListTestParent
83+
{
84+
public IndexColumnListTestParent(int id)
85+
{
86+
Id = id;
87+
Children = new List<string>();
88+
}
89+
public IndexColumnListTestParent()
90+
{
91+
}
92+
93+
public virtual int Id { get; protected set; }
94+
public virtual IList<string> Children { get; protected set; }
95+
96+
public override bool Equals(object obj)
97+
{
98+
var that = obj as IndexColumnListTestParent;
99+
return that?.Id == Id;
100+
}
101+
102+
public override int GetHashCode()
103+
{
104+
return Id.GetHashCode();
105+
}
106+
}
107+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
2+
assembly="NHibernate.Envers.Tests"
3+
namespace="NHibernate.Envers.Tests.Integration.ManyToMany">
4+
<class name="IndexColumnListTestParent">
5+
<id name="Id">
6+
<generator class="assigned"/>
7+
</id>
8+
<list name="Children" table="ParentChild">
9+
<key column ="parentId" />
10+
<index column="childIndex"/>
11+
<many-to-many class="IndexColumnListTestChild" column="childId"/>
12+
</list>
13+
</class>
14+
15+
<class name="IndexColumnListTestChild">
16+
<id name="Id">
17+
<generator class="assigned"/>
18+
</id>
19+
<bag name="Parents" inverse="true" table="ParentChild">
20+
<key column ="childId" />
21+
<many-to-many class="IndexColumnListTestParent" column="parentId"/>
22+
</bag>
23+
</class>
24+
</hibernate-mapping>
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using NHibernate.Envers.Configuration.Attributes;
4+
using NHibernate.Util;
5+
using NUnit.Framework;
6+
using SharpTestsEx;
7+
8+
namespace NHibernate.Envers.Tests.Integration.ManyToMany
9+
{
10+
public class IndexColumnListTest :TestBase
11+
{
12+
public IndexColumnListTest(string strategyType) : base(strategyType)
13+
{
14+
}
15+
16+
protected override void Initialize()
17+
{
18+
var parent = new IndexColumnListTestParent(1);
19+
using(var tx = Session.BeginTransaction())
20+
{
21+
parent.AddChild(new IndexColumnListTestChild(1, "child1"));
22+
parent.AddChild(new IndexColumnListTestChild(2, "child2"));
23+
Session.Save(parent);
24+
parent.Children.ForEach(x => Session.Save(x));
25+
tx.Commit();
26+
}
27+
using(var tx = Session.BeginTransaction())
28+
{
29+
parent.RemoveChild(parent.Children[0]);
30+
Session.Merge(parent);
31+
tx.Commit();
32+
}
33+
using(var tx = Session.BeginTransaction())
34+
{
35+
var child = new IndexColumnListTestChild(3, "child3");
36+
parent.Children.Insert(0, child);
37+
child.Parents.Add(parent);
38+
Session.Save(child);
39+
Session.Merge(parent);
40+
tx.Commit();
41+
}
42+
using(var tx = Session.BeginTransaction())
43+
{
44+
while (parent.Children.Any())
45+
{
46+
var child = parent.Children[0];
47+
parent.Children.Remove(child);
48+
Session.Delete(child);
49+
}
50+
Session.Merge(parent);
51+
tx.Commit();
52+
}
53+
}
54+
55+
[Test]
56+
public void VerifyRevisionCounts()
57+
{
58+
CollectionAssert.AreEquivalent(new[] { 1, 2, 3, 4 }, AuditReader().GetRevisions(typeof(IndexColumnListTestParent), 1));
59+
CollectionAssert.AreEquivalent(new[] { 1, 2 }, AuditReader().GetRevisions(typeof(IndexColumnListTestChild), 1));
60+
CollectionAssert.AreEquivalent(new[] { 1, 2, 3, 4 }, AuditReader().GetRevisions(typeof(IndexColumnListTestChild), 2));
61+
CollectionAssert.AreEquivalent(new[] { 3, 4 }, AuditReader().GetRevisions(typeof(IndexColumnListTestChild), 3));
62+
}
63+
64+
[Test]
65+
public void VerifyIndexCollectionRev1()
66+
{
67+
var parent = AuditReader().Find<IndexColumnListTestParent>(1, 1);
68+
parent.Children.Select(x => x.Id).Should().Have.SameSequenceAs(1, 2);
69+
}
70+
71+
[Test]
72+
public void VerifyIndexCollectionRev2()
73+
{
74+
var parent = AuditReader().Find<IndexColumnListTestParent>(1, 2);
75+
parent.Children.Select(x => x.Id).Should().Have.SameSequenceAs(2);
76+
}
77+
78+
[Test]
79+
public void VerifyIndexCollectionRev3()
80+
{
81+
var parent = AuditReader().Find<IndexColumnListTestParent>(1, 3);
82+
parent.Children.Select(x => x.Id).Should().Have.SameSequenceAs(3, 2);
83+
}
84+
85+
[Test]
86+
public void VerifyIndexCollectionRev4()
87+
{
88+
var parent = AuditReader().Find<IndexColumnListTestParent>(1, 4);
89+
parent.Children.Should().Be.Empty();
90+
}
91+
92+
protected override IEnumerable<string> Mappings => new[] { "Integration.ManyToMany.IndexColumnList.hbm.xml" };
93+
}
94+
95+
[Audited]
96+
public class IndexColumnListTestParent
97+
{
98+
public IndexColumnListTestParent(int id)
99+
{
100+
Id = id;
101+
Children = new List<IndexColumnListTestChild>();
102+
}
103+
public IndexColumnListTestParent()
104+
{
105+
}
106+
107+
public virtual int Id { get; protected set; }
108+
public virtual IList<IndexColumnListTestChild> Children { get; protected set; }
109+
110+
public virtual void AddChild(IndexColumnListTestChild child)
111+
{
112+
child.Parents.Add(this);
113+
Children.Add(child);
114+
}
115+
116+
public virtual void RemoveChild(IndexColumnListTestChild child)
117+
{
118+
child.Parents.Remove(this);
119+
Children.Remove(child);
120+
}
121+
122+
public override bool Equals(object obj)
123+
{
124+
var that = obj as IndexColumnListTestParent;
125+
return that?.Id == Id;
126+
}
127+
128+
public override int GetHashCode()
129+
{
130+
return Id.GetHashCode();
131+
}
132+
}
133+
134+
[Audited]
135+
public class IndexColumnListTestChild
136+
{
137+
public IndexColumnListTestChild(int id, string name)
138+
{
139+
Id = id;
140+
Name = name;
141+
Parents = new List<IndexColumnListTestParent>();
142+
}
143+
public IndexColumnListTestChild()
144+
{
145+
}
146+
147+
public virtual int Id { get; protected set; }
148+
public virtual string Name { get; protected set; }
149+
public virtual IList<IndexColumnListTestParent> Parents { get; protected set; }
150+
151+
public override bool Equals(object obj)
152+
{
153+
var that = obj as IndexColumnListTestChild;
154+
return that?.Id == Id;
155+
}
156+
157+
public override int GetHashCode()
158+
{
159+
return Id.GetHashCode();
160+
}
161+
}
162+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
2+
assembly="NHibernate.Envers.Tests"
3+
namespace="NHibernate.Envers.Tests.Integration.OneToMany">
4+
<class name="IndexColumnListTestParent">
5+
<id name="Id">
6+
<generator class="assigned"/>
7+
</id>
8+
<list name="Children" inverse="true">
9+
<key column ="parentId" />
10+
<index column="childIndex"/>
11+
<one-to-many class="IndexColumnListTestChild" />
12+
</list>
13+
</class>
14+
15+
<class name="IndexColumnListTestChild">
16+
<id name="Id">
17+
<generator class="assigned"/>
18+
</id>
19+
<many-to-one name="Parent" column="parentId" />
20+
</class>
21+
</hibernate-mapping>

0 commit comments

Comments
 (0)