protected override void Initialize() { var ste1 = new StrTestEntity { Str = "Str1" }; var ste2 = new StrTestEntity { Str = "Str2" }; var mtocte1 = new ManyToOneComponentTestEntity { Comp1 = new ManyToOneComponent { Data = "data1", Entity = ste1 } }; using (var tx = Session.BeginTransaction()) { ste_id1 = (int)Session.Save(ste1); ste_id2 = (int)Session.Save(ste2); tx.Commit(); } using (var tx = Session.BeginTransaction()) { mtocte_id1 = (int)Session.Save(mtocte1); tx.Commit(); } using (var tx = Session.BeginTransaction()) { mtocte1.Comp1.Entity = ste2; tx.Commit(); } }
protected override void Initialize() { var rfd = new StrTestEntity { Str = "x" }; timestamp1 = DateTime.UtcNow.AddSeconds(-1); using (var tx = Session.BeginTransaction()) { Session.Save(rfd); tx.Commit(); } timestamp2 = DateTime.UtcNow; Thread.Sleep(MillisecondPrecision); using (var tx = Session.BeginTransaction()) { rfd.Str = "y"; tx.Commit(); } timestamp3 = DateTime.UtcNow; Thread.Sleep(MillisecondPrecision); using (var tx = Session.BeginTransaction()) { rfd.Str = "z"; tx.Commit(); } timestamp4 = DateTime.UtcNow; }
protected override void Initialize() { var fe = new StrTestEntity { Str = "x" }; using (var tx = Session.BeginTransaction()) { id = (int)Session.Save(fe); Session.Flush(); tx.Commit(); } using (var tx = Session.BeginTransaction()) { // No revision - we change the data, but do not flush the session fe.Str = "y"; tx.Commit(); } using (var tx = Session.BeginTransaction()) { fe.Str = "z"; Session.Flush(); fe.Str = "z2"; tx.Commit(); } }
protected override void Initialize() { var ste1 = new StrTestEntity { Str = "str1" }; var ste2 = new StrTestEntity { Str = "str2" }; var otmcte1 = new OneToManyComponentTestEntity { Comp1 = new OneToManyComponent { Data = "data1" } }; using (var tx = Session.BeginTransaction()) { ste_id1 = (int)Session.Save(ste1); ste_id2 = (int)Session.Save(ste2); tx.Commit(); } using (var tx = Session.BeginTransaction()) { otmcte1.Comp1.Entities.Add(ste1); otmcte_id1 = (int)Session.Save(otmcte1); tx.Commit(); } using (var tx = Session.BeginTransaction()) { otmcte1.Comp1.Entities.Add(ste2); tx.Commit(); } }
protected override void Initialize() { var emptyEntity = new StrTestEntity { Str = "" }; var nullEntity = new StrTestEntity { Str = null }; //revision 1 using (var tx = Session.BeginTransaction()) { emptyId = (int)Session.Save(emptyEntity); nullId = (int)Session.Save(nullEntity); tx.Commit(); } // Should not generate revision after NULL to "" modification and vice versa on Oracle. using (var tx = Session.BeginTransaction()) { emptyEntity.Str = null; nullEntity.Str = ""; tx.Commit(); } }
protected override void Initialize() { var te = new StrTestEntity { Str = "x" }; timestamp1 = DateTime.UtcNow.AddSeconds(-1); using (var tx = Session.BeginTransaction()) { TestRevisionListener.Data = "data1"; id = (int)Session.Save(te); tx.Commit(); } timestamp2 = DateTime.UtcNow; Thread.Sleep(100); using (var tx = Session.BeginTransaction()) { TestRevisionListener.Data = "data2"; te.Str = "y"; tx.Commit(); } timestamp3 = DateTime.UtcNow; }
protected override void Initialize() { var imke = new IdMapKeyEntity(); var ste1 = new StrTestEntity { Str = "x" }; var ste2 = new StrTestEntity { Str = "y" }; // Revision 1 (intialy 1 mapping) using (var tx = Session.BeginTransaction()) { Session.Save(ste1); Session.Save(ste2); imke.IdMap[ste1.Id] = ste1; id = (int)Session.Save(imke); tx.Commit(); } // Revision 2 (sse1: adding 1 mapping) using (var tx = Session.BeginTransaction()) { imke.IdMap[ste2.Id] = ste2; tx.Commit(); } }
protected override void Initialize() { var ste = new StrTestEntity { Str = "x" }; var site = new StrIntTestEntity { Str = "y", Number = 1 }; // Revision 1 - Adding two entities using (var tx = Session.BeginTransaction()) { steId = (int)Session.Save(ste); siteId = (int)Session.Save(site); tx.Commit(); } // Revision 2 - Modifying one entity using (var tx = Session.BeginTransaction()) { site.Number = 2; tx.Commit(); } // Revision 3 - Deleting both entities using (var tx = Session.BeginTransaction()) { Session.Delete(ste); Session.Delete(site); tx.Commit(); } }
protected override void Initialize() { var entity = new SortedSetEntity(); var a = new StrTestEntity { Str = "a" }; var b = new StrTestEntity { Str = "b" }; using (var tx = Session.BeginTransaction()) { id = (Guid)Session.Save(entity); tx.Commit(); } using (var tx = Session.BeginTransaction()) { entity.SortedSet.Add(a); entity.SortedSet.Add(b); tx.Commit(); } using (var tx = Session.BeginTransaction()) { entity.SortedSet.Remove(b); entity.SortedMap[a] = "a"; entity.SortedMap[b] = "b"; tx.Commit(); } }
protected override void Initialize() { var ste1 = new StrTestEntity { Str = "x" }; var ste2 = new StrTestEntity { Str = "y" }; // Revision 1 - Adding two entities using (var tx = Session.BeginTransaction()) { steId1 = (int)Session.Save(ste1); steId2 = (int)Session.Save(ste2); tx.Commit(); } // Revision 2 - Changing first and removing second entity using (var tx = Session.BeginTransaction()) { ste1.Str = "z"; Session.Delete(ste2); tx.Commit(); } // Revision 3 - Modifying and removing the same entity. using (var tx = Session.BeginTransaction()) { ste1.Str = "a"; Session.Delete(ste1); tx.Commit(); } }
public void CompareRevisionIdToAuditedRevisionWithOptionalFlush(bool flushAndClear) { int id; int revisionId; var x = new StrTestEntity { Str = "x" }; using (var tx = Session.BeginTransaction()) { id = (int)Session.Save(x); // Get current revision id (this should be equal to the revision of "x") revisionId = AuditReader().GetCurrentRevision <DefaultRevisionEntity>(true).Id; if (flushAndClear) { // Flush session Session.Flush(); // Clear cache (this seems to cause the problem) Session.Clear(); } tx.Commit(); } var revisions = AuditReader().GetRevisions(typeof(StrTestEntity), id); Assert.That(revisions.Count(), Is.EqualTo(1)); // If the following assertion fails, the "x" has a different revision Assert.That(revisions.Last(), Is.EqualTo(revisionId)); }
protected override void Initialize() { var child = new StrTestEntity { Str = "data" }; var parent = new ListRefCollEntity { Id = parentId, Data = "initial data", Collection = new List <StrTestEntity> { child } }; //Revision 1 using (var tx = Session.BeginTransaction()) { childId = (int)Session.Save(child); Session.Save(parent); tx.Commit(); } ForceNewSession(); //Revision 2 using (var tx = Session.BeginTransaction()) { parent.Data = "modified data"; Session.Update(parent); tx.Commit(); } }
public void VerifyCurrent() { var expected = new StrTestEntity { Id = id, Str = "z" }; Assert.AreEqual(expected, Session.Get <StrTestEntity>(id)); }
public void ShouldTrackUpdateAndRemoveTheSameEntity() { var ste1 = new StrTestEntity { Id = steId1 }; crossTypeRevisionChangesReader().FindEntities(3) .Should().Have.SameValuesAs(ste1); }
public void VerifyHistoryOfId() { var ver1 = new StrTestEntity { Id = id, Str = "x" }; Assert.AreEqual(ver1, AuditReader().Find <StrTestEntity>(id, 1)); Assert.IsNull(AuditReader().Find <StrTestEntity>(id, 2)); }
public void ShouldTrackAddedTwoEntities() { var ste1 = new StrTestEntity { Str = "x", Id = steId1 }; var ste2 = new StrTestEntity { Str = "y", Id = steId2 }; crossTypeRevisionChangesReader().FindEntities(1) .Should().Have.SameValuesAs(ste1, ste2); }
public void ShouldTrackUpdateAndRemoveDifferentEntities() { var ste1 = new StrTestEntity { Str = "z", Id = steId1 }; var ste2 = new StrTestEntity { Id = steId2 }; crossTypeRevisionChangesReader().FindEntities(2) .Should().Have.SameValuesAs(ste1, ste2); }
protected override void Initialize() { var entity = new StrTestEntity { Str = "data" }; using (var tx = Session.BeginTransaction()) { Session.Save(entity); tx.Commit(); } }
public void ShouldTrackAddedEntities() { var ste = new StrTestEntity { Str = "x", Id = steId }; var site = new StrIntTestEntity { Str = "y", Number = 1, Id = siteId }; crossTypeRevisionChangesReader().FindEntities(1) .Should().Have.SameValuesAs(ste, site); }
public void ShouldFindChangedEntitiesByRevisionTypeDeleted() { var ste = new StrTestEntity { Id = steId }; var site = new StrIntTestEntity { Id = siteId }; crossTypeRevisionChangesReader().FindEntities(3, RevisionType.Deleted) .Should().Have.SameValuesAs(site, ste); }
public void VerifyHistoryOfId1() { var ver1 = new StrTestEntity { Id = id, Str = "y" }; var ver2 = new StrTestEntity { Id = id, Str = "z" }; Assert.AreEqual(ver1, AuditReader().Find <StrTestEntity>(id, 1)); Assert.AreEqual(ver2, AuditReader().Find <StrTestEntity>(id, 2)); }
protected override void Initialize() { var te = new StrTestEntity { Str = "x" }; // Revision 1 using (var tx = Session.BeginTransaction()) { id = (int)Session.Save(te); // Setting the data on the revision entity var custom = AuditReader().GetCurrentRevision <CustomDataRevEntity>(false); custom.Data = "data1"; tx.Commit(); } // Revision 2 using (var tx = Session.BeginTransaction()) { te.Str = "y"; // Setting the data on the revision entity var custom = (CustomDataRevEntity)AuditReader().GetCurrentRevision(false); custom.Data = "data2"; tx.Commit(); } // Revision 3 - no changes, but rev entity should be persisted using (var tx = Session.BeginTransaction()) { // Setting the data on the revision entity var custom = AuditReader().GetCurrentRevision <CustomDataRevEntity>(true); custom.Data = "data3"; tx.Commit(); } // No changes, rev entity won't be persisted using (var tx = Session.BeginTransaction()) { // Setting the data on the revision entity var custom = AuditReader().GetCurrentRevision <CustomDataRevEntity>(false); custom.Data = "data4"; tx.Commit(); } // Revision 4 using (var tx = Session.BeginTransaction()) { te.Str = "z"; var custom = AuditReader().GetCurrentRevision <CustomDataRevEntity>(false); custom.Data = "data5"; custom = AuditReader().GetCurrentRevision <CustomDataRevEntity>(false); custom.Data = "data5bis"; tx.Commit(); } }
protected override void Initialize() { ing1_id = 1233; ing2_id = 929; var ed1 = new StrTestEntity { Str = "data_ed_1" }; var ed2 = new StrTestEntity { Str = "data_ed_1" }; var ing1 = new SetUniEntity { Id = ing1_id, Data = "data_ing_1" }; var ing2 = new SetUniEntity { Id = ing2_id, Data = "data_ing_2" }; using (var tx = Session.BeginTransaction()) { ed1_id = (int)Session.Save(ed1); ed2_id = (int)Session.Save(ed2); Session.Save(ing1); Session.Save(ing2); tx.Commit(); } using (var tx = Session.BeginTransaction()) { ing1.References = new HashSet <StrTestEntity> { ed1 }; ing2.References = new HashSet <StrTestEntity> { ed1, ed2 }; tx.Commit(); } using (var tx = Session.BeginTransaction()) { ing1.References.Add(ed2); tx.Commit(); } using (var tx = Session.BeginTransaction()) { ing1.References.Remove(ed1); tx.Commit(); } using (var tx = Session.BeginTransaction()) { ing1.References = null; tx.Commit(); } }
public void ShouldThrowIfInsertOutsideActiveTransaction() { // Illegal insertion of entity outside of active transaction. var entity = new StrTestEntity { Str = "data" }; Assert.Throws <AuditException>(() => { Session.Save(entity); Session.Flush(); }); }
protected override void Initialize() { var te = new StrTestEntity { Str = "x" }; using (var tx = Session.BeginTransaction()) { Session.Save(te); listener.Called.Should().Be.False(); tx.Commit(); listener.Called.Should().Be.True(); } }
protected override void Initialize() { using (var tx = Session.BeginTransaction()) { var fe = new StrTestEntity { Str = "x" }; id1 = (int)Session.Save(fe); Session.Flush(); Session.Delete(fe); Session.Flush(); tx.Commit(); } }
public void SortedSetShouldStillHaveCorrectComparer() { var newObj = new StrTestEntity { Str = "c" }; var rev = AuditReader().Find <SortedSetEntity>(id, 3); rev.SortedSet.Count .Should().Be.GreaterThan(0); rev.SortedSet.Add(newObj); rev.SortedSet.First() .Should().Be.SameInstanceAs(newObj); }
public void ShouldTrackDeletedEntitiesGroupByRevisionType() { var ste = new StrTestEntity { Id = steId }; var site = new StrIntTestEntity { Id = siteId }; var result = crossTypeRevisionChangesReader().FindEntitiesGroupByRevisionType(3); result[RevisionType.Added].Should().Be.Empty(); result[RevisionType.Modified].Should().Be.Empty(); result[RevisionType.Deleted].Should().Have.SameValuesAs(ste, site); }
protected override void Initialize() { entity = new StrTestEntity { Str = "data" }; using (var distrTx = new TransactionScope()) { using (var newSession = Session.SessionFactory.OpenSession()) { newSession.FlushMode = FlushMode.Manual; newSession.Save(entity); newSession.Flush(); } distrTx.Complete(); } }
public void ShouldThrowIfDeleteOutsideActiveTransaction() { var entity = new StrTestEntity { Str = "data" }; using (var tx = Session.BeginTransaction()) { Session.Save(entity); tx.Commit(); } // Illegal modification of entity state outside of active transaction. Assert.Throws <AuditException>(() => { Session.Delete(entity); Session.Flush(); }); }