|
From: Oleg T. <he...@us...> - 2005-10-25 21:34:02
|
Update of /cvsroot/mvp-xml/Common/v2/test/UpperLowerTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1205/v2/test/UpperLowerTests Added Files: Customer.cs Customer.xml Customer.xsd Customer.xsx FirstUpperLowerTests.cs Log Message: --- NEW FILE: Customer.xml --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Customer.xsx --- <?xml version="1.0" encoding="utf-8"?> <!--This file is auto-generated by the XML Schema Designer. It holds layout information for components on the designer surface.--> <XSDDesignerLayout layoutVersion="2" viewPortLeft="0" viewPortTop="0" zoom="100"> <customer_XmlElement left="317" top="254" width="5292" height="2963" selected="0" zOrder="1" index="0" expanded="1"> <order_XmlElement left="317" top="3725" width="5292" height="2963" selected="0" zOrder="2" index="1" expanded="1" /> </customer_XmlElement> </XSDDesignerLayout> --- NEW FILE: Customer.xsd --- <?xml version="1.0" encoding="utf-8" ?> <xs:schema id="Customer" targetNamespace="mvp-xml-customer" elementFormDefault="qualified" xmlns="mvp-xml-customer" xmlns:mstns="mvp-xml-customer" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Customer"> <xs:complexType> <xs:sequence> <xs:element name="Name" type="xs:string" /> <xs:element name="Order"> <xs:complexType> <xs:attribute name="Id" type="xs:int" use="required" /> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="Id" type="xs:string" /> </xs:complexType> </xs:element> </xs:schema> --- NEW FILE: Customer.cs --- namespace Mvp.Xml.Tests.UpperLowerTests { /// <remarks/> [System.Xml.Serialization.XmlTypeAttribute(Namespace="mvp-xml-customer")] [System.Xml.Serialization.XmlRootAttribute(Namespace="mvp-xml-customer", IsNullable=false)] public class Customer { /// <remarks/> public string Name; /// <remarks/> public CustomerOrder Order; /// <remarks/> [System.Xml.Serialization.XmlAttributeAttribute()] public string Id; } /// <remarks/> [System.Xml.Serialization.XmlTypeAttribute(Namespace="mvp-xml-customer")] public class CustomerOrder { /// <remarks/> [System.Xml.Serialization.XmlAttributeAttribute()] public int Id; } } --- NEW FILE: FirstUpperLowerTests.cs --- #region using using System; using System.Diagnostics; using System.IO; using System.Reflection; using System.Xml; using System.Xml.Serialization; using System.Xml.XPath; using System.Xml.Schema; using Mvp.Xml.Common; using NUnit.Framework; #endregion using namespace Mvp.Xml.Tests.UpperLowerTests { [TestFixture] public class FirstUpperLowerTests { [Test] public void XmlFirstUpperReader() { string xml = "<customer id='1' pp:id='aba' xmlns='urn-kzu' xmlns:pp='urn-pepenamespace'><pp:order /><order id='1'>Chocolates</order></customer>"; XmlFirstUpperReader fr = new XmlFirstUpperReader(new StringReader(xml)); fr.MoveToContent(); Assert.AreEqual("Customer", fr.LocalName); fr.MoveToFirstAttribute(); Assert.AreEqual("Id", fr.LocalName); fr.MoveToNextAttribute(); Assert.AreEqual("pp:Id", fr.Name); // Namespace ordering is not guaranteed. fr.MoveToNextAttribute(); Assert.IsTrue( fr.Name == "xmlns" || fr.Name == "xmlns:pp" ); fr.MoveToNextAttribute(); Assert.IsTrue( fr.Name == "xmlns" || fr.Name == "xmlns:pp" ); fr.MoveToElement(); fr.Read(); Assert.AreEqual("pp:Order", fr.Name); } [Test] public void XmlFirstLowerWriter() { string xml = "<Customer Id=\"1\" pp:Id=\"aba\" xmlns=\"urn-kzu\" xmlns:pp=\"urn-pepenamespace\"><pp:Order /><Order Id=\"1\">chocolates</Order></Customer>"; XmlTextReader tr = new XmlTextReader(new StringReader(xml)); StringWriter sw = new StringWriter(); XmlFirstLowerWriter fw = new XmlFirstLowerWriter(sw); fw.WriteNode(tr, true); fw.Flush(); Assert.AreEqual(xml.ToLower(), sw.ToString()); } [Test] public void Deserialization() { XmlFirstUpperReader fu = new XmlFirstUpperReader(Globals.GetResource( this.GetType().Namespace + ".Customer.xml")); XmlReaderSettings settings = new XmlReaderSettings(); settings.ValidationType = ValidationType.Schema; settings.Schemas.Add(XmlSchema.Read(Globals.GetResource( this.GetType().Namespace + ".Customer.xsd"), null)); XmlReader vr = XmlReader.Create(fu, settings); XmlSerializer ser = new XmlSerializer(typeof(Customer)); Customer c = (Customer) ser.Deserialize(vr); Assert.AreEqual("0736", c.Id); Assert.AreEqual("Daniel Cazzulino", c.Name); Assert.AreEqual(25, c.Order.Id); } [Test] public void Serialization() { XmlFirstUpperReader fu = new XmlFirstUpperReader(Globals.GetResource( this.GetType().Namespace + ".Customer.xml")); XmlSerializer ser = new XmlSerializer(typeof(Customer)); Customer c = (Customer) ser.Deserialize(fu); StringWriter sw = new StringWriter(); XmlFirstLowerWriter fl = new XmlFirstLowerWriter(sw); ser.Serialize(fl, c); Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-16\"?><customer xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" id=\"0736\" xmlns=\"mvp-xml-customer\"><name>Daniel Cazzulino</name><order id=\"25\" /></customer>", sw.ToString()); } } } |