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 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 WellFormedConfiguration() { XmlConfigurator.Configure(); string xml = @"<nhv-configuration xmlns='urn:nhv-configuration-1.0'> <property name='apply_to_ddl'>false</property> <property name='autoregister_listeners'>false</property> <property name='message_interpolator_class'>Myinterpolator</property> <property name='external_mappings_loader_class'>MyLoader</property> <property name='default_validator_mode'>OverrideAttributeWithXml</property> <property name='constraint_validator_factory'>SomeNamespace.Type,SomeAssembly</property> <mapping assembly='aAssembly'/> <mapping file='aFile'/> <mapping assembly='anotherAssembly' resource='TheResource'/> <shared_engine_provider class='MySharedEngineProvider'/> </nhv-configuration>" ; XmlDocument cfgXml = new XmlDocument(); cfgXml.LoadXml(xml); XmlTextReader xtr = new XmlTextReader(xml, XmlNodeType.Document, null); XmlConfiguration cfg; using (LoggerSpy ls = new LoggerSpy(typeof(XmlConfiguration), Level.Warn)) { cfg = new XmlConfiguration(xtr); int found = ls.GetOccurenceContaining(NHibernate.Validator.Cfg.Environment.SharedEngineClass + " propety is ignored out of application configuration file."); Assert.AreEqual(1, found); } Assert.AreEqual("MySharedEngineProvider", cfg.SharedEngineProviderClass); Assert.AreEqual(6, cfg.Properties.Count); Assert.AreEqual(3, cfg.Mappings.Count); Assert.AreEqual("false", cfg.Properties["apply_to_ddl"]); Assert.AreEqual("false", cfg.Properties["autoregister_listeners"]); Assert.AreEqual("Myinterpolator", cfg.Properties["message_interpolator_class"]); Assert.AreEqual("MyLoader", cfg.Properties["external_mappings_loader_class"]); Assert.AreEqual("OverrideAttributeWithXml", cfg.Properties["default_validator_mode"]); Assert.AreEqual("SomeNamespace.Type,SomeAssembly", cfg.Properties["constraint_validator_factory"]); Assert.Contains(new MappingConfiguration("aAssembly", ""), (IList)cfg.Mappings); Assert.Contains(new MappingConfiguration("aFile"), (IList)cfg.Mappings); Assert.Contains(new MappingConfiguration("anotherAssembly", "TheResource"), (IList)cfg.Mappings); }
public void DuplicateClassDef() { ValidatorEngine ve = new ValidatorEngine(); XmlConfiguration nhvc = new XmlConfiguration(); nhvc.Properties[Environment.ApplyToDDL] = "false"; nhvc.Properties[Environment.AutoregisterListeners] = "false"; nhvc.Properties[Environment.ValidatorMode] = "useExternal"; string an = Assembly.GetExecutingAssembly().FullName; nhvc.Mappings.Add(new MappingConfiguration(an, "NHibernate.Validator.Tests.Base.Address.nhv.xml")); nhvc.Mappings.Add(new MappingConfiguration(an, "NHibernate.Validator.Tests.Engine.DuplicatedAddress.nhv.xml")); using (LoggerSpy ls = new LoggerSpy(typeof(IClassMappingFactory).Assembly, "NHibernate.Validator.Engine.StateFullClassMappingFactory", Level.Warn)) { ve.Configure(nhvc); int found = ls.GetOccurencesOfMessage( x => x.StartsWith("Duplicated external definition for class " + typeof(Address).AssemblyQualifiedName)); Assert.AreEqual(1, found); } }
public void DuplicateClassDef() { XmlConfigurator.Configure(); ValidatorEngine ve = new ValidatorEngine(); XmlConfiguration nhvc = new XmlConfiguration(); nhvc.Properties[Environment.ApplyToDDL] = "false"; nhvc.Properties[Environment.AutoregisterListeners] = "false"; nhvc.Properties[Environment.ValidatorMode] = "useExternal"; string an = Assembly.GetExecutingAssembly().FullName; nhvc.Mappings.Add(new MappingConfiguration(an, "NHibernate.Validator.Tests.Base.Address.nhv.xml")); nhvc.Mappings.Add(new MappingConfiguration(an, "NHibernate.Validator.Tests.Engine.DuplicatedAddress.nhv.xml")); using (LoggerSpy ls = new LoggerSpy("NHibernate.Validator.Engine.StateFullClassMappingFactory", Level.Warn)) { ve.Configure(nhvc); int found = ls.GetOccurencesOfMessage( x => x.StartsWith("Duplicated external definition for class " + typeof (Address).AssemblyQualifiedName)); Assert.AreEqual(1, found); } }
public void WellFormedConfiguration() { XmlConfigurator.Configure(); string xml = @"<nhv-configuration xmlns='urn:nhv-configuration-1.0'> <property name='apply_to_ddl'>false</property> <property name='autoregister_listeners'>false</property> <property name='message_interpolator_class'>Myinterpolator</property> <property name='external_mappings_loader_class'>MyLoader</property> <property name='default_validator_mode'>OverrideAttributeWithXml</property> <property name='constraint_validator_factory'>SomeNamespace.Type,SomeAssembly</property> <mapping assembly='aAssembly'/> <mapping file='aFile'/> <mapping assembly='anotherAssembly' resource='TheResource'/> <shared_engine_provider class='MySharedEngineProvider'/> </nhv-configuration>"; XmlDocument cfgXml = new XmlDocument(); cfgXml.LoadXml(xml); XmlTextReader xtr = new XmlTextReader(xml, XmlNodeType.Document, null); XmlConfiguration cfg; using (LoggerSpy ls = new LoggerSpy(typeof(XmlConfiguration), Level.Warn)) { cfg = new XmlConfiguration(xtr); int found = ls.GetOccurenceContaining(NHibernate.Validator.Cfg.Environment.SharedEngineClass + " propety is ignored out of application configuration file."); Assert.AreEqual(1, found); } Assert.AreEqual("MySharedEngineProvider", cfg.SharedEngineProviderClass); Assert.AreEqual(6, cfg.Properties.Count); Assert.AreEqual(3, cfg.Mappings.Count); Assert.AreEqual("false", cfg.Properties["apply_to_ddl"]); Assert.AreEqual("false", cfg.Properties["autoregister_listeners"]); Assert.AreEqual("Myinterpolator", cfg.Properties["message_interpolator_class"]); Assert.AreEqual("MyLoader", cfg.Properties["external_mappings_loader_class"]); Assert.AreEqual("OverrideAttributeWithXml", cfg.Properties["default_validator_mode"]); Assert.AreEqual("SomeNamespace.Type,SomeAssembly",cfg.Properties["constraint_validator_factory"]); Assert.Contains(new MappingConfiguration("aAssembly", ""), (IList)cfg.Mappings); Assert.Contains(new MappingConfiguration("aFile"), (IList)cfg.Mappings); Assert.Contains(new MappingConfiguration("anotherAssembly", "TheResource"), (IList)cfg.Mappings); }