コード例 #1
0
        protected override void Initialize()
        {
            var refEntity = new SetRefEdEntity {
                Id = 1, Data = "str1"
            };
            var refingEntity = new SetRefIngEntity {
                Id = 1, Data = "refing1", Reference = refEntity
            };
            var refingEntity2 = new SetRefIngEntity {
                Id = 2, Data = "refing2", Reference = refEntity
            };

            //rev 1
            using (var tx = Session.BeginTransaction())
            {
                Session.Save(refEntity);
                Session.Save(refingEntity);
                tx.Commit();
            }
            //rev 2
            using (var tx = Session.BeginTransaction())
            {
                Session.Save(refingEntity2);
                tx.Commit();
            }
        }
コード例 #2
0
        protected override void Initialize()
        {
            var ed1 = new SetRefEdEntity {
                Id = 1, Data = "data_ed_1"
            };
            var ed2 = new SetRefEdEntity {
                Id = 2, Data = "data_ed_2"
            };

            var ing1 = new SetRefIngEntity {
                Id = 1, Data = "data_ing_1"
            };
            var ing2 = new SetRefIngEntity {
                Id = 2, Data = "data_ing_2"
            };

            using (var tx = Session.BeginTransaction())             //rev1
            {
                ed1_id = (int)Session.Save(ed1);
                Session.Save(ed2);
                ing1.Reference = ed1;
                ing2.Reference = ed1;
                ing1_id        = (int)Session.Save(ing1);
                ing2_id        = (int)Session.Save(ing2);
                tx.Commit();
            }
            using (var tx = Session.BeginTransaction())             //rev2
            {
                ing1.Reference = ed2;
                ing2.Reference = ed2;
                tx.Commit();
            }
        }
コード例 #3
0
        protected override void Initialize()
        {
            var ed1 = new SetRefEdEntity {
                Id = ed1_id, Data = "data_ed_1"
            };
            var ed2 = new SetRefEdEntity {
                Id = ed2_id, Data = "data_ed_2"
            };
            var ing1 = new SetRefIngEntity {
                Id = ing1_id, Data = "data_ing_1", Reference = ed1
            };
            var ing2 = new SetRefIngEntity {
                Id = ing2_id, Data = "data_ing_2", Reference = ed1
            };
            var ing3 = new SetRefIngEntity {
                Id = ing3_id, Data = "data_ing_3", Reference = ed1
            };
            var ing4 = new SetRefIngEntity {
                Id = ing4_id, Data = "data_ing_4", Reference = ed1
            };

            using (var tx = Session.BeginTransaction())
            {
                Session.Save(ed1);
                Session.Save(ed2);
                Session.Save(ing1);
                Session.Save(ing2);
                Session.Save(ing3);
                Session.Save(ing4);
                tx.Commit();
            }
            using (var tx = Session.BeginTransaction())
            {
                ing1.Reference = null;
                tx.Commit();
            }
            using (var tx = Session.BeginTransaction())
            {
                Session.Delete(ing2);
                tx.Commit();
            }
            using (var tx = Session.BeginTransaction())
            {
                ing3.Reference = ed2;
                tx.Commit();
            }
            using (var tx = Session.BeginTransaction())
            {
                Session.Delete(ed1);
                ing4.Reference = null;
                tx.Commit();
            }
        }
コード例 #4
0
        public void VerifyProxyIdentifier()
        {
            var refEntity = Session.Load <SetRefEdEntity>(1);

            refEntity.Should().Be.InstanceOf <INHibernateProxy>();

            var refingEntity3 = new SetRefIngEntity {
                Id = 3, Data = "refing2", Reference = refEntity
            };

            //rev 3
            using (var tx = Session.BeginTransaction())
            {
                Session.Save(refingEntity3);
                tx.Commit();
            }
        }
コード例 #5
0
        protected override void Initialize()
        {
            ed1_id  = 45;
            ed2_id  = 123;
            ing1_id = 1000;
            ing2_id = 2000;
            var ed1 = new SetRefEdEntity {
                Id = ed1_id, Data = "data_ed_1"
            };
            var ed2 = new SetRefEdEntity {
                Id = ed2_id, Data = "data_ed_2"
            };
            var ing1 = new SetRefIngEntity {
                Id = ing1_id, Data = "data_ing_1"
            };
            var ing2 = new SetRefIngEntity {
                Id = ing2_id, Data = "data_ing_2"
            };

            using (var tx = Session.BeginTransaction())
            {
                Session.Save(ed1);
                Session.Save(ed2);
                tx.Commit();
            }
            using (var tx = Session.BeginTransaction())
            {
                ing1.Reference = ed1;
                ing2.Reference = ed1;
                Session.Save(ing1);
                Session.Save(ing2);
                tx.Commit();
            }
            using (var tx = Session.BeginTransaction())
            {
                ing1.Reference = ed2;
                tx.Commit();
            }
            using (var tx = Session.BeginTransaction())
            {
                ing2.Reference = ed2;
                tx.Commit();
            }
        }
コード例 #6
0
 protected override void Initialize()
 {
     ed = new SetRefEdEntity {
         Data = "foo", Id = 17
     };
     ing = new SetRefIngEntity {
         Data = "bar", Reference = ed, Id = 34
     };
     edNotReferenced = new SetRefEdEntity {
         Data = "baz", Id = 4
     };
     using (var tx = Session.BeginTransaction())
     {
         Session.Save(ed);
         Session.Save(ing);
         Session.Save(edNotReferenced);
         tx.Commit();
     }
 }
コード例 #7
0
        public void VerifyHistoryOfEd1()
        {
            var ing1 = Session.Get <SetRefIngEntity>(ing1_id);
            var ing2 = new SetRefIngEntity {
                Id = ing2_id, Data = "data_ing_2"
            };
            var ing3 = Session.Get <SetRefIngEntity>(ing3_id);
            var ing4 = Session.Get <SetRefIngEntity>(ing4_id);

            var rev1 = AuditReader().Find <SetRefEdEntity>(ed1_id, 1);
            var rev2 = AuditReader().Find <SetRefEdEntity>(ed1_id, 2);
            var rev3 = AuditReader().Find <SetRefEdEntity>(ed1_id, 3);
            var rev4 = AuditReader().Find <SetRefEdEntity>(ed1_id, 4);
            var rev5 = AuditReader().Find <SetRefEdEntity>(ed1_id, 5);

            CollectionAssert.AreEquivalent(new[] { ing1, ing2, ing3, ing4 }, rev1.Reffering);
            CollectionAssert.AreEquivalent(new[] { ing2, ing3, ing4 }, rev2.Reffering);
            CollectionAssert.AreEquivalent(new[] { ing3, ing4 }, rev3.Reffering);
            CollectionAssert.AreEquivalent(new[] { ing4 }, rev4.Reffering);
            Assert.IsNull(rev5);
        }
コード例 #8
0
        protected override void Initialize()
        {
            var ed1 = new SetRefEdEntity {
                Id = ed1_id, Data = "data_ed_1"
            };
            var ing1 = new SetRefIngEntity {
                Id = ing1_id, Data = "data_ing_1"
            };

            using (var tx = Session.BeginTransaction())
            {
                Session.Save(ed1);
                tx.Commit();
            }
            using (var tx = Session.BeginTransaction())
            {
                Session.Save(ing1);
                ed1.Reffering = new HashSet <SetRefIngEntity> {
                    ing1
                };
                tx.Commit();
            }
        }
コード例 #9
0
        protected override void Initialize()
        {
            var entity = new SetRefEdEntity {
                Id = entityId, Data = "data"
            };
            var child = new SetRefIngEntity {
                Id = childId, Data = "data", Reference = entity
            };

            //revision 1
            using (var tx = Session.BeginTransaction())
            {
                Session.Save(entity);
                tx.Commit();
            }

            //revision 2
            using (var tx = Session.BeginTransaction())
            {
                Session.Save(child);
                child.Data = "changed data";
                tx.Commit();
            }
        }
        public void VerifySessionCacheCollectionClear()
        {
            var auditEntityNames = new[] { "NHibernate.Envers.Tests.Entities.OneToMany.SetRefEdEntity_AUD",
                                           "NHibernate.Envers.Tests.Entities.OneToMany.SetRefIngEntity_AUD" };

            var ed1 = new SetRefEdEntity {
                Id = 1, Data = "data_ed_1"
            };
            var ed2 = new SetRefEdEntity {
                Id = 2, Data = "data_ed_2"
            };
            var ing1 = new SetRefIngEntity {
                Id = 3, Data = "data_ing_1"
            };
            var ing2 = new SetRefIngEntity {
                Id = 4, Data = "data_ing_2"
            };

            using (var tx = Session.BeginTransaction())
            {
                Session.Save(ed1);
                Session.Save(ed2);
                Session.Save(ing1);
                Session.Save(ing2);
                tx.Commit();
            }

            checkEmptyAuditSessionCache(auditEntityNames);

            using (var tx = Session.BeginTransaction())
            {
                ing1.Reference = ed1;
                ing2.Reference = ed1;
                tx.Commit();
            }

            checkEmptyAuditSessionCache(auditEntityNames);

            using (var tx = Session.BeginTransaction())
            {
                var reffering = new HashSet <SetRefIngEntity> {
                    ing1, ing2
                };
                ed2.Reffering = reffering;
                tx.Commit();
            }
            checkEmptyAuditSessionCache(auditEntityNames);

            using (var tx = Session.BeginTransaction())
            {
                ed2.Reffering.Remove(ing1);
                tx.Commit();
            }
            checkEmptyAuditSessionCache(auditEntityNames);

            using (var tx = Session.BeginTransaction())
            {
                ed2.Reffering.First().Data = "mod_data_ing_2";
                tx.Commit();
            }
            checkEmptyAuditSessionCache(auditEntityNames);
        }
コード例 #11
0
        protected override void Initialize()
        {
            var refEdEntity1 = new SetRefEdEntity {
                Id = 1, Data = "Demo Data 1"
            };
            var refIngEntity1 = new SetRefIngEntity {
                Id = 2, Data = "Example Data 1", Reference = refEdEntity1
            };

            //Revision 1
            using (var tx = Session.BeginTransaction())
            {
                Session.Save(refEdEntity1);
                Session.Save(refIngEntity1);
                tx.Commit();
            }

            //Revision 2 - removing both object in the same revision
            using (var tx = Session.BeginTransaction())
            {
                Session.Delete(refIngEntity1);
                Session.Delete(refEdEntity1);
                tx.Commit();
            }

            var refEdEntity2 = new SetRefEdEntity {
                Id = 3, Data = "Demo Data 2"
            };
            var refIngEntity2 = new SetRefIngEntity {
                Id = 4, Data = "Example Data 2", Reference = refEdEntity2
            };

            //Revision 3
            using (var tx = Session.BeginTransaction())
            {
                Session.Save(refEdEntity2);
                Session.Save(refIngEntity2);
                tx.Commit();
            }

            //Revision 4 - removing child object
            using (var tx = Session.BeginTransaction())
            {
                Session.Delete(refIngEntity2);
                tx.Commit();
            }

            //Revision 5 - removing parent object
            using (var tx = Session.BeginTransaction())
            {
                Session.Delete(refEdEntity2);
                tx.Commit();
            }

            var setOwningEntity1 = new SetOwningEntity {
                Id = 5, Data = "Demo Data 1"
            };
            var setOwnedEntity1 = new SetOwnedEntity {
                Id = 6, Data = "Example Data 1"
            };
            var owning = new HashSet <SetOwningEntity>();
            var owned  = new HashSet <SetOwnedEntity>();

            owning.Add(setOwningEntity1);
            owned.Add(setOwnedEntity1);
            setOwningEntity1.References = owned;
            setOwnedEntity1.Referencing = owning;

            //Revision 6
            using (var tx = Session.BeginTransaction())
            {
                Session.Save(setOwnedEntity1);
                Session.Save(setOwningEntity1);
                tx.Commit();
            }

            //Revision 7 - removing both object in the same revision
            using (var tx = Session.BeginTransaction())
            {
                Session.Delete(setOwningEntity1);
                Session.Delete(setOwnedEntity1);
                tx.Commit();
            }

            var setOwningEntity2 = new SetOwningEntity {
                Id = 7, Data = "Demo Data 2"
            };
            var setOwnedEntity2 = new SetOwnedEntity {
                Id = 8, Data = "Example Data 2"
            };

            owning = new HashSet <SetOwningEntity>();
            owned  = new HashSet <SetOwnedEntity>();
            owning.Add(setOwningEntity2);
            owned.Add(setOwnedEntity2);
            setOwningEntity2.References = owned;
            setOwnedEntity2.Referencing = owning;

            //Revision 8
            using (var tx = Session.BeginTransaction())
            {
                Session.Save(setOwnedEntity2);
                Session.Save(setOwningEntity2);
                tx.Commit();
            }

            //Revision 9 - removing first object
            using (var tx = Session.BeginTransaction())
            {
                Session.Delete(setOwningEntity2);
                tx.Commit();
            }

            //Revision 10 - removing second object
            using (var tx = Session.BeginTransaction())
            {
                Session.Delete(setOwnedEntity2);
                tx.Commit();
            }

            var stringSetEntity = new StringSetEntity();

            stringSetEntity.Strings.Add("string 1");
            stringSetEntity.Strings.Add("string 2");

            //Revision 11
            using (var tx = Session.BeginTransaction())
            {
                stringSetId = (int)Session.Save(stringSetEntity);
                tx.Commit();
            }

            //Revision 12 - removing element collection
            using (var tx = Session.BeginTransaction())
            {
                Session.Delete(stringSetEntity);
                tx.Commit();
            }

            unversionedEntity1 = new UnversionedStrTestEntity {
                Str = "string 1"
            };
            unversionedEntity2 = new UnversionedStrTestEntity {
                Str = "string 2"
            };
            var relationNotAuditedEntity = new M2MIndexedListTargetNotAuditedEntity {
                Id = 1, Data = "Parent"
            };

            relationNotAuditedEntity.References.Add(unversionedEntity1);
            relationNotAuditedEntity.References.Add(unversionedEntity2);
            //Revision 13
            using (var tx = Session.BeginTransaction())
            {
                Session.Save(unversionedEntity1);
                Session.Save(unversionedEntity2);
                Session.Save(relationNotAuditedEntity);
                tx.Commit();
            }

            //Revision 14 - removing entity with unversioned relation
            using (var tx = Session.BeginTransaction())
            {
                Session.Delete(relationNotAuditedEntity);
                tx.Commit();
            }

            stringEntity1 = new StrTestPrivSeqEntity {
                Str = "value 1"
            };
            stringEntity2 = new StrTestPrivSeqEntity {
                Str = "value 2"
            };
            intEntity1 = new IntTestPrivSeqEntity {
                Number = 1
            };
            intEntity2 = new IntTestPrivSeqEntity {
                Number = 2
            };
            var mapEntity = new TernaryMapEntity();

            mapEntity.Map[intEntity1] = stringEntity1;
            mapEntity.Map[intEntity2] = stringEntity2;
            //Revision 15
            using (var tx = Session.BeginTransaction())
            {
                Session.Save(stringEntity1);
                Session.Save(stringEntity2);
                Session.Save(intEntity1);
                Session.Save(intEntity2);
                ternaryMapId = (int)Session.Save(mapEntity);
                tx.Commit();
            }

            //Revision 16 - updating ternary map
            using (var tx = Session.BeginTransaction())
            {
                intEntity2.Number = 3;
                stringEntity2.Str = "Value 3";
                tx.Commit();
            }

            // Revision 17 - removing ternary map
            using (var tx = Session.BeginTransaction())
            {
                Session.Delete(mapEntity);
                tx.Commit();
            }

            var collEd1 = new CollectionRefEdEntity {
                Id = 1, Data = "data_ed_1"
            };
            var collIng1 = new CollectionRefIngEntity {
                Id = 2, Data = "data_ing_1", Reference = collEd1
            };

            collEd1.Reffering = new List <CollectionRefIngEntity> {
                collIng1
            };

            //Revision 18 - testing one-to-many collection
            using (var tx = Session.BeginTransaction())
            {
                Session.Save(collEd1);
                Session.Save(collIng1);
                tx.Commit();
            }

            //Revision 19
            using (var tx = Session.BeginTransaction())
            {
                collIng1.Data = "modified data_ing_1";
                tx.Commit();
            }

            //Revision 20
            using (var tx = Session.BeginTransaction())
            {
                Session.Delete(collIng1);
                Session.Delete(collEd1);
                tx.Commit();
            }

            var listEd1 = new ListOwnedEntity {
                Id = 1, Data = "data_ed_1"
            };
            var listIng1 = new ListOwningEntity {
                Id = 2, Data = "data_ing_1"
            };

            listEd1.Referencing = new List <ListOwningEntity> {
                listIng1
            };
            listIng1.References = new List <ListOwnedEntity> {
                listEd1
            };

            //Revision 21
            using (var tx = Session.BeginTransaction())
            {
                Session.Save(listEd1);
                Session.Save(listIng1);
                tx.Commit();
            }

            //Revision 22
            using (var tx = Session.BeginTransaction())
            {
                listIng1.Data = "modified data_ing_1";
                tx.Commit();
            }

            //Revision 23
            using (var tx = Session.BeginTransaction())
            {
                Session.Delete(listIng1);
                Session.Delete(listEd1);
                tx.Commit();
            }
        }