コード例 #1
0
        public void MixingLoaders()
        {
            string xml =
                @"<nhv-configuration xmlns='urn:nhv-configuration-1.0'>
		<mapping assembly='NHibernate.Validator.Tests' resource='NHibernate.Validator.Tests.Base.Address.nhv.xml'/>
	</nhv-configuration>"    ;
            XmlDocument cfgXml = new XmlDocument();

            cfgXml.LoadXml(xml);
            XmlTextReader    xtr = new XmlTextReader(xml, XmlNodeType.Document, null);
            XmlConfiguration cfg = new XmlConfiguration(xtr);
            XmlMappingLoader ml  = new XmlMappingLoader();

            ml.LoadMappings(cfg.Mappings);

            string tmpf = Path.GetTempFileName();

            using (StreamWriter sw = new StreamWriter(tmpf))
            {
                sw.WriteLine("<?xml version='1.0' encoding='utf-8' ?>");
                sw.WriteLine("<nhv-mapping xmlns='urn:nhibernate-validator-1.0'>");
                sw.WriteLine("<class name='Boo'>");
                sw.WriteLine("<property name='field'><notnullorempty/></property>");
                sw.WriteLine("</class>");
                sw.WriteLine("</nhv-mapping>");
                sw.Flush();
            }
            ml.AddFile(tmpf);
            Assert.AreEqual(2, ml.Mappings.Length);
        }
コード例 #2
0
        public void ResourceNotFound()
        {
            string xml =
                @"<nhv-configuration xmlns='urn:nhv-configuration-1.0'>
		<mapping assembly='NHibernate.Validator.Tests' resource='Base.Address.nhv.xml'/>
	</nhv-configuration>"    ;
            XmlDocument cfgXml = new XmlDocument();

            cfgXml.LoadXml(xml);
            XmlTextReader    xtr = new XmlTextReader(xml, XmlNodeType.Document, null);
            XmlConfiguration cfg = new XmlConfiguration(xtr);
            XmlMappingLoader ml  = new XmlMappingLoader();

            ActionAssert.Throws <ValidatorConfigurationException>(() => ml.LoadMappings(cfg.Mappings));
        }
コード例 #3
0
        public void CompiledMappings()
        {
            const string xml    = @"<nhv-configuration xmlns='urn:nhv-configuration-1.0'>
		<mapping assembly='NHibernate.Validator.Tests' resource='NHibernate.Validator.Tests.Base.Address.nhv.xml'/>
	</nhv-configuration>"    ;
            var          cfgXml = new XmlDocument();

            cfgXml.LoadXml(xml);
            var xtr = new XmlTextReader(xml, XmlNodeType.Document, null);
            var cfg = new XmlConfiguration(xtr);
            var ml  = new XmlMappingLoader();

            ml.LoadMappings(cfg.Mappings);
            var cm = ml.GetMappings();

            Assert.That(cm.Count(), Is.EqualTo(1));
            Assert.That(cm.FirstOrDefault(x => x.EntityType == typeof(Base.Address)), Is.Not.Null);
        }
コード例 #4
0
        public void LoadMappingsNull()
        {
            XmlMappingLoader ml = new XmlMappingLoader();

            ActionAssert.Throws <ArgumentNullException>(() => ml.LoadMappings(null));
        }
コード例 #5
0
        public void LoadMappingsNull()
        {
            XmlMappingLoader ml = new XmlMappingLoader();

            Assert.That(() => ml.LoadMappings(null), Throws.TypeOf <ArgumentNullException>());
        }