diff --git a/Src/NHibernate.Envers.Tests/NetSpecific/Integration/Tree/Mapping.hbm.xml b/Src/NHibernate.Envers.Tests/NetSpecific/Integration/Tree/Mapping.hbm.xml new file mode 100644 index 00000000..14972753 --- /dev/null +++ b/Src/NHibernate.Envers.Tests/NetSpecific/Integration/Tree/Mapping.hbm.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Src/NHibernate.Envers.Tests/NetSpecific/Integration/Tree/TreeEntity.cs b/Src/NHibernate.Envers.Tests/NetSpecific/Integration/Tree/TreeEntity.cs new file mode 100644 index 00000000..2c475fda --- /dev/null +++ b/Src/NHibernate.Envers.Tests/NetSpecific/Integration/Tree/TreeEntity.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using NHibernate.Envers.Configuration.Attributes; + +namespace NHibernate.Envers.Tests.NetSpecific.Integration.Tree +{ + [Audited] + public class TreeEntity + { + public virtual long Id { get; set; } + public virtual string Name { get; set; } + public virtual TreeEntity Parent { get; set; } + public virtual IList Children { get; protected set; } = new List(); + + public override bool Equals(object obj) + { + if (!(obj is TreeEntity other)) + return false; + return Id == other.Id; + } + + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} \ No newline at end of file diff --git a/Src/NHibernate.Envers.Tests/NetSpecific/Integration/Tree/TreeTest.cs b/Src/NHibernate.Envers.Tests/NetSpecific/Integration/Tree/TreeTest.cs new file mode 100644 index 00000000..a94bd07e --- /dev/null +++ b/Src/NHibernate.Envers.Tests/NetSpecific/Integration/Tree/TreeTest.cs @@ -0,0 +1,57 @@ +using System.Collections.Generic; +using NUnit.Framework; + +namespace NHibernate.Envers.Tests.NetSpecific.Integration.Tree +{ + public class TreeTest : TestBase + { + private long parentId; + private long childId; + + public TreeTest(AuditStrategyForTest strategyType) : base(strategyType) + { + } + + protected override IEnumerable Mappings => new[] {"NetSpecific.Integration.Tree.Mapping.hbm.xml"}; + + protected override void Initialize() + { + var parent = new TreeEntity {Name = "Parent"}; + + using (var tx = Session.BeginTransaction()) + { + parentId = (long) Session.Save(parent); + tx.Commit(); + } + + var child = new TreeEntity + { + Name = "Child", + Parent = new TreeEntity {Id = parentId} + }; + + using (var tx = Session.BeginTransaction()) + { + childId = (long) Session.Save(child); + tx.Commit(); + } + } + + [Test] + public void VerifyRevisionCount() + { + CollectionAssert.AreEquivalent(new[] {1}, AuditReader().GetRevisions(typeof(TreeEntity), parentId)); + CollectionAssert.AreEquivalent(new[] {2}, AuditReader().GetRevisions(typeof(TreeEntity), childId)); + } + + [Test] + public void VerifyHistory() + { + var rev1 = AuditReader().Find(parentId, 1); + var rev2 = AuditReader().Find(parentId, 2); + + Assert.IsNotNull(rev1.Name); + Assert.IsNotNull(rev2.Name); + } + } +} \ No newline at end of file