public void RevisionsPropertyEqQuery()
        {
            var revs_id1 = AuditReader().CreateQuery()
                           .ForRevisionsOfEntity(typeof(StrIntTestEntity), false, true)
                           .AddProjection(AuditEntity.RevisionNumber())
                           .Add(AuditEntity.Property("Str").Le("a"))
                           .Add(AuditEntity.Id().Eq(id1))
                           .GetResultList();
            var revs_id2 = AuditReader().CreateQuery()
                           .ForRevisionsOfEntity(typeof(StrIntTestEntity), false, true)
                           .AddProjection(AuditEntity.RevisionNumber())
                           .Add(AuditEntity.Property("Str").Le("a"))
                           .Add(AuditEntity.Id().Eq(id2))
                           .GetResultList();
            var revs_id3 = AuditReader().CreateQuery()
                           .ForRevisionsOfEntity(typeof(StrIntTestEntity), false, true)
                           .AddProjection(AuditEntity.RevisionNumber())
                           .Add(AuditEntity.Property("Str").Le("a"))
                           .Add(AuditEntity.Id().Eq(id3))
                           .GetResultList();

            CollectionAssert.AreEquivalent(new[] { 1 }, revs_id1);
            CollectionAssert.AreEquivalent(new[] { 1, 2 }, revs_id2);
            CollectionAssert.AreEquivalent(new[] { 3 }, revs_id3);
        }
        public void VerifyAllLatestRevisionOfEntityType()
        {
            var result = AuditReader().CreateQuery()
                         .ForRevisionsOfEntity(typeof(StrIntTestEntity), false, true)
                         .Add(AuditEntity.RevisionNumber().Maximize().ComputeAggregationInInstanceContext())
                         .AddOrder(AuditEntity.Property("id").Asc())
                         .GetResultList();

            result.Count.Should().Be.EqualTo(4);

            var result1 = (object[])result[0];
            var result2 = (object[])result[1];
            var result3 = (object[])result[2];
            var result4 = (object[])result[3];

            checkRevisionData(result1, 4, RevisionType.Modified, new StrIntTestEntity {
                Id = id1, Number = 5, Str = "d"
            });
            checkRevisionData(result2, 4, RevisionType.Modified, new StrIntTestEntity {
                Id = id2, Number = 20, Str = "a"
            });
            checkRevisionData(result3, 1, RevisionType.Added, new StrIntTestEntity {
                Id = id3, Number = 42, Str = "c"
            });
            checkRevisionData(result4, 5, RevisionType.Deleted, new StrIntTestEntity {
                Id = id4, Number = 0, Str = null
            });
        }
 public void VerifyHistoryOfParent()
 {
     AuditReader().Find <Car>(parentId, 1).Owners.Should().Be.Empty();
     AuditReader().CreateQuery().ForRevisionsOfEntity(typeof(Car), true, true)
     .Add(AuditEntity.Id().Eq(parentId))
     .Add(AuditEntity.RevisionNumber().Eq(2))
     .GetSingleResult <Car>()
     .Owners.Should().Be.Empty();
 }
        public void VerifyEntityIdProjection()
        {
            var maxId = AuditReader().CreateQuery().ForRevisionsOfEntity(typeof(IntTestEntity), true, true)
                        .AddProjection(AuditEntity.Id().Max())
                        .Add(AuditEntity.RevisionNumber().Gt(2))
                        .GetSingleResult();

            maxId.Should().Be.EqualTo(2);
        }
Beispiel #5
0
        public void VerifyHistoryOfParent()
        {
            var rev3 = AuditReader().CreateQuery().ForRevisionsOfEntity(typeof(TernaryMapEntity), true, true)
                       .Add(AuditEntity.Id().Eq(id))
                       .Add(AuditEntity.RevisionNumber().Eq(3))
                       .GetSingleResult <TernaryMapEntity>();

            rev3.Map.Keys.Single().Number.Should().Be.EqualTo(2);
            rev3.Map.Values.Single().Str.Should().Be.EqualTo("2");
        }
        public void VerifyRevisionGeQuery()
        {
            var result = AuditReader().CreateQuery()
                         .ForRevisionsOfEntity(typeof(StrIntTestEntity), false, true)
                         .AddProjection(AuditEntity.RevisionNumber().Distinct())
                         .Add(AuditEntity.RevisionNumber().Ge(2))
                         .GetResultList();

            CollectionAssert.AreEquivalent(new[] { 2, 3, 4 }, result);
        }
 public IList <object[]> GetRawRevisions(Person person)
 {
     return(AuditReaderFactory.Get(Session).CreateQuery()
            .ForRevisionsOfEntity(typeof(Career), false, true)
            .Add(AuditEntity.Property("Person").Eq(person))
            // don't process audit changes before baseline entities were initialised; some career.organization and career.unit
            // fields return as proxies and throw 'object not found' exceptions.
            .Add(AuditEntity.RevisionNumber().Ge(100))
            .GetResultList <object[]>());
 }
        public void VerifyMaximzeWithIdEq()
        {
            var revsId1 = AuditReader().CreateQuery()
                          .ForRevisionsOfEntity(typeof(StrIntTestEntity), false, true)
                          .AddProjection(AuditEntity.RevisionNumber())
                          .Add(AuditEntity.Property("Number").Maximize()
                               .Add(AuditEntity.Id().Eq(id2)))
                          .GetResultList();

            CollectionAssert.AreEqual(new[] { 2, 3, 4 }, revsId1);
        }
        public void VerifyMaximizeRevision()
        {
            var result = AuditReader().CreateQuery()
                         .ForRevisionsOfEntity(typeof(StrIntTestEntity), false, true)
                         .AddProjection(AuditEntity.RevisionNumber())
                         .Add(AuditEntity.RevisionNumber().Maximize()
                              .Add(AuditEntity.Property("Number").Eq(10)))
                         .GetResultList();

            CollectionAssert.AreEquivalent(new[] { 2 }, result);
        }
        public void VerifyMinimizeWithPropertyEq()
        {
            var result = AuditReader().CreateQuery()
                         .ForRevisionsOfEntity(typeof(StrIntTestEntity), false, true)
                         .AddProjection(AuditEntity.RevisionNumber())
                         .Add(AuditEntity.Property("Number").Minimize()
                              .Add(AuditEntity.Property("Str").Eq("a")))
                         .GetResultList();

            CollectionAssert.AreEqual(new[] { 1 }, result);
        }
        public void VerifyRevisionCountQuery()
        {
            // The query shouldn't be ordered as always, otherwise - we get an exception.
            var result = AuditReader().CreateQuery()
                         .ForRevisionsOfEntity(typeof(StrIntTestEntity), false, true)
                         .AddProjection(AuditEntity.RevisionNumber().Count())
                         .Add(AuditEntity.Id().Eq(id1))
                         .GetSingleResult <long>();

            Assert.AreEqual(4, result);
        }
        public void VerifyRevisionOrderQuery()
        {
            var result = AuditReader().CreateQuery()
                         .ForRevisionsOfEntity(typeof(StrIntTestEntity), false, true)
                         .AddProjection(AuditEntity.RevisionNumber())
                         .Add(AuditEntity.Id().Eq(id1))
                         .AddOrder(AuditEntity.RevisionNumber().Desc())
                         .GetResultList();

            CollectionAssert.AreEqual(new[] { 4, 3, 2, 1 }, result);
        }
 public void VerifyEntityIdOrdering()
 {
     AuditReader().CreateQuery().ForRevisionsOf <IntTestEntity>(true)
     .Add(AuditEntity.RevisionNumber().Lt(2))
     .AddOrder(AuditEntity.Id().Desc())
     .Results()
     .Should().Have.SameSequenceAs(new IntTestEntity {
         Id = 2, Number = 10
     }, new IntTestEntity {
         Id = 1, Number = 2
     });
 }
 public void VerifyHistoryOfOwning()
 {
     AuditReader().Find <OneToOneOwningEntity>(id, 1)
     .Owned.Should().Not.Be.Null();
     AuditReader().Find <OneToOneOwningEntity>(id, 2)
     .Owned.Should().Be.Null();
     AuditReader().CreateQuery().ForRevisionsOf <OneToOneOwningEntity>(true)
     .Add(AuditEntity.Id().Eq(id))
     .Add(AuditEntity.RevisionNumber().Eq(3))
     .Results().First()
     .Owned.Should().Be.Null();
 }
        public void VerifyHistoryOfParent()
        {
            AuditReader().Find <StringSetEntity>(parentId, 1)
            .Strings.Should().Be.Empty();
            AuditReader().Find <StringSetEntity>(parentId, 2)
            .Strings.Single().Should().Be.EqualTo("2");
            var rev3 = AuditReader().CreateQuery().ForRevisionsOfEntity(typeof(StringSetEntity), true, true)
                       .Add(AuditEntity.Id().Eq(parentId))
                       .Add(AuditEntity.RevisionNumber().Eq(3))
                       .GetSingleResult <StringSetEntity>();

            rev3.Strings.Single().Should().Be.EqualTo("2");
        }
Beispiel #16
0
        public void VerifyHistoryOfParent()
        {
            AuditReader().Find <BagParent>(parentId, 1)
            .Children.Single().Name.Should().Be.EqualTo("child1");
            AuditReader().Find <BagParent>(parentId, 2)
            .Children.Single().Name.Should().Be.EqualTo("child12");
            var rev3 = AuditReader().CreateQuery().ForRevisionsOfEntity(typeof(BagParent), true, true)
                       .Add(AuditEntity.Id().Eq(parentId))
                       .Add(AuditEntity.RevisionNumber().Eq(3))
                       .GetSingleResult <BagParent>();

            rev3.Children.Single().Name.Should().Be.EqualTo("child12");
        }
Beispiel #17
0
        public IEnumerable <long> GetRevisions(string entityName, object primaryKey)
        {
            ArgumentsTools.CheckNotNull(primaryKey, "Primary key");

            if (!verCfg.EntCfg.IsVersioned(entityName))
            {
                throw new NotAuditedException(entityName, entityName + " is not versioned!");
            }

            var resultList = CreateQuery().ForRevisionsOfEntity(entityName, false, true)
                             .AddProjection(AuditEntity.RevisionNumber())
                             .Add(AuditEntity.Id().Eq(primaryKey))
                             .GetResultList();

            return(from object revision in resultList select Convert.ToInt64(revision));
        }
        public void VerifyRevisionProjectionQuery()
        {
            var result = AuditReader().CreateQuery()
                         .ForRevisionsOfEntity(typeof(StrIntTestEntity), false, true)
                         .AddProjection(AuditEntity.RevisionNumber().Max())
                         .AddProjection(AuditEntity.RevisionNumber().Count())
                         .AddProjection(AuditEntity.RevisionNumber().CountDistinct())
                         .AddProjection(AuditEntity.RevisionNumber().Min())
                         .Add(AuditEntity.Id().Eq(id1))
                         .GetSingleResult <object[]>();

            Assert.AreEqual(4, result[0]);
            Assert.AreEqual(4, result[1]);
            Assert.AreEqual(4, result[2]);
            Assert.AreEqual(1, result[3]);
        }
Beispiel #19
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();
        }
Beispiel #20
0
        public IList GetRevisions(System.Type cls, Object primaryKey)
        {
            // todo: if a class is not versioned from the beginning, there's a missing ADD rev - what then?
            ArgumentsTools.CheckNotNull(cls, "Entity class");
            ArgumentsTools.CheckNotNull(primaryKey, "Primary key");
            CheckSession();

            String entityName = cls.FullName;

            if (!verCfg.EntCfg.IsVersioned(entityName))
            {
                throw new NotAuditedException(entityName, entityName + " is not versioned!");
            }

            return(CreateQuery().ForRevisionsOfEntity(cls, false, true)
                   .AddProjection(AuditEntity.RevisionNumber())
                   .Add(AuditEntity.Id().Eq(primaryKey))
                   .GetResultList());
        }
Beispiel #21
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();
        }
        public void VerifyMaximizeInDisjunction()
        {
            var idsToQuery = new[] { id1, id3 };
            var disjuction = AuditEntity.Disjunction();

            foreach (var id in idsToQuery)
            {
                disjuction.Add(AuditEntity.RevisionNumber().Maximize().Add(AuditEntity.Id().Eq(id)));
            }
            var result = AuditReader().CreateQuery()
                         .ForRevisionsOf <StrIntTestEntity>(true)
                         .Add(disjuction)
                         .Results();
            var idsSeen = new HashSet <int>();

            foreach (var entity in result)
            {
                var id = entity.Id;
                idsToQuery.Should().Contain(id);
                idsSeen.Add(id).Should().Be.True();
            }
        }