public void WhenGetAuditConfMultipleTimesThenDoesNotThrowsForDupicatedMappings()
        {
            var cfg = new Cfg.Configuration();

            cfg.Configure();

            cfg.AddXml(SimpleMapping);
            AuditConfiguration.GetFor(cfg);             //<< external call

            AuditConfiguration.SetConfigMetas(cfg, new AttributeConfiguration());
            var listeners = new[] { new AuditEventListener() };

            cfg.AppendListeners(ListenerType.PostInsert, listeners);
            cfg.AppendListeners(ListenerType.PostUpdate, listeners);
            cfg.AppendListeners(ListenerType.PostDelete, listeners);
            cfg.AppendListeners(ListenerType.PostCollectionRecreate, listeners);
            cfg.AppendListeners(ListenerType.PreCollectionRemove, listeners);
            cfg.AppendListeners(ListenerType.PreCollectionUpdate, listeners);

            Executing.This(() =>
            {
                using (cfg.BuildSessionFactory())
                {
                    // build the session factory to run initialization of listeners and be completelly sure
                    // there isn't problems
                }
            }).Should().NotThrow();
        }
        private Cfg.Configuration CreateConfig()
        {
            var cfg = new Cfg.Configuration();

            cfg.Configure();
            addMappings(cfg);
            return(cfg);
        }
        public void ShouldThrowCorrectException()
        {
            var cfg = new Cfg.Configuration();

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

            Assert.Throws <AuditException>(() => cfg.IntegrateWithEnvers());
        }
		///<summary>
		/// Create a NHibernate Configuration
		///</summary>
		///<returns></returns>
		private Cfg.Configuration CreateNHConfiguration() {
			Cfg.Configuration retVal = new Cfg.Configuration();
            if(!string.IsNullOrEmpty(configuration.NHConfigFile))
            {
                string configFile = configuration.NHConfigFile.Replace("~", AppDomain.CurrentDomain.BaseDirectory);
                retVal.Configure(configFile);
            }
			return retVal;
		}
        public void WhenCallIntegrationThenMappingsShouldBeAvailableImmediately()
        {
            var cfg = new Cfg.Configuration();

            cfg.Configure();
            cfg.AddXml(SimpleMapping);
            cfg.IntegrateWithEnvers();

            cfg.ClassMappings.Where(cm => cm.EntityName.Contains("SimpleAuiditableForConfEntity")).Should().Have.Count.EqualTo(2);
        }
        public void ShouldResultInMappingException()
        {
            var nhCfg = new Cfg.Configuration();

            nhCfg.Configure()
            .AddResource("NHibernate.Envers.Tests.Integration.SuperClass.AuditOverride.Invalid.Mapping.hbm.xml", GetType().Assembly);

            Assert.Throws <MappingException>(() =>
                                             nhCfg.IntegrateWithEnvers());
        }
Ejemplo n.º 7
0
 ///<summary>
 /// Create a NHibernate Configuration
 ///</summary>
 ///<returns></returns>
 private Cfg.Configuration CreateNHConfiguration()
 {
     Cfg.Configuration retVal = new Cfg.Configuration();
     if (!string.IsNullOrEmpty(configuration.NHConfigFile))
     {
         string configFile = configuration.NHConfigFile.Replace("~", AppDomain.CurrentDomain.BaseDirectory);
         retVal.Configure(configFile);
     }
     return(retVal);
 }
        public void Setup()
        {
            var cfg = new Cfg.Configuration();

            cfg.Configure();
            var ass = GetType().Assembly;

            cfg.AddResource("NHibernate.Envers.Tests.NetSpecific.Integration.Configuration.Inheritance.Mapping.hbm.xml", ass);
            var attrConf = new AttributeConfiguration();

            metaData = attrConf.CreateMetaData(cfg);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        public void WhenIntegrateThenBuildSessionFactoryDoesNotThrows()
        {
            var cfg = new Cfg.Configuration();

            cfg.Configure().OverrideSettingsFromEnvironmentVariables();
            cfg.AddXml(SimpleMapping);
            cfg.IntegrateWithEnvers();

            Executing.This(() =>
            {
                using (cfg.BuildSessionFactory())
                {
                    // build the session factory to run initialization of listeners and be completelly sure
                    // there isn't problems
                }
            }).Should().NotThrow();
        }
 public void BaseSetup()
 {
     TestAssembly = GetType().Assembly.GetName().Name;
     Cfg          = new Cfg.Configuration().SetEnversProperty(ConfigurationKey.AuditStrategy, StrategyType);
     AddToConfiguration(Cfg);
     Cfg.Configure().OverrideSettingsFromEnvironmentVariables();
     addMappings();
     Cfg.IntegrateWithEnvers(new AuditEventListener(), EnversConfiguration());
     createDb();
     _sessionFactory = (ISessionFactoryImplementor)Cfg.BuildSessionFactory();
     if (!testShouldRun())
     {
         Assert.Ignore(TestShouldNotRunMessage());
     }
     createDbSchema();
     Session = openSession(_sessionFactory);
     Initialize();
     closeSessionAndAuditReader();
     Session = openSession(_sessionFactory);
 }
Ejemplo n.º 12
0
        public void BaseSetup()
        {
            TestAssembly = GetType().Assembly.GetName().Name;
            Cfg          = new Cfg.Configuration();
            Cfg.SetEnversProperty(ConfigurationKey.AuditStrategy, StrategyType);
            AddToConfiguration(Cfg);
            Cfg.Configure();
            addMappings();
            Cfg.IntegrateWithEnvers(new AuditEventListener(), EnversConfiguration());
            SessionFactory = Cfg.BuildSessionFactory();
            var notRun = TestShouldNotRunMessage();

            if (!string.IsNullOrEmpty(notRun))
            {
                Assert.Ignore(notRun);
            }
            Session = openSession(SessionFactory);
            Initialize();
            closeSessionAndAuditReader();
            Session = openSession(SessionFactory);
        }
Ejemplo n.º 13
0
 protected virtual void Configure(Cfg.Configuration configuration)
 {
     configuration.Configure();
 }