コード例 #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 AddWrongFile()
        {
            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("<no valid node>");
                sw.WriteLine("</nhv-mapping>");
                sw.Flush();
            }
            XmlMappingLoader ml = new XmlMappingLoader();

            ActionAssert.Throws <ValidatorConfigurationException>(() => ml.AddFile(tmpf));
        }
コード例 #3
0
        public void AddFile()
        {
            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();
            }
            XmlMappingLoader ml = new XmlMappingLoader();

            ml.AddFile(tmpf);
            Assert.AreEqual(1, ml.Mappings.Length);
        }
コード例 #4
0
        public void AddWrongFileName()
        {
            XmlMappingLoader ml = new XmlMappingLoader();

            Assert.Throws <ValidatorConfigurationException>(() => ml.AddFile("NoExistFile"), "Could not load file NoExistFile");
        }