public void ApplyWrongConstraint() { XmlConfigurator.Configure(); NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration(); if (TestConfigurationHelper.hibernateConfigFile != null) cfg.Configure(TestConfigurationHelper.hibernateConfigFile); cfg.AddResource("NHibernate.Validator.Tests.Integration.WrongClass.whbm.xml", Assembly.GetExecutingAssembly()); Environment.SharedEngineProvider = null; XmlConfiguration nhvc = new XmlConfiguration(); nhvc.Properties[Environment.ApplyToDDL] = "true"; nhvc.Properties[Environment.AutoregisterListeners] = "true"; nhvc.Properties[Environment.ValidatorMode] = "UseAttribute"; using (LoggerSpy ls = new LoggerSpy(typeof(ValidatorInitializer), Level.Warn)) { ValidatorInitializer.Initialize(cfg); int found = ls.GetOccurenceContaining( string.Format("Unable to apply constraints on DDL for [MappedClass={0}]", typeof (WrongClass).FullName)); Assert.AreEqual(1, found); found = ls.GetOccurenceContaining( string.Format("Unable to apply constraints on DDL for [MappedClass={0}]", typeof (WrongClass1).FullName)); Assert.AreEqual(1, found); } }
public void WorkWithOutSharedEngine() { NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration(); if (TestConfigurationHelper.hibernateConfigFile != null) cfg.Configure(TestConfigurationHelper.hibernateConfigFile); string[] mappings = new string[] { "Integration.Address.hbm.xml", "Integration.Tv.hbm.xml", "Integration.TvOwner.hbm.xml", "Integration.Martian.hbm.xml", "Integration.Music.hbm.xml" }; foreach (string file in mappings) { cfg.AddResource("NHibernate.Validator.Tests" + "." + file, Assembly.GetExecutingAssembly()); } Environment.SharedEngineProvider = null; XmlConfiguration nhvc = new XmlConfiguration(); nhvc.Properties[Environment.ApplyToDDL] = "true"; nhvc.Properties[Environment.AutoregisterListeners] = "true"; nhvc.Properties[Environment.ValidatorMode] = "UseAttribute"; ValidatorInitializer.Initialize(cfg); }
public void ApplyWrongConstraint() { XmlConfigurator.Configure(); NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration(); if (TestConfigurationHelper.hibernateConfigFile != null) { cfg.Configure(TestConfigurationHelper.hibernateConfigFile); } cfg.AddResource("NHibernate.Validator.Tests.Integration.WrongClass.whbm.xml", Assembly.GetExecutingAssembly()); Environment.SharedEngineProvider = null; XmlConfiguration nhvc = new XmlConfiguration(); nhvc.Properties[Environment.ApplyToDDL] = "true"; nhvc.Properties[Environment.AutoregisterListeners] = "true"; nhvc.Properties[Environment.ValidatorMode] = "UseAttribute"; using (LoggerSpy ls = new LoggerSpy(typeof(ValidatorInitializer), Level.Warn)) { ValidatorInitializer.Initialize(cfg); int found = ls.GetOccurenceContaining( string.Format("Unable to apply constraints on DDL for [MappedClass={0}]", typeof(WrongClass).FullName)); Assert.AreEqual(1, found); found = ls.GetOccurenceContaining( string.Format("Unable to apply constraints on DDL for [MappedClass={0}]", typeof(WrongClass1).FullName)); Assert.AreEqual(1, found); } }
public void WorkWithOutSharedEngine() { NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration(); if (TestConfigurationHelper.hibernateConfigFile != null) { cfg.Configure(TestConfigurationHelper.hibernateConfigFile); } string[] mappings = new string[] { "Integration.Address.hbm.xml", "Integration.Tv.hbm.xml", "Integration.TvOwner.hbm.xml", "Integration.Martian.hbm.xml", "Integration.Music.hbm.xml" }; foreach (string file in mappings) { cfg.AddResource("NHibernate.Validator.Tests" + "." + file, Assembly.GetExecutingAssembly()); } Environment.SharedEngineProvider = null; XmlConfiguration nhvc = new XmlConfiguration(); nhvc.Properties[Environment.ApplyToDDL] = "true"; nhvc.Properties[Environment.AutoregisterListeners] = "true"; nhvc.Properties[Environment.ValidatorMode] = "UseAttribute"; ValidatorInitializer.Initialize(cfg); }
public NHibernate.Cfg.Configuration ConfigureNHibernate() { var cfg = new NHibernate.Cfg.Configuration(); if (TestConfigurationHelper.hibernateConfigFile != null) cfg.Configure(TestConfigurationHelper.hibernateConfigFile); cfg.AddResource("NHibernate.Validator.Tests.Specifics.NHV82.Person.hbm.xml", Assembly.GetExecutingAssembly()); return cfg; }
public NHibernate.Cfg.Configuration ConfigureNHibernate() { var cfg = new NHibernate.Cfg.Configuration(); if (TestConfigurationHelper.hibernateConfigFile != null) { cfg.Configure(TestConfigurationHelper.hibernateConfigFile); } cfg.AddResource("NHibernate.Validator.Tests.Specifics.NHV82.Person.hbm.xml", Assembly.GetExecutingAssembly()); return(cfg); }
private void Configure() { cfg = new NHibernate.Cfg.Configuration(); if (TestConfigurationHelper.hibernateConfigFile != null) { cfg.Configure(TestConfigurationHelper.hibernateConfigFile); } Assembly assembly = Assembly.Load(MappingsAssembly); foreach (string file in Mappings) { cfg.AddResource(MappingsAssembly + "." + file, assembly); } Configure(cfg); }
/// <summary> /// Registers the resources. /// </summary> /// <param name="cfg">The CFG.</param> /// <param name="facilityConfig">The facility config.</param> protected void RegisterResources(Configuration cfg, IConfiguration facilityConfig) { if (facilityConfig == null) return; foreach (IConfiguration item in facilityConfig.Children) { String name = item.Attributes["name"]; String assembly = item.Attributes["assembly"]; if (assembly != null) { cfg.AddResource(name, ObtainAssembly(assembly)); } else { cfg.AddXmlFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, name)); } } }
/// <remarks> /// Cначала осуществляется поиск fluent-маппинга, в случае /// неудачи ищется hbm.xml-маппинг. /// </remarks> private ISessionFactoryProvider FindMapping(Type type, Assembly assembly = null) { assembly ??= type.Assembly; var fluentMappings = assembly.GetTypes() .Where(x => x.IsSubclassOf(typeof(ClasslikeMapBase <>).MakeGenericType(type))) .ToList(); if (fluentMappings.Count > 1) { throw new EntityMappingRegistrationException($"There are more than one fluent mapping for {type.FullName}."); } var fluentMapping = fluentMappings.SingleOrDefault(); if (fluentMapping != null) { _fluentMappingTypes.Add(fluentMapping); Logger.LogDebug($"An entity with the {type.FullName} has been registered with the fluent mapping"); } else { var typeManifestName = assembly.GetManifestResourceNames() .SingleOrDefault(x => x.Contains($"{type.FullName}.hbm.xml")); if (string.IsNullOrEmpty(typeManifestName)) { throw new EntityMappingRegistrationException($"There is no .hbm.xml mapping for {type.FullName}."); } nhConfig.AddResource(typeManifestName, assembly); Logger.LogDebug($"An entity with the {type.FullName} and the mapping {typeManifestName} has been registered"); } return(this); }
private void Configure() { cfg = new NHibernate.Cfg.Configuration(); if (TestConfigurationHelper.hibernateConfigFile != null) cfg.Configure(TestConfigurationHelper.hibernateConfigFile); Assembly assembly = Assembly.Load(MappingsAssembly); foreach (string file in Mappings) { cfg.AddResource(MappingsAssembly + "." + file, assembly); } Configure(cfg); }