public void Setup()
        {
            var cfg = new FluentConfiguration();

            cfg.Audit <Dog>();
            cfg.Audit <Cat>();
            metas = cfg.CreateMetaData(null);
        }
Beispiel #2
0
        public void Setup()
        {
            var fluent = new FluentConfiguration();

            fluent.Audit <TestEntityWithContext>();
            fluent.Audit <FactoryCreatedTestEntity>()
            .UseFactory(new TestEntityFactory());

            metas = fluent.CreateMetaData(null);
        }
Beispiel #3
0
        public void Setup()
        {
            var cfg = new FluentConfiguration();

            cfg.Audit <FieldEntity>()
            .Exclude("data1")
            .Exclude("data2");
            cfg.Audit <NotAuditedOwnerEntity>()
            .ExcludeRelationData("RelationField");
            metas = cfg.CreateMetaData(null);
        }
        public void TestCustomLists()
        {
            var cfg = new Cfg.Configuration();

            cfg.Configure();
            cfg.AddResource("NHibernate.Envers.Tests.NetSpecific.UnitTests.CustomLists.Mapping.hbm.xml", GetType().Assembly);

            var ecfg = new FluentConfiguration();

            ecfg.Audit <AuditParent>().SetCollectionMapper <CustomCollectionMapperFactory <AuditChild> >(a => a.Children);
            ecfg.Audit <AuditChild>();

            // Throws exceptions without custon list hooks
            cfg.IntegrateWithEnvers(ecfg);
        }
Beispiel #5
0
        protected override void Configure(NHibernate.Cfg.Configuration configuration)
        {
            // The ValidatorInitializer and the ValidateEventListener share the same engine

            // Initialize the SharedEngine
            fortest = new NHibernateSharedEngineProvider();
            Cfg.Environment.SharedEngineProvider = fortest;
            ValidatorEngine ve = Cfg.Environment.SharedEngineProvider.GetEngine();

            ve.Clear();

            XmlConfiguration nhvc = new XmlConfiguration();

            nhvc.Properties[Cfg.Environment.ApplyToDDL]               = "true";
            nhvc.Properties[Cfg.Environment.AutoregisterListeners]    = "true";
            nhvc.Properties[Cfg.Environment.ValidatorMode]            = "UseAttribute";
            nhvc.Properties[Cfg.Environment.MessageInterpolatorClass] = typeof(PrefixMessageInterpolator).AssemblyQualifiedName;

            var enversConf = new FluentConfiguration();

            enversConf.Audit <Address>();
            configuration.IntegrateWithEnvers(enversConf);

            ve.Configure(nhvc);

            ValidatorInitializer.Initialize(configuration);
        }
Beispiel #6
0
        public void WhenRegisterInheritedThenBaseIsAudited()
        {
            var cfg = new FluentConfiguration();

            cfg.Audit(new[] { typeof(Dog), typeof(Cat) });
            cfg.CreateMetaData(null).Keys.Should().Have.SameValuesAs(new[] { typeof(Animal), typeof(Cat), typeof(Dog) });
        }
Beispiel #7
0
        public void WhenRegisterTypeThenIsAudited()
        {
            var cfg = new FluentConfiguration();

            cfg.Audit(new[] { typeof(Animal) });
            cfg.CreateMetaData(null).Keys.Should().Contain(typeof(Animal)).And.Have.Count.EqualTo(1);
        }
Beispiel #8
0
        public void Setup()
        {
            var cfg = new FluentConfiguration();

            cfg.Audit <NotAuditedOwnerEntity>()
            .ExcludeRelationData(s => s.Relation);
            metas = cfg.CreateMetaData(null);
        }
        public void ExcludingMethodShouldThrow()
        {
            var cfg = new FluentConfiguration();

            Assert.Throws <FluentException>(() =>
                                            cfg.Audit <MethodEntity>()
                                            .Exclude(obj => obj.SomeMethod()));
        }
        public void IncorrectString()
        {
            var cfg = new FluentConfiguration();

            Assert.Throws <FluentException>(() =>
                                            cfg.Audit(typeof(FieldEntity))
                                            .Exclude("data3")
                                            );
        }
        public void Setup()
        {
            var cfg = new FluentConfiguration();

            cfg.Audit <Dog>()
            .Exclude(dog => dog.Name)
            .Exclude("weight");
            metas = cfg.CreateMetaData(null);
        }
Beispiel #12
0
        public void Setup()
        {
            var cfg = new FluentConfiguration();

            cfg.Audit <SomePropsEntity>()
            .Exclude(s => s.Number)
            .Exclude(s => s.String)
            .Exclude(s => s.FieldNumber);
            metas = cfg.CreateMetaData(null);
        }
Beispiel #13
0
        public void WhenRegisterInheritedThenAllHasOnlyAuditedAttribute()
        {
            var cfg = new FluentConfiguration();

            cfg.Audit(new[] { typeof(Dog), typeof(Cat) });
            var metas = cfg.CreateMetaData(null);

            foreach (var entityMeta in metas.Values)
            {
                entityMeta.ClassMetas.OnlyContains <AuditedAttribute>();
            }
        }
Beispiel #14
0
        public void ShouldSetTableInfo()
        {
            var fluentCfg = new FluentConfiguration();

            fluentCfg.Audit(typeof(StrTestEntity))
            .SetTableInfo(table =>
            {
                table.Schema  = "testschema";
                table.Catalog = "testcatalog";
                table.Value   = "tableName";
            });
            CheckTableInfo(fluentCfg);
        }
Beispiel #15
0
        public void ShouldSetMapperGeneric()
        {
            var propInfo  = typeof(SetRefCollEntity).GetProperty("Collection");
            var fluentCfg = new FluentConfiguration();

            fluentCfg.Audit <SetRefCollEntity>()
            .SetCollectionMapper <SomeCollectionMapper>(e => e.Collection);

            var metas       = fluentCfg.CreateMetaData(null);
            var memberMetas = metas[typeof(SetRefCollEntity)].MemberMetas[propInfo];

            memberMetas.OnlyContains <CustomCollectionMapperAttribute>();
            memberMetas.OfType <CustomCollectionMapperAttribute>().First().CustomCollectionFactory
            .Should().Be.EqualTo <SomeCollectionMapper>();
        }
Beispiel #16
0
        public void ShouldSetJoinTableInfo()
        {
            var fluentCfg = new FluentConfiguration();

            fluentCfg.Audit(typeof(SetRefCollEntity))
            .SetTableInfo("Collection",
                          table =>
            {
                table.Schema             = "testschema";
                table.Catalog            = "testcatalog";
                table.TableName          = "tableName";
                table.InverseJoinColumns = new[] { "donald", "duck" };
            });
            CheckJoinTableInfo(fluentCfg);
        }
Beispiel #17
0
        public void PropertyShouldHaveOneAuditAttributeWithNoAuditedRelation_using_field()
        {
            var cfg = new FluentConfiguration();

            cfg.Audit <NotAuditedOwnerEntity>()
            .ExcludeRelationData("RelationField");
            metas = cfg.CreateMetaData(null);

            var propInfo = typeof(NotAuditedOwnerEntity).GetField("RelationField");
            var entMeta  = metas[typeof(NotAuditedOwnerEntity)];

            entMeta.MemberMetas[propInfo]
            .Should().Have.Count.EqualTo(1);
            var auditAttr = (AuditedAttribute)entMeta.MemberMetas[propInfo].First();

            auditAttr.TargetAuditMode.Should().Be.EqualTo(RelationTargetAuditMode.NotAudited);
        }