Skip to content

Commit 94e1483

Browse files
author
Rico Pfennig
committed
Added test for issue NHE-161: https://nhibernate.jira.com/browse/NHE-161
1 parent 8a85bb0 commit 94e1483

File tree

4 files changed

+105
-0
lines changed

4 files changed

+105
-0
lines changed

Src/NHibernate.Envers.Tests/NHibernate.Envers.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@
149149
<Compile Include="NetSpecific\Integration\RevInfo\Time\LongTest.cs" />
150150
<Compile Include="NetSpecific\Integration\ModifiedFlags\Casee.cs" />
151151
<Compile Include="NetSpecific\Integration\ModifiedFlags\MergeColModTest.cs" />
152+
<Compile Include="NetSpecific\Integration\RevisionOnCollectionChange\Domain.cs" />
153+
<Compile Include="NetSpecific\Integration\RevisionOnCollectionChange\Fixture.cs" />
152154
<Compile Include="NetSpecific\UnitTests\CustomLists\CustomListClasses.cs" />
153155
<Compile Include="NetSpecific\UnitTests\CustomLists\CustomListsTestModel.cs" />
154156
<Compile Include="NetSpecific\UnitTests\CustomLists\CustomListTests.cs" />
@@ -802,6 +804,7 @@
802804
<Compile Include="ValidityTestBase.cs" />
803805
</ItemGroup>
804806
<ItemGroup>
807+
<EmbeddedResource Include="NetSpecific\Integration\RevisionOnCollectionChange\Mapping.hbm.xml" />
805808
<EmbeddedResource Include="NetSpecific\Integration\MultiLevelInheritance\Mapping.hbm.xml" />
806809
<EmbeddedResource Include="NetSpecific\Integration\BidirectionalSameColumn\Mapping.hbm.xml" />
807810
<EmbeddedResource Include="NetSpecific\Integration\CustomMapping\ImplicitEnversCollectionType\Mapping.hbm.xml" />
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using NHibernate.Envers.Configuration.Attributes;
4+
5+
namespace NHibernate.Envers.Tests.NetSpecific.Integration.RevisionOnCollectionChange
6+
{
7+
[Audited]
8+
public class Person
9+
{
10+
public Person()
11+
{
12+
Cars = new List<Car>();
13+
}
14+
public virtual Guid Id { get; set; }
15+
16+
public virtual IList<Car> Cars { get; protected set; }
17+
}
18+
19+
[Audited]
20+
public class Car
21+
{
22+
public virtual Guid Id { get; set; }
23+
24+
public virtual Person Owner { get; set; }
25+
}
26+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using NHibernate.Cfg;
2+
using NHibernate.Envers.Configuration;
3+
using NUnit.Framework;
4+
5+
namespace NHibernate.Envers.Tests.NetSpecific.Integration.RevisionOnCollectionChange
6+
{
7+
[TestFixture]
8+
public class Fixture : TestBase
9+
{
10+
private object _newOwnerId;
11+
private object _carId;
12+
13+
public Fixture(string strategyType) : base(strategyType)
14+
{
15+
}
16+
17+
protected override void AddToConfiguration(Cfg.Configuration configuration)
18+
{
19+
configuration.SetEnversProperty(ConfigurationKey.GlobalWithModifiedFlag, true);
20+
configuration.SetEnversProperty(ConfigurationKey.RevisionOnCollectionChange, true);
21+
base.AddToConfiguration(configuration);
22+
}
23+
24+
protected override void Initialize()
25+
{
26+
using (var tx = Session.BeginTransaction())
27+
{
28+
var oldOwner = new Person();
29+
Session.Save(oldOwner);
30+
var newOwner = new Person();
31+
_newOwnerId = Session.Save(newOwner);
32+
var car = new Car { Owner = oldOwner };
33+
_carId = Session.Save(car);
34+
tx.Commit();
35+
}
36+
}
37+
38+
[Test]
39+
public void ChangeParentReferenceShouldNotThwrowException()
40+
{
41+
using (var tx = Session.BeginTransaction())
42+
{
43+
var car = Session.Get<Car>(_carId);
44+
car.Owner = Session.Get<Person>(_newOwnerId);
45+
tx.Commit();
46+
}
47+
}
48+
}
49+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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.RevisionOnCollectionChange">
5+
<class name="Car">
6+
<id name="Id">
7+
<column name="Id" />
8+
<generator class="guid.comb"/>
9+
</id>
10+
<many-to-one class="Person" name="Owner">
11+
<column name="Owner_Id" />
12+
</many-to-one>
13+
</class>
14+
15+
<class name="Person">
16+
<id name="Id">
17+
<column name="Id" />
18+
<generator class="guid.comb"/>
19+
</id>
20+
<bag name="Cars">
21+
<key>
22+
<column name="Owner_Id" />
23+
</key>
24+
<one-to-many class="Car" />
25+
</bag>
26+
</class>
27+
</hibernate-mapping>

0 commit comments

Comments
 (0)