diff --git a/Src/NHibernate.Envers.Tests/NetSpecific/Integration/Lazy/LazyPropTest.cs b/Src/NHibernate.Envers.Tests/NetSpecific/Integration/Lazy/LazyPropTest.cs new file mode 100644 index 00000000..7a91ce6f --- /dev/null +++ b/Src/NHibernate.Envers.Tests/NetSpecific/Integration/Lazy/LazyPropTest.cs @@ -0,0 +1,217 @@ +using NHibernate.Envers.Query; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Text; + +namespace NHibernate.Envers.Tests.NetSpecific.Integration.Lazy +{ + public class LazyPropTest : TestBase + { + public LazyPropTest(AuditStrategyForTest strategyType) : base(strategyType) + { + } + + protected override void Initialize() + { + } + + [Test] + public void UpdateLazyPropInSameSession() + { + string notLazyStart = "notLazyNotUpd", + lazyStart = "lazyBefore", + notLazyEnd = "notLazyNotUpd", + lazyEnd = "lazyAfrer"; + + var factory = Cfg.BuildSessionFactory(); + + using (var s = factory.OpenSession()) + { + using (var tx = s.BeginTransaction()) + { + s.SaveOrUpdate(new EntityWithLazyProp + { + Id = 1, + NotLazyProp = notLazyStart, + LazyProp = lazyStart + }); + tx.Commit(); + } + + using (var tx = s.BeginTransaction()) + { + var ent = s.Get(1); + + ent.LazyProp = lazyEnd; + + s.SaveOrUpdate(ent); + tx.Commit(); + } + } + + var current = factory.OpenSession().Get(1); + + Assert.AreEqual(notLazyEnd, current.NotLazyProp); + Assert.AreEqual(lazyEnd, current.LazyProp); + + var history = AuditReader() + .CreateQuery() + .ForRevisionsOfEntity(typeof(EntityWithLazyProp), false, true) + .Add(AuditEntity.Id().Eq(1)) + .GetResultList(); + + Assert.AreEqual(2, history.Count); + } + + [Test] + public void UpdateNotLazyPropInSameSession() + { + string notLazyStart = "notLazyBefore", + lazyStart = "lazyNotUpd", + notLazyEnd = "notLazyAfrer", + lazyEnd = "lazyNotUpd"; + + var factory = Cfg.BuildSessionFactory(); + + using (var s = factory.OpenSession()) + { + using (var tx = s.BeginTransaction()) + { + s.SaveOrUpdate(new EntityWithLazyProp + { + Id = 1, + NotLazyProp = notLazyStart, + LazyProp = lazyStart + }); + tx.Commit(); + } + + using (var tx = s.BeginTransaction()) + { + var ent = s.Get(1); + + ent.NotLazyProp = notLazyEnd; + + s.SaveOrUpdate(ent); + tx.Commit(); + } + } + + var current = factory.OpenSession().Get(1); + + Assert.AreEqual(notLazyEnd, current.NotLazyProp); + Assert.AreEqual(lazyEnd, current.LazyProp); + + var history = AuditReader() + .CreateQuery() + .ForRevisionsOfEntity(typeof(EntityWithLazyProp), false, true) + .Add(AuditEntity.Id().Eq(1)) + .GetResultList(); + + Assert.AreEqual(2, history.Count); + } + + [Test] + public void UpdateLazyPropInOtherSession() + { + string notLazyStart = "notLazyNotUpd", + lazyStart = "lazyBefore", + notLazyEnd = "notLazyNotUpd", + lazyEnd = "lazyAfrer"; + + var factory = Cfg.BuildSessionFactory(); + + using (var s = factory.OpenSession()) + { + using (var tx = s.BeginTransaction()) + { + s.SaveOrUpdate(new EntityWithLazyProp + { + Id = 1, + NotLazyProp = notLazyStart, + LazyProp = lazyStart + }); + tx.Commit(); + } + } + + using (var s = factory.OpenSession()) + { + using (var tx = s.BeginTransaction()) + { + EntityWithLazyProp ent = s.Get(1); + + ent.LazyProp = lazyEnd; + + s.SaveOrUpdate(ent); + tx.Commit(); + } + } + + var current = Session.Get(1); + + Assert.AreEqual(notLazyEnd, current.NotLazyProp); + Assert.AreEqual(lazyEnd, current.LazyProp); + + var history = AuditReader() + .CreateQuery() + .ForRevisionsOfEntity(typeof(EntityWithLazyProp), false, true) + .Add(AuditEntity.Id().Eq(1)) + .GetResultList(); + + Assert.AreEqual(2, history.Count); + } + + [Test] + public void UpdateNotLazyPropInOtherSession() + { + string notLazyStart = "notLazyBefore", + lazyStart = "lazyNotUpd", + notLazyEnd = "notLazyAfrer", + lazyEnd = "lazyNotUpd"; + + var factory = Cfg.BuildSessionFactory(); + + using (var s = factory.OpenSession()) + { + using (var tx = s.BeginTransaction()) + { + s.SaveOrUpdate(new EntityWithLazyProp + { + Id = 1, + NotLazyProp = notLazyStart, + LazyProp = lazyStart + }); + tx.Commit(); + } + } + + using (var s = factory.OpenSession()) + { + using (var tx = s.BeginTransaction()) + { + var ent = s.Get(1); + + ent.NotLazyProp = notLazyEnd; + + s.SaveOrUpdate(ent); + tx.Commit(); + } + } + + var current = Session.Get(1); + + Assert.AreEqual(notLazyEnd, current.NotLazyProp); + Assert.AreEqual(lazyEnd, current.LazyProp); + + var history = AuditReader() + .CreateQuery() + .ForRevisionsOfEntity(typeof(EntityWithLazyProp), false, true) + .Add(AuditEntity.Id().Eq(1)) + .GetResultList(); + + Assert.AreEqual(2, history.Count); + } + } +} diff --git a/Src/NHibernate.Envers.Tests/NetSpecific/Integration/Lazy/LazyProperty.cs b/Src/NHibernate.Envers.Tests/NetSpecific/Integration/Lazy/LazyProperty.cs new file mode 100644 index 00000000..ad9e1667 --- /dev/null +++ b/Src/NHibernate.Envers.Tests/NetSpecific/Integration/Lazy/LazyProperty.cs @@ -0,0 +1,15 @@ +using NHibernate.Envers.Configuration.Attributes; +using System; +using System.Collections.Generic; +using System.Text; + +namespace NHibernate.Envers.Tests.NetSpecific.Integration.Lazy +{ + [Audited] + public class EntityWithLazyProp + { + public virtual int Id { get; set; } + public virtual string NotLazyProp { get; set; } + public virtual string LazyProp { get; set; } + } +} diff --git a/Src/NHibernate.Envers.Tests/NetSpecific/Integration/Lazy/Mapping.hbm.xml b/Src/NHibernate.Envers.Tests/NetSpecific/Integration/Lazy/Mapping.hbm.xml new file mode 100644 index 00000000..5746522d --- /dev/null +++ b/Src/NHibernate.Envers.Tests/NetSpecific/Integration/Lazy/Mapping.hbm.xml @@ -0,0 +1,13 @@ + + + + + + + + + + \ No newline at end of file