Ejemplo n.º 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);
        }
        public void VerifyEntitiesReferencedByIng1ToId3()
        {
            var rev1_related = AuditReader().CreateQuery()
                               .ForEntitiesAtRevision(typeof(SetRefIngEmbIdEntity), 1)
                               .Add(AuditEntity.RelatedId("Reference").Eq(id3))
                               .Add(AuditEntity.Id().Eq(id1))
                               .GetResultList();
            var rev2_related = AuditReader().CreateQuery()
                               .ForEntitiesAtRevision(typeof(SetRefIngEmbIdEntity), 2)
                               .Add(AuditEntity.RelatedId("Reference").Eq(id3))
                               .Add(AuditEntity.Id().Eq(id1))
                               .GetResultList();
            var rev3_related = AuditReader().CreateQuery()
                               .ForEntitiesAtRevision(typeof(SetRefIngEmbIdEntity), 3)
                               .Add(AuditEntity.RelatedId("Reference").Eq(id3))
                               .Add(AuditEntity.Id().Eq(id1))
                               .GetResultList();

            CollectionAssert.IsEmpty(rev1_related);
            CollectionAssert.AreEquivalent(new[] { new SetRefIngEmbIdEntity {
                                                       Id = id1, Data = "x"
                                                   } }, rev2_related);
            CollectionAssert.AreEquivalent(new[] { new SetRefIngEmbIdEntity {
                                                       Id = id1, Data = "x"
                                                   } }, rev3_related);
        }
Ejemplo n.º 3
0
 public IList <object[]> GetRawRevisions(Person person)
 {
     return(AuditReaderFactory.Get(Session).CreateQuery()
            .ForRevisionsOfEntity(typeof(Person), false, true)
            .Add(AuditEntity.Id().Eq(person.Id))
            .GetResultList <object[]>());
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public void SelectEntitiesAndRevisionsQuery()
        {
            var result = AuditReader().CreateQuery()
                         .ForRevisionsOfEntity(typeof(StrIntTestEntity), false, true)
                         .Add(AuditEntity.Id().Eq(id1))
                         .GetResultList <IList>();

            Assert.AreEqual(new StrIntTestEntity {
                Id = id1, Str = "a", Number = 10
            }, result[0][0]);
            Assert.AreEqual(new StrIntTestEntity {
                Id = id1, Str = "aBc", Number = 10
            }, result[1][0]);
            Assert.AreEqual(new StrIntTestEntity {
                Id = id1
            }, result[2][0]);

            Assert.AreEqual(1, ((DefaultRevisionEntity)result[0][1]).Id);
            Assert.AreEqual(2, ((DefaultRevisionEntity)result[1][1]).Id);
            Assert.AreEqual(4, ((DefaultRevisionEntity)result[2][1]).Id);

            Assert.AreEqual(RevisionType.Added, result[0][2]);
            Assert.AreEqual(RevisionType.Modified, result[1][2]);
            Assert.AreEqual(RevisionType.Deleted, result[2][2]);
        }
        public void VerifyHistoryOfAccountNotAuditedOwners()
        {
            var noProxyPersonVer1 = new NotAuditedNoProxyPerson {
                PersonId = noProxyPersonId, Name = "Kinga"
            };
            var proxyPersonVer1 = new NotAuditedProxyPerson {
                PersonId = proxyPersonId, Name = "Lukasz"
            };
            var accountNotAuditedOwnersVer1 = new AccountNotAuditedOwners {
                AccountId = accountNotAuditedOwnersId, Type = "Standard"
            };

            noProxyPersonVer1.Account           = accountNotAuditedOwnersVer1;
            proxyPersonVer1.Account             = accountNotAuditedOwnersVer1;
            accountNotAuditedOwnersVer1.Owner   = noProxyPersonVer1;
            accountNotAuditedOwnersVer1.CoOwner = proxyPersonVer1;

            var result = (object[])AuditReader().CreateQuery().ForRevisionsOfEntity(typeof(AccountNotAuditedOwners), false, true)
                         .Add(AuditEntity.Id().Eq(accountNotAuditedOwnersId))
                         .GetResultList()[0];

            var theResult = (AccountNotAuditedOwners)result[0];

            result[0].Should().Be.EqualTo(accountNotAuditedOwnersVer1);
            result[2].Should().Be.EqualTo(RevisionType.Added);
            // Checking non-proxy reference
            theResult.Owner.Should().Be.EqualTo(accountNotAuditedOwnersVer1.Owner);
            // checking proxy reference
            (theResult.CoOwner is INHibernateProxy).Should().Be.True();
            theResult.CoOwner.PersonId.Should().Be.EqualTo(proxyPersonVer1.PersonId);

            AuditReader().Find(typeof(AccountNotAuditedOwners), accountNotAuditedOwnersId, 2)
            .Should().Be.EqualTo(accountNotAuditedOwnersVer1);
        }
Ejemplo n.º 7
0
 public void SelectRevisionTypeQueryUsingRevisionInfo()
 {
     var result = AuditReader().CreateQuery().ForHistoryOf<StrIntTestEntity, DefaultRevisionEntity>()
         .Add(AuditEntity.Id().Eq(id1))
         .Results();
     result.Select(x => x.Operation).Should().Have.SameSequenceAs(RevisionType.Added, RevisionType.Modified, RevisionType.Deleted);
 }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public void QueryHistoryReturnAllRevisions()
        {
            var parentRevisions = AuditReader().CreateQuery().ForRevisionsOf <Parent>()
                                  .Add(AuditEntity.Id().Eq(parentId))
                                  .Results().ToList();

            Assert.AreEqual(3, parentRevisions.Count);
        }
Ejemplo n.º 10
0
 public void VerifyEntityNotModifiedAtRevision()
 {
     var result = AuditReader().CreateQuery()
                 .ForEntitiesModifiedAtRevision(typeof(StrIntTestEntity), 3)
                 .Add(AuditEntity.Id().Eq(id1))
                 .GetResultList<StrIntTestEntity>();
     result.Should().Be.Empty();
 }
Ejemplo n.º 11
0
 public void EntitiesIdQuery()
 {
     var ver2 = AuditReader().CreateQuery()
                 .ForEntitiesAtRevision(typeof (StrIntTestEntity), 2)
                 .Add(AuditEntity.Id().Eq(id2))
                 .GetSingleResult<StrIntTestEntity>();
     Assert.AreEqual(new StrIntTestEntity { Id = id2, Str = "a", Number = 20 }, ver2);
 }
Ejemplo n.º 12
0
 public void VerifyUnusualIdFieldName()
 {
     AuditReader().CreateQuery().ForRevisionsOf <UnusualIdNamingEntity>(true)
     .Add(AuditEntity.Id().Like("Id1"))
     .Single()
     .Should().Be.EqualTo(new UnusualIdNamingEntity {
         UniqueField = "Id1", VariousData = "data1"
     });
 }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        public IList <AuditTrailDTO> GetEventRevisions(Event e)
        {
            IList <object[]> objects = AuditReaderFactory.Get(Session).CreateQuery()
                                       .ForRevisionsOfEntity(typeof(Event), false, true)
                                       .Add(AuditEntity.Id().Eq(e.Id))
                                       .GetResultList <object[]>();

            return(this.AddDifferences <Event>(this.TransformToDto(objects)));
        }
 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();
 }
Ejemplo n.º 16
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 VerifyRevisionTypes()
        {
            var results = AuditReader().CreateQuery()
                          .ForRevisionsOfEntity(typeof(StrTestEntity), false, true)
                          .Add(AuditEntity.Id().Eq(id))
                          .GetResultList();

            Assert.AreEqual(RevisionType.Added, ((IList)results[0])[2]);
            Assert.AreEqual(RevisionType.Modified, ((IList)results[1])[2]);
        }
Ejemplo n.º 18
0
        public void VerifyRevisionTypes()
        {
            //rk - avoid casting to ilist. generics?
            var results = AuditReader().CreateQuery()
                          .ForRevisionsOfEntity(typeof(StrTestEntity), false, true)
                          .Add(AuditEntity.Id().Eq(id))
                          .GetResultList();

            Assert.AreEqual(RevisionType.Added, ((IList)results[0])[2]);
            Assert.AreEqual(RevisionType.Deleted, ((IList)results[1])[2]);
        }
        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);
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
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");
        }
Ejemplo n.º 22
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");
        }
        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 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);
        }
Ejemplo n.º 25
0
        public void ParentsHistoricalVersionsPointsToCurrentNotAuditedChild()
        {
            var parentRevisions = AuditReader().CreateQuery().ForRevisionsOf <Parent>()
                                  .Add(AuditEntity.Id().Eq(parentId))
                                  .Results().ToList();

            foreach (var revision in parentRevisions)
            {
                Assert.AreEqual(childLatestStr, revision.Child.Str);
            }
        }
Ejemplo n.º 26
0
 public void SelectEntitiesQuery()
 {
     var result = AuditReader().CreateQuery()
                     .ForRevisionsOfEntity(typeof (StrIntTestEntity), true, false)
                     .Add(AuditEntity.Id().Eq(id1))
                     .GetResultList<StrIntTestEntity>();
     CollectionAssert.AreEquivalent(new[]
                 {
                     new StrIntTestEntity {Id = id1, Str = "a", Number = 10},
                     new StrIntTestEntity {Id = id1, Str = "aBc", Number = 10}
                 }, result);
 }
Ejemplo n.º 27
0
        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]);
        }
 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();
 }
Ejemplo n.º 29
0
 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
     });
 }
Ejemplo n.º 30
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");
        }