예제 #1
0
        public void TestXml()
        {
            xmlProcessorSvc = iocContainer.Resolve<IXmlProcessorSvc>();
            xmlProcessorSvc.LoadXsdSchema(new XsdDescriptor("BerwickHeights.Platform.Core.Test", "BerwickHeights.Platform.Core.Test.Test.xsd"));
            xmlProcessorSvc.LoadXsdSchema(new XsdDescriptor("BerwickHeights.Platform.Core.Test", "BerwickHeights.Platform.Core.Test.XSD.Other.Test2.xsd"));

            TestDataType data = new TestDataType() { Data1 = "data1", Data2 = "data2", Data3 = new TestDataType2() { Data21="data21", Data22 = "data22"} };
            string xml = xmlProcessorSvc.Serialize(data);
            ValidationResult result = xmlProcessorSvc.Validate(xml);
            Assert.IsTrue(result.IsValid);
            TestDataType data2 = xmlProcessorSvc.Deserialize<TestDataType>(xml);
            Assert.AreEqual(data.Data1, data2.Data1);
            Assert.AreEqual(data.Data2, data2.Data2);
            Assert.AreEqual(data.Data3.Data21, data2.Data3.Data21);
            Assert.AreEqual(data.Data3.Data22, data2.Data3.Data22);
            Assert.AreEqual(data.Data4, data2.Data4);

            // Test validating xsd:any
            result = xmlProcessorSvc.Validate("<?xml version=\"1.0\"?><TestData xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" Data4=\"data3\" xmlns=\"http://xsd.berwickheights.com/Test\"><Data1>data1</Data1><Data2>data2</Data2><AnyData><xyx>foo</xyx></AnyData></TestData>");
            Assert.IsTrue(result.IsValid);

            // Test validating bad xml input
            result = xmlProcessorSvc.Validate("<?xml version=\"1.0\"?><TestData xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" Data4=\"data3\" xmlns=\"http://xsd.berwickheights.com/Test\"><Data5>data1</Data5><Data6>data2</Data6></TestData>");
            Assert.IsFalse(result.IsValid);
        }
예제 #2
0
 public static bool LoadFromFile(string fileName, out TestDataType obj)
 {
     System.Exception exception = null;
     return LoadFromFile(fileName, out obj, out exception);
 }
예제 #3
0
 public static bool Deserialize(string xml, out TestDataType obj)
 {
     System.Exception exception = null;
     return Deserialize(xml, out obj, out exception);
 }
예제 #4
0
 /// <summary>
 /// Deserializes xml markup from file into an TestDataType object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output TestDataType object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, out TestDataType obj, out System.Exception exception)
 {
     exception = null;
     obj = default(TestDataType);
     try
     {
         obj = LoadFromFile(fileName);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }
예제 #5
0
 /// <summary>
 /// Deserializes workflow markup into an TestDataType object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output TestDataType object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out TestDataType obj, out System.Exception exception)
 {
     exception = null;
     obj = default(TestDataType);
     try
     {
         obj = Deserialize(xml);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }