public void WrongPropertyInCustomAttribute() { 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(" assembly='NHibernate.Validator.Tests'"); sw.WriteLine(" namespace='NHibernate.Validator.Tests.Configuration'>"); sw.WriteLine("<class name='WellKnownRules'>"); sw.WriteLine("<property name='AP'>"); sw.WriteLine("<rule attribute='ACustomAttribute'>"); sw.WriteLine("<param name='WrongName' value='A string value'/>"); sw.WriteLine("</rule>"); sw.WriteLine("</property>"); sw.WriteLine("</class>"); sw.WriteLine("</nhv-mapping>"); sw.Flush(); } XmlMappingLoader ml = new XmlMappingLoader(); using (StreamReader sr = new StreamReader(tmpf)) { ml.AddInputStream(sr.BaseStream, tmpf); } NhvMapping map = ml.Mappings[0]; NhvmClass cm = map.@class[0]; XmlClassMapping rm = new XmlClassMapping(cm); MemberInfo mi; mi = typeof(WellKnownRules).GetField("AP"); Assert.That(() => rm.GetMemberAttributes(mi), Throws.TypeOf <InvalidPropertyNameException>()); }
public void AddWrongStream() { 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(); using (StreamReader sr = new StreamReader(tmpf)) { ActionAssert.Throws <ValidatorConfigurationException>(() => ml.AddInputStream(sr.BaseStream, tmpf)); } }
public void AddStream() { 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(); using (StreamReader sr = new StreamReader(tmpf)) { ml.AddInputStream(sr.BaseStream, tmpf); } Assert.AreEqual(1, ml.Mappings.Length); }