Example #1
0
        public void VerifyManyToManyCollectionSemantics()
        {
            var edVer1 = new ListOwnedEntity {
                Id = 1, Data = "data_ed_1"
            };
            var ingVer1 = new ListOwningEntity {
                Id = 2, Data = "data_ing_1"
            };
            var ingVer2 = new ListOwningEntity {
                Id = 2, Data = "modified data_ing_1"
            };

            var entity = AuditReader().Find <ListOwnedEntity>(1, 21);

            entity.Should().Be.EqualTo(edVer1);
            entity.Referencing.Should().Have.SameValuesAs(ingVer1);

            entity = AuditReader().Find <ListOwnedEntity>(1, 22);
            entity.Referencing.Should().Have.SameValuesAs(ingVer2);

            var res = AuditReader().CreateQuery().ForHistoryOf <ListOwnedEntity, DefaultRevisionEntity>(true)
                      .Add(AuditEntity.Id().Eq(1))
                      .Add(AuditEntity.RevisionType().Eq(RevisionType.Deleted))
                      .Results().First();

            res.RevisionEntity.Id.Should().Be.EqualTo(23);
            res.Entity.Data.Should().Be.EqualTo("data_ed_1");
            res.Entity.Referencing.Should().Have.SameValuesAs(ingVer2);
        }
Example #2
0
        public void VerifyTernaryMap()
        {
            var ternaryMap = new TernaryMapEntity {
                Id = ternaryMapId
            };

            ternaryMap.Map[intEntity1] = stringEntity1;
            ternaryMap.Map[new IntTestPrivSeqEntity {
                               Id = intEntity2.Id, Number = 2
                           }]          = new StrTestPrivSeqEntity
            {
                Id  = stringEntity2.Id,
                Str = "value 2"
            };

            var entity = AuditReader().Find <TernaryMapEntity>(ternaryMapId, 15);

            entity.Map.Should().Have.SameValuesAs(ternaryMap.Map);

            ternaryMap.Map.Clear();
            ternaryMap.Map.Add(intEntity1, stringEntity1);
            ternaryMap.Map.Add(intEntity2, stringEntity2);

            entity = AuditReader().Find <TernaryMapEntity>(ternaryMapId, 16);
            entity.Map.Should().Have.SameValuesAs(ternaryMap.Map);

            var res = AuditReader().CreateQuery().ForHistoryOf <TernaryMapEntity, DefaultRevisionEntity>(true)
                      .Add(AuditEntity.Id().Eq(ternaryMapId))
                      .Add(AuditEntity.RevisionType().Eq(RevisionType.Deleted))
                      .Results().First();

            res.RevisionEntity.Id.Should().Be.EqualTo(17);
            res.Entity.Map.Should().Have.SameValuesAs(ternaryMap.Map);
        }
Example #3
0
        public void VerifyReferencedOneToManyDifferentRevisions()
        {
            var res = AuditReader().CreateQuery().ForHistoryOf <SetRefIngEntity, DefaultRevisionEntity>()
                      .Add(AuditEntity.Id().Eq(4))
                      .Add(AuditEntity.RevisionType().Eq(RevisionType.Deleted))
                      .Results().First();

            res.RevisionEntity.Id.Should().Be.EqualTo(4);
            res.Entity.Data.Should().Be.EqualTo("Example Data 2");
            res.Entity.Reference.Data.Should().Be.EqualTo("Demo Data 2");
        }
Example #4
0
        public void VerifyElementCollection()
        {
            var res = AuditReader().CreateQuery().ForHistoryOf <StringSetEntity, DefaultRevisionEntity>()
                      .Add(AuditEntity.Id().Eq(stringSetId))
                      .Add(AuditEntity.RevisionType().Eq(RevisionType.Deleted))
                      .Results().First();

            res.RevisionEntity.Id.Should().Be.EqualTo(12);
            res.Entity.Strings
            .Should().Have.SameValuesAs("string 1", "string 2");
        }
Example #5
0
        public void VerifyUnversionedRelation()
        {
            var res = AuditReader().CreateQuery().ForHistoryOf <M2MIndexedListTargetNotAuditedEntity, DefaultRevisionEntity>()
                      .Add(AuditEntity.Id().Eq(1))
                      .Add(AuditEntity.RevisionType().Eq(RevisionType.Deleted))
                      .Results().First();

            res.RevisionEntity.Id.Should().Be.EqualTo(14);
            res.Entity.References
            .Should().Have.SameSequenceAs(unversionedEntity1, unversionedEntity2);
        }
        public void SelectRevisionTypeQuery()
        {
            var result = AuditReader().CreateQuery()
                .ForRevisionsOfEntity(typeof(StrIntTestEntity), false, true)
                .AddProjection(AuditEntity.RevisionType())
                .Add(AuditEntity.Id().Eq(id1))
                .GetResultList<RevisionType>();

            Assert.AreEqual(RevisionType.Added, result[0]);
            Assert.AreEqual(RevisionType.Modified, result[1]);
            Assert.AreEqual(RevisionType.Deleted, result[2]);
        }
Example #7
0
        public IList <object[]> GetRawRevisions(Type type, RevisionType revisionType, DateTime?startDate, DateTime?endDate)
        {
            IAuditQuery q = AuditReaderFactory.Get(Session).CreateQuery()
                            .ForRevisionsOfEntity(type, false, true)
                            .Add(AuditEntity.RevisionType().Eq(revisionType))
                            .AddOrder(AuditEntity.RevisionProperty("REVTSTMP").Desc());

            if (startDate.HasValue && endDate.HasValue)
            {
                q = q.Add(AuditEntity.RevisionProperty("REVTSTMP").Between(startDate, endDate));
            }
            return(q.GetResultList <object[]>());
        }
Example #8
0
        public void VerifyOwnedManyToManyDifferentRevisions()
        {
            var res = AuditReader().CreateQuery().ForHistoryOf <SetOwningEntity, DefaultRevisionEntity>()
                      .Add(AuditEntity.Id().Eq(7))
                      .Add(AuditEntity.RevisionType().Eq(RevisionType.Deleted))
                      .Results().First();

            res.RevisionEntity.Id.Should().Be.EqualTo(9);
            res.Entity.Data.Should().Be.EqualTo("Demo Data 2");
            res.Entity.References.Should().Have.SameValuesAs(new SetOwnedEntity {
                Id = 8, Data = "Example Data 2"
            });
        }
Example #9
0
        public void VerifyReferringOneToManySameRevision()
        {
            var res = AuditReader().CreateQuery().ForHistoryOf <SetRefEdEntity, DefaultRevisionEntity>()
                      .Add(AuditEntity.Id().Eq(1))
                      .Add(AuditEntity.RevisionType().Eq(RevisionType.Deleted))
                      .Results().First();

            res.RevisionEntity.Id.Should().Be.EqualTo(2);
            res.Entity.Data.Should().Be.EqualTo("Demo Data 1");
            res.Entity.Reffering.Should().Have.SameValuesAs(new SetRefIngEntity {
                Id = 2, Data = "Example Data 1"
            });
        }
        public void ShouldFindEntitiesRemovedAtRevision()
        {
            var result = AuditReader().CreateQuery()
                .ForEntitiesModifiedAtRevision(typeof(StrIntTestEntity).FullName, 4)
                .GetResultList<StrIntTestEntity>();
            var revisionType = AuditReader().CreateQuery()
                .ForEntitiesModifiedAtRevision(typeof(StrIntTestEntity), 4)
                .AddProjection(AuditEntity.RevisionType())
                .Add(AuditEntity.Id().Eq(id1))
                .GetSingleResult<RevisionType>();

            result.Should().Have.SameValuesAs(new StrIntTestEntity { Id = id1 });

            revisionType.Should().Be.EqualTo(RevisionType.Deleted);
        }
        public void ShouldFindEntitiesModifiedAtRevision()
        {
            var result = AuditReader().CreateQuery()
                .ForEntitiesModifiedAtRevision(typeof(StrIntTestEntity), 2)
                .GetResultList<StrIntTestEntity>();
            var revisionType = AuditReader().CreateQuery()
                .ForEntitiesModifiedAtRevision(typeof(StrIntTestEntity), 2)
                .AddProjection(AuditEntity.RevisionType())
                .Add(AuditEntity.Id().Eq(id1))
                .GetSingleResult<RevisionType>();

            result.Should().Have.SameValuesAs(new StrIntTestEntity { Id = id1, Str = "aBc", Number = 10 },
                                                            new StrIntTestEntity { Id = id2, Str = "a", Number = 20 });

            revisionType.Should().Be.EqualTo(RevisionType.Modified);
        }
        public void VerifyRevisionTypeNeQuery()
        {
            // The query shouldn't be ordered as always, otherwise - we get an exception.
            var result = AuditReader().CreateQuery()
                         .ForRevisionsOfEntity(typeof(StrIntTestEntity), true, true)
                         .Add(AuditEntity.Id().Eq(id1))
                         .Add(AuditEntity.RevisionType().Ne(RevisionType.Modified))
                         .GetResultList();

            CollectionAssert.AreEqual(
                new[]
            {
                new StrIntTestEntity {
                    Str = "a", Number = 10, Id = id1
                }
            }, result);
        }
Example #13
0
        public void VerifyOwningManyToManyDifferentRevisions()
        {
            var res = AuditReader().CreateQuery().ForHistoryOf <SetOwnedEntity, DefaultRevisionEntity>()
                      .Add(AuditEntity.Id().Eq(8))
                      .Add(AuditEntity.RevisionType().Eq(RevisionType.Deleted))
                      .Results().First();

            res.RevisionEntity.Id.Should().Be.EqualTo(10);
            res.Entity.Data.Should().Be.EqualTo("Example Data 2");
            res.Entity.Referencing.Should().Be.Empty();

            //after commit in revision 9, related entity has been removed
            res = AuditReader().CreateQuery().ForHistoryOf <SetOwnedEntity, DefaultRevisionEntity>()
                  .Add(AuditEntity.Id().Eq(8))
                  .Add(AuditEntity.RevisionNumber().Eq(9))
                  .Results().First();
            res.Entity.Data.Should().Be.EqualTo("Example Data 2");
            res.Entity.Referencing.Should().Be.Empty();
        }
Example #14
0
        public void VerifyReferringOneToManyDifferentRevision()
        {
            var res = AuditReader().CreateQuery().ForHistoryOf <SetRefEdEntity, DefaultRevisionEntity>()
                      .Add(AuditEntity.Id().Eq(3))
                      .Add(AuditEntity.RevisionType().Eq(RevisionType.Deleted))
                      .Results().First();

            res.RevisionEntity.Id.Should().Be.EqualTo(5);
            res.Entity.Data.Should().Be.EqualTo("Demo Data 2");
            res.Entity.Reffering.Should().Be.Empty();

            //after commit in revision 4, child entity has been removed
            res = AuditReader().CreateQuery().ForHistoryOf <SetRefEdEntity, DefaultRevisionEntity>()
                  .Add(AuditEntity.Id().Eq(3))
                  .Add(AuditEntity.RevisionNumber().Eq(4))
                  .Results().First();
            res.Entity.Data.Should().Be.EqualTo("Demo Data 2");
            res.Entity.Reffering.Should().Be.Empty();
        }