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 IList <Career> GetCareers(Person person, DateTime date)
 {
     return(AuditReaderFactory.Get(Session).CreateQuery()
            .ForEntitiesAtRevision(typeof(Career), GetRevisionNumberForDate(date))
            .Add(AuditEntity.Property("Person").Eq(person))
            .GetResultList <Career>());
 }
        public void VerifyEntitiesAvgMaxQuery()
        {
            var ver1 = (object[])AuditReader().CreateQuery()
                       .ForEntitiesAtRevision(typeof(IntTestEntity), 1)
                       .AddProjection(AuditEntity.Property("Number").Max())
                       .AddProjection(AuditEntity.Property("Number").Function("avg"))
                       .GetSingleResult();
            var ver2 = (object[])AuditReader().CreateQuery()
                       .ForEntitiesAtRevision(typeof(IntTestEntity), 2)
                       .AddProjection(AuditEntity.Property("Number").Max())
                       .AddProjection(AuditEntity.Property("Number").Function("avg"))
                       .GetSingleResult();
            var ver3 = (object[])AuditReader().CreateQuery()
                       .ForEntitiesAtRevision(typeof(IntTestEntity), 3)
                       .AddProjection(AuditEntity.Property("Number").Max())
                       .AddProjection(AuditEntity.Property("Number").Function("avg"))
                       .GetSingleResult();

            Assert.AreEqual(10, ver1[0]);
            Assert.AreEqual(6, ver1[1]);

            Assert.AreEqual(10, ver2[0]);
            Assert.AreEqual(6, ver2[1]);

            Assert.AreEqual(52, ver3[0]);
            Assert.AreEqual(20, ver3[1]);
        }
        public void ComponentAsIdGetAudit()
        {
            var ent1 = new Entity1
            {
                Id = 1
            };

            Save(ent1);

            var ent2 = new Entity2()
            {
                Id = 1
            };

            Save(ent2);

            var udf = new SomeEntUDF
            {
                Id = new ComponentAsId
                {
                    Key1 = ent1,
                    Key2 = ent2
                },
            };

            Save(udf);


            var history = Session.Auditer().CreateQuery()
                          .ForRevisionsOfEntity(typeof(SomeEntUDF), false, true)
                          .Add(AuditEntity.Property("Id.Key1.Id").Eq(ent1.Id))
                          .GetResultList();

            Assert.AreEqual(1, history.Count);
        }
 public void ShouldTraverse()
 {
     AuditReader().CreateQuery().ForEntitiesAtRevision <Car>(1)
     .TraverseRelation("Owner", JoinType.InnerJoin)
     .Add(AuditEntity.Property("Name").Like("Ford%")).Single()
     .Id.Should().Be.EqualTo(fordId);
 }
        public void VerifyHasNotChangedCriteria()
        {
            var list = AuditReader().CreateQuery().ForRevisionsOfEntity(typeof(AuditedTestEntity), true, true)
                       .Add(AuditEntity.Property("Data").HasNotChanged()).GetResultList <AuditedTestEntity>();

            list.Should().Be.Empty();
        }
        public void ShouldDoMultipleProjections()
        {
            var result = AuditReader().CreateQuery().ForEntitiesAtRevision(typeof(Car), 2)
                         .TraverseRelation("Owner", JoinType.InnerJoin)
                         .AddOrder(AuditEntity.Property("Age").Asc())
                         .AddProjection(AuditEntity.SelectEntity(false))
                         .TraverseRelation("Address", JoinType.InnerJoin)
                         .AddProjection(AuditEntity.Property("Number"))
                         .GetResultList();

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

            var index0 = (object[])result[0];

            ((Person)index0[0]).Id.Should().Be.EqualTo(vwOwnerId);
            index0[1].Should().Be.EqualTo(5);

            var index1 = (object[])result[1];

            ((Person)index1[0]).Id.Should().Be.EqualTo(fordOwnerId);
            index1[1].Should().Be.EqualTo(5);

            var index2 = (object[])result[2];

            ((Person)index2[0]).Id.Should().Be.EqualTo(toyotaOwnerId);
            index2[1].Should().Be.EqualTo(20);
        }
Exemple #8
0
 private static void addHasNotChangedProperties(IAuditQuery query, IEnumerable <string> propertyNames)
 {
     foreach (var propertyName in propertyNames)
     {
         query.Add(AuditEntity.Property(propertyName).HasNotChanged());
     }
 }
        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 IList <object[]> GetRawRevisions(Person person)
 {
     return(AuditReaderFactory.Get(Session).CreateQuery()
            .ForRevisionsOfEntity(typeof(PersonPhoto), false, true)
            .Add(AuditEntity.Property("Person").Eq(person))
            .GetResultList <object[]>());
 }
 public void EntitiesPropertyEqualsQuery()
 {
     var ver1 = AuditReader().CreateQuery()
                 .ForEntitiesAtRevision(typeof(StrIntTestEntity), 1)
                 .Add(AuditEntity.Property("Str").Eq("a"))
                 .GetResultList();
     var ver2 = AuditReader().CreateQuery()
                 .ForEntitiesAtRevision(typeof(StrIntTestEntity), 2)
                 .Add(AuditEntity.Property("Str").Eq("a"))
                 .GetResultList();
     var ver3 = AuditReader().CreateQuery()
                 .ForEntitiesAtRevision(typeof(StrIntTestEntity), 3)
                 .Add(AuditEntity.Property("Str").Eq("a"))
                 .GetResultList();
     CollectionAssert.AreEquivalent(new[]
                 {
                     new StrIntTestEntity {Id = id1, Str = "a", Number = 10},
                     new StrIntTestEntity {Id = id2, Str = "a", Number = 10}
                 }, ver1);
     CollectionAssert.AreEquivalent(new[]
                 {
                     new StrIntTestEntity {Id = id2, Str = "a", Number = 20}
                 }, ver2);
     CollectionAssert.AreEquivalent(new[]
                 {
                     new StrIntTestEntity {Id = id2, Str = "a", Number = 20},
                     new StrIntTestEntity {Id = id3, Str = "a", Number = 5}
                 }, ver3);
 }
 public void ShouldDoMultipleTraverse()
 {
     AuditReader().CreateQuery().ForEntitiesAtRevision <Car>(1)
     .TraverseRelation("Owner", JoinType.InnerJoin)
     .TraverseRelation("Address", JoinType.InnerJoin)
     .Add(AuditEntity.Property("Number").Eq(20)).Single()
     .Id.Should().Be.EqualTo(toyotaId);
 }
Exemple #13
0
 public void CanQueryOnAccessNoneProperty()
 {
     AuditReader().CreateQuery()
     .ForHistoryOf <Child, DefaultRevisionEntity>()
     .Add(AuditEntity.Property("ParentId").Eq(parentId))
     .Results()
     .Count().Should().Be.EqualTo(2);
 }
        public void ShouldWorkUsingObjectArrayDirectly()
        {
            var searchedInts = new object[] { 75 };

            Session.Auditer().CreateQuery().ForEntitiesAtRevision <Person>(1)
            .Add(AuditEntity.Property("Weight.Kilo").In(searchedInts))
            .Results().Should().Not.Be.Empty();
        }
 public void CanQueryComponentProperty_UsingUnderscore()
 {
     Session.Auditer().CreateQuery()
     .ForRevisionsOf <Person>()
     .Add(AuditEntity.Property("Weight_Kilo").Eq(personWeight))
     .Results()
     .Should().Have.Count.EqualTo(1);
 }
        public void ShouldNotGiveHit()
        {
            var searchedInts = new[] { 3, 85, 125 };

            Session.Auditer().CreateQuery().ForEntitiesAtRevision <Person>(1)
            .Add(AuditEntity.Property("Weight.Kilo").In(searchedInts))
            .Results().Should().Be.Empty();
        }
 public void ShouldFind()
 {
     AuditReader().CreateQuery().ForRevisionsOf <EntityReferingEmbEntity>()
     .Add(AuditEntity.Property("Data").Eq("data"))
     .Add(AuditEntity.Property("Reference").In(new List <EmbIdTestEntity> {
         embEntNoRef1, embEnt, embEntNoRef2
     }))
     .Results().Should().Have.SameSequenceAs(new[] { ent });
 }
 public void ShouldDoProjection()
 {
     AuditReader().CreateQuery().ForEntitiesAtRevision(typeof(Car), 2)
     .TraverseRelation("Owner", JoinType.InnerJoin)
     .AddProjection(AuditEntity.Property("Age"))
     .AddOrder(AuditEntity.Property("Age").Asc())
     .GetResultList <int>()
     .Should().Have.SameSequenceAs(20, 30, 40);
 }
        public void VerifyHasChangedCriteria()
        {
            var list = AuditReader().CreateQuery().ForRevisionsOfEntity(typeof(AuditedTestEntity), true, true)
                       .Add(AuditEntity.Property("Data").HasChanged()).GetResultList <AuditedTestEntity>();

            list.Should().Have.Count.EqualTo(2);
            list[0].Data.Should().Be.EqualTo("str1");
            list[1].Data.Should().Be.EqualTo("str2");
        }
Exemple #20
0
        public void ReferenceMulticolumnPropertyIsNullQuery()
        {
            var ver = AuditReader().CreateQuery()
                      .ForEntitiesAtRevision <SetRefIngEmbIdEntity>(2)
                      .Add(AuditEntity.Property("Reference").IsNull())
                      .Single();

            ver.Id.Should().Be.EqualTo(idMulticolumnReferenceToParentNull);
        }
Exemple #21
0
        public void ReferencePropertyIsNotNullQuery()
        {
            var ver = AuditReader().CreateQuery()
                      .ForEntitiesAtRevision <CollectionRefIngEntity>(3)
                      .Add(AuditEntity.Property("Reference").IsNotNull())
                      .Single();

            ver.Id.Should().Be.EqualTo(idReferenceToParentNotNull);
        }
 public void VerifyEmbeddedIdPropertyRestriction()
 {
     var ver2 = AuditReader().CreateQuery()
         .ForEntitiesAtRevision<EmbIdTestEntity>(2)
         .Add(AuditEntity.Property("Id.X").Eq(embId.X))
         .Add(AuditEntity.Property("Id.Y").Eq(embId.Y))
         .Single();
     ver2.Str1.Should().Be.EqualTo("something");
 }
 public void ShouldMissDueToOtherProoerty()
 {
     AuditReader().CreateQuery().ForRevisionsOf <EntityReferingEmbEntity>()
     .Add(AuditEntity.Property("Reference").In(new List <EmbIdTestEntity> {
         embEnt
     }))
     .Add(AuditEntity.Property("Data").Eq("not data"))
     .Results().Should().Be.Empty();
 }
Exemple #24
0
        public IList <AuditTrailDTO> GetEventCollectionRevisions <T>(Event e)
        {
            IList <object[]> objects = AuditReaderFactory.Get(Session).CreateQuery()
                                       .ForRevisionsOfEntity(typeof(T), false, true)
                                       .Add(AuditEntity.Property("Event").Eq(e))
                                       .GetResultList <object[]>();

            return(this.AddDifferences <T>(this.TransformToDto(objects)));
        }
 public void VerifyIdPropertyRestriction()
 {
     var ver2 = AuditReader().CreateQuery()
         .ForEntitiesAtRevision<StrIntTestEntity>(2)
         .Add(AuditEntity.Property("Id").Eq(id2))
         .Single();
     ver2.Number.Should().Be.EqualTo(20);
     ver2.Str.Should().Be.EqualTo("a");
 }
 public void VerifyInsensitiveLikeWithMatchMode()
 {
     var site1 = new StrIntTestEntity { Id = id1, Number = 10, Str = "aBc" };
     AuditReader().CreateQuery()
                              .ForRevisionsOf<StrIntTestEntity>(false)
                              .Add(AuditEntity.Property("Str").InsensitiveLike("BC", MatchMode.Anywhere))
                              .Single()
                              .Should().Be.EqualTo(site1);
 }
Exemple #27
0
 public void ShouldThrowUsingInOnCollection()
 {
     Assert.Throws <AuditException>(() =>
                                    AuditReader().CreateQuery().ForRevisionsOf <SetRefEdEntity>()
                                    .Add(AuditEntity.Property("Reffering").In(new List <SetRefIngEntity> {
         ing
     }))
                                    .Results());
 }
Exemple #28
0
 public void ShouldBeAbleToUseInOnSingleSide()
 {
     AuditReader().CreateQuery().ForRevisionsOf <SetRefIngEntity>()
     .Add(AuditEntity.Property("Reference").In(new List <SetRefEdEntity> {
         ed, edNotReferenced
     }))
     .Add(AuditEntity.Property("Data").Eq("bar"))
     .Results().Should().Contain(ing);
 }
Exemple #29
0
        public int GetEventCount(DateTime date)
        {
            int revision = this.GetRevisionNumberForDate(date);

            return(AuditReaderFactory.Get(Session).CreateQuery()
                   .ForEntitiesAtRevision(typeof(Event), Convert.ToInt64(revision))
                   .Add(AuditEntity.Property("Archive").Eq(false))
                   .GetResultList().Count);
        }
        public void VerifyEntitiesReferencedToId3()
        {
            var rev1_related = AuditReader().CreateQuery()
                               .ForEntitiesAtRevision(typeof(SetRefIngEmbIdEntity), 1)
                               .Add(AuditEntity.RelatedId("Reference").Eq(id3))
                               .GetResultList();
            var rev1 = AuditReader().CreateQuery()
                       .ForEntitiesAtRevision(typeof(SetRefIngEmbIdEntity), 1)
                       .Add(AuditEntity.Property("Reference").Eq(new SetRefEdEmbIdEntity {
                Id = id3
            }))
                       .GetResultList();

            var rev2_related = AuditReader().CreateQuery()
                               .ForEntitiesAtRevision(typeof(SetRefIngEmbIdEntity), 2)
                               .Add(AuditEntity.RelatedId("Reference").Eq(id3))
                               .GetResultList();
            var rev2 = AuditReader().CreateQuery()
                       .ForEntitiesAtRevision(typeof(SetRefIngEmbIdEntity), 2)
                       .Add(AuditEntity.Property("Reference").Eq(new SetRefEdEmbIdEntity {
                Id = id3
            }))
                       .GetResultList();

            var rev3_related = AuditReader().CreateQuery()
                               .ForEntitiesAtRevision(typeof(SetRefIngEmbIdEntity), 3)
                               .Add(AuditEntity.RelatedId("Reference").Eq(id3))
                               .GetResultList();
            var rev3 = AuditReader().CreateQuery()
                       .ForEntitiesAtRevision(typeof(SetRefIngEmbIdEntity), 3)
                       .Add(AuditEntity.Property("Reference").Eq(new SetRefEdEmbIdEntity {
                Id = id3
            }))
                       .GetResultList();

            Assert.AreEqual(rev1, rev1_related);
            Assert.AreEqual(rev2, rev2_related);
            Assert.AreEqual(rev3, rev3_related);

            CollectionAssert.IsEmpty(rev1);
            CollectionAssert.AreEquivalent(new[]
            {
                new SetRefIngEmbIdEntity {
                    Id = id1, Data = "x"
                }
            }, rev2);
            CollectionAssert.AreEquivalent(new[]
            {
                new SetRefIngEmbIdEntity {
                    Id = id1, Data = "x"
                },
                new SetRefIngEmbIdEntity {
                    Id = id2, Data = "y"
                }
            }, rev3);
        }