2 // ComplexDataStructure.cs
\r
5 // Lluis Sanchez Gual (lluis@ximian.com)
\r
7 // (C) 2004 Novell, Inc.
\r
13 using System.Xml.Schema;
\r
14 using System.Xml.Serialization;
\r
15 using System.Collections;
\r
16 using System.ComponentModel;
\r
17 using NUnit.Framework;
\r
19 namespace MonoTests.System.XmlSerialization
\r
22 public class ComplexDataStructure: Assertion
\r
25 public void TestWriteLiteral ()
\r
27 Test data = BuildTestObject ();
\r
29 XmlSerializer ss = new XmlSerializer (GetLiteralTypeMapping ());
\r
30 XmlSerializerNamespaces nams = new XmlSerializerNamespaces ();
\r
31 StringWriter sw = new StringWriter();
\r
32 ss.Serialize (sw,data,nams);
\r
33 string serialized = sw.ToString ();
\r
34 serialized = XmlSerializerTests.Infoset (serialized);
\r
36 StreamReader sr = new StreamReader ("Test/XmlFiles/literal-data.xml");
\r
37 string expected = sr.ReadToEnd ();
\r
40 expected = XmlSerializerTests.Infoset (expected);
\r
41 AssertEquals (expected, serialized);
\r
44 public void TestReadLiteral ()
\r
46 XmlSerializer ss = new XmlSerializer (GetLiteralTypeMapping ());
\r
47 XmlSerializerNamespaces nams = new XmlSerializerNamespaces ();
\r
49 StreamReader sr = new StreamReader ("Test/XmlFiles/literal-data.xml");
\r
50 Test data = (Test) ss.Deserialize (sr);
\r
53 CheckObjectContent (BuildTestObject(), data);
\r
56 XmlTypeMapping GetLiteralTypeMapping ()
\r
58 XmlRootAttribute root = new XmlRootAttribute("rootroot");
\r
59 Type[] types = new Type[] {typeof(UknTestPart), typeof(AnotherTestPart), typeof(DblStringContainer) };
\r
60 XmlReflectionImporter ri = new XmlReflectionImporter ();
\r
61 foreach (Type t in types) ri.IncludeType (t);
\r
62 return ri.ImportTypeMapping (typeof(Test), root);
\r
65 XmlTypeMapping GetEncodedTypeMapping ()
\r
67 SoapReflectionImporter sri = new SoapReflectionImporter ();
\r
68 sri.IncludeType (typeof(UknTestPart));
\r
69 sri.IncludeType (typeof(AnotherTestPart));
\r
70 sri.IncludeType (typeof(DblStringContainer));
\r
71 return sri.ImportTypeMapping (typeof(Test));
\r
74 Test BuildTestObject ()
\r
76 XmlDocument doc = new XmlDocument();
\r
78 Test t = new UknTestPart();
\r
83 t.parts = new TestPart[3];
\r
84 t.parts[0] = new TestPart();
\r
85 t.parts[0].name = "un";
\r
86 t.parts[0].bval = true;
\r
87 t.parts[1] = new TestPart();
\r
88 t.parts[1].name = "dos";
\r
89 t.parts[1].bval = false;
\r
90 t.parts[2] = t.parts[0];
\r
91 t.part = t.parts[1];
\r
92 t.strings = new string[] { "un", "dos", null, "tres" };
\r
93 t.ushorts = new ushort[] { 1,2,3 };
\r
95 t.ta.extraTextNodes = new XmlNode[] { doc.CreateTextNode ("AA"), doc.CreateTextNode ("BB") };
\r
97 t.tam2 = new TA[][][]
\r
99 new TA[][] { new TA[] {new TA(), new TA()}, new TA[] {new TA(), new TA()}},
\r
100 new TA[][] { new TA[] {new TB(), new TA()}, new TA[] {new TB(), new TA()}},
\r
101 new TA[][] { new TA[] {new TA(), new TB()}, new TA[] {new TA(), new TA()}}
\r
105 t.flatParts = t.parts;
\r
107 t.flatParts2 = new TA[] {new TA(), new TB(), null, new TB()};
\r
109 t.anot = new AnotherTestPart ();
\r
110 ((AnotherTestPart)t.anot).lo = 1234567890;
\r
113 t.ob2 = t.parts[1];
\r
115 XmlElement e1 = doc.CreateElement ("explicitElement");
\r
116 XmlElement e2 = doc.CreateElement ("subElement");
\r
117 e2.SetAttribute ("unAtrib","val");
\r
118 doc.AppendChild (e1);
\r
119 e1.AppendChild (e2);
\r
123 t.someElems = new XmlNode[3];
\r
124 t.someElems[0] = e1;
\r
125 t.someElems[1] = null;
\r
126 t.someElems[2] = e2;
\r
128 t.extraElems = new XmlElement[1];
\r
129 t.extraElems[0] = doc.CreateElement ("extra1");
\r
130 t.extraElems[0].SetAttribute ("val","1");
\r
132 t.extraElems23 = new XmlElement[2];
\r
133 t.extraElems23[0] = doc.CreateElement ("extra2");
\r
134 t.extraElems23[0].SetAttribute ("val","2");
\r
135 t.extraElems23[1] = doc.CreateElement ("extra3");
\r
136 t.extraElems23[1].SetAttribute ("val","3");
\r
138 t.extraElemsRest = doc.CreateElement ("extra4");
\r
139 t.extraElemsRest.SetAttribute ("val","4");
\r
141 t.uktester = new UnknownAttributeTester();
\r
142 t.uktester.aa = "hihi";
\r
144 t.uktester.extraAtts = new XmlAttribute[3];
\r
145 t.uktester.extraAtts[0] = doc.CreateAttribute ("extraAtt1");
\r
146 t.uktester.extraAtts[0].Value = "val1";
\r
147 t.uktester.extraAtts[1] = doc.CreateAttribute ("extraAtt2");
\r
148 t.uktester.extraAtts[1].Value = "val2";
\r
149 t.uktester.extraAtts[2] = doc.CreateAttribute ("extraAtt3");
\r
150 t.uktester.extraAtts[2].Value = "val3";
\r
153 t.ob4 = (float)54321.12;
\r
156 t.opArray = new option[] { option.CC, option.BB, option.AA };
\r
157 t.ukOpt = option.DD;
\r
158 t.opAtt = option.BB;
\r
160 t.byteArray = new byte[] { 11,33,55,222 };
\r
161 t.byteByteArray = new byte[][] { t.byteArray, t.byteArray };
\r
163 t.ttList = new ArrayList();
\r
164 t.ttList.Add ("two");
\r
165 t.ttList.Add ("strings");
\r
166 // t.extraText = "Additional text";
\r
168 t.RoList = new ArrayList ();
\r
169 t.RoList.Add (t.parts[0]);
\r
170 t.RoList.Add (t.parts[1]);
\r
172 /* t.struc = new OneStruct();
\r
173 t.struc.aa = 776655;
\r
174 t.struc.cc = "this is a struct";
\r
176 t.multiList = new ArrayList[2];
\r
177 t.multiList[0] = new ArrayList ();
\r
178 t.multiList[0].Add (22);
\r
179 t.multiList[0].Add (33);
\r
180 t.multiList[1] = new ArrayList ();
\r
181 t.multiList[1].Add (888);
\r
182 t.multiList[1].Add (999);
\r
185 t.defElem = "theDefValue";
\r
186 t.defAttr = "theDefValue";
\r
188 t.special = new CustomHashtable ();
\r
189 t.special.Add ("one","1");
\r
190 t.special.Add ("two","2");
\r
191 t.special.Add ("three","3");
\r
193 t.attqname = new XmlQualifiedName ("thename","thenamespace");
\r
195 DblStringContainer dbc = new DblStringContainer ();
\r
196 dbc.doublestring = new string [][] { null, new string[] {"hello"} };
\r
197 AnotherTestPart at = new AnotherTestPart ();
\r
201 DblStringContainerAnm dbca = new DblStringContainerAnm ();
\r
203 t.dbscontainer = dbca;
\r
208 void CheckObjectContent (Test exp, Test t)
\r
210 AssertEquals ("t.a", exp.a, t.a);
\r
211 AssertEquals ("t.b", exp.b, t.b);
\r
212 AssertEquals ("t.bbis", exp.bbis, t.bbis);
\r
213 AssertEquals ("t.c", exp.c, t.c);
\r
215 AssertNotNull ("t.parts", t.parts);
\r
216 CheckParts ("t.parts", exp.parts, t.parts);
\r
218 TestPart.AssertEquals ("t.part", exp.part, t.part);
\r
220 AssertionHelper.AssertEqualsArray ("t.strings", exp.strings, t.strings);
\r
221 AssertionHelper.AssertEqualsArray ("t.ushorts", exp.ushorts, t.ushorts);
\r
223 TA.AssertEquals ("t.ta", exp.ta, t.ta);
\r
225 AssertNotNull ("t.tam2", t.tam2);
\r
226 CheckTaArray ("t.tam2", exp.tam2, t.tam2);
\r
228 AssertNotNull ("t.tam3", t.tam3);
\r
229 CheckTaArray ("t.tam3", exp.tam3, t.tam3);
\r
231 AssertNotNull ("t.flatParts", t.flatParts);
\r
232 CheckParts ("t.flatParts", exp.flatParts, t.flatParts);
\r
234 // Null element is ignored
\r
235 AssertNotNull ("t.flatParts2", t.flatParts2);
\r
236 AssertEquals ("t.flatParts2.Length", 3, t.flatParts2.Length);
\r
237 TA.AssertEquals ("t.flatParts2 0", exp.flatParts2[0], t.flatParts2[0]);
\r
238 TA.AssertEquals ("t.flatParts2 1", exp.flatParts2[1], t.flatParts2[1]);
\r
239 TA.AssertEquals ("t.flatParts2 2", exp.flatParts2[3], t.flatParts2[2]);
\r
241 AssertNotNull ("t.anot", t.anot);
\r
242 AssertEquals ("t.anot.lo", ((AnotherTestPart)exp.anot).lo, ((AnotherTestPart)t.anot).lo);
\r
244 TestPart.AssertEquals ("t.ob", exp.ob as TestPart, t.ob as TestPart);
\r
245 TestPart.AssertEquals ("t.ob2", exp.ob2 as TestPart, t.ob2 as TestPart);
\r
247 AssertionHelper.AssertEqualsXml ("t.oneElem", exp.oneElem, t.oneElem);
\r
248 AssertionHelper.AssertEqualsXml ("t.oneElem2", exp.oneElem2, t.oneElem2);
\r
250 // One of the elements was null and it is ignored
\r
251 AssertNotNull ("t.someElems", t.someElems);
\r
252 AssertEquals ("t.someElems.Length", 2, t.someElems.Length);
\r
253 AssertionHelper.AssertEqualsXml ("t.someElems[0]", exp.someElems[0], t.someElems[0]);
\r
254 AssertionHelper.AssertEqualsXml ("t.someElems[1]", exp.someElems[2], t.someElems[1]);
\r
256 AssertNotNull ("t.extraElems", t.extraElems);
\r
257 AssertEquals ("t.extraElems.Length", exp.extraElems.Length, t.extraElems.Length);
\r
258 for (int n=0; n<exp.extraElems.Length; n++)
\r
259 AssertionHelper.AssertEqualsXml ("t.extraElems[" + n + "]", exp.extraElems[n], t.extraElems[n]);
\r
261 AssertNotNull ("t.extraElems23", t.extraElems23);
\r
262 AssertEquals ("t.extraElems23.Length", exp.extraElems23.Length, t.extraElems23.Length);
\r
263 for (int n=0; n<t.extraElems23.Length; n++)
\r
264 AssertionHelper.AssertEqualsXml ("t.extraElems23[" + n + "]", exp.extraElems23[n], t.extraElems23[n]);
\r
266 AssertionHelper.AssertEqualsXml ("t.extraElemsRest", exp.extraElemsRest, t.extraElemsRest);
\r
268 UnknownAttributeTester.AssertEquals ("t.uktester", exp.uktester, t.uktester);
\r
270 AssertEquals ("t.ob3", exp.ob3, t.ob3);
\r
271 AssertEquals ("t.ob4", exp.ob4, t.ob4);
\r
272 AssertEquals ("t.op1", exp.op1, t.op1);
\r
274 AssertionHelper.AssertEqualsArray ("t.opArray", exp.opArray, t.opArray);
\r
276 AssertEquals ("t.ukOpt", exp.ukOpt, t.ukOpt);
\r
277 AssertEquals ("t.opAtt", exp.opAtt, t.opAtt);
\r
279 AssertionHelper.AssertEqualsArray ("t.byteArray", exp.byteArray, t.byteArray);
\r
280 AssertionHelper.AssertEqualsArray ("t.byteByteArray", exp.byteByteArray, t.byteByteArray);
\r
282 AssertNotNull ("t.ttList", t.ttList);
\r
283 AssertionHelper.AssertEqualsArray ("t.ttList", exp.ttList.ToArray(), t.ttList.ToArray());
\r
285 AssertNotNull ("t.RoList", t.RoList);
\r
286 AssertEquals ("t.RoList.Count", exp.RoList.Count, t.RoList.Count);
\r
287 for (int n=0; n<exp.RoList.Count; n++)
\r
288 TestPart.AssertEquals ("t.RoList " + n, (TestPart)exp.RoList[n], (TestPart)t.RoList[n]);
\r
290 AssertEquals ("t.struc.aa", exp.struc.aa, t.struc.aa);
\r
291 AssertEquals ("t.struc.cc", exp.struc.cc, t.struc.cc);
\r
293 AssertNotNull ("t.multiList", t.multiList);
\r
294 AssertEquals ("t.multiList.Count", exp.multiList.Length, t.multiList.Length);
\r
295 for (int n=0; n<exp.multiList.Length; n++)
\r
296 AssertionHelper.AssertEqualsArray ("t.multiList " + n, exp.multiList[n].ToArray(), t.multiList[n].ToArray());
\r
298 AssertEquals ("t.defElem", exp.defElem, t.defElem);
\r
299 AssertEquals ("t.defAttr", exp.defAttr, t.defAttr);
\r
301 CustomHashtable.AssertEquals ("t.special", exp.special, t.special);
\r
303 AssertEquals ("t.attqname", exp.attqname, t.attqname);
\r
305 AssertNotNull ("t.dbscontainer", t.dbscontainer);
\r
306 DblStringContainer tdbca = t.dbscontainer.at as DblStringContainer;
\r
307 DblStringContainer expdbca = exp.dbscontainer.at as DblStringContainer;
\r
308 AssertNotNull ("t.dbscontainer.at", tdbca);
\r
310 AssertNotNull ("t.dbscontainer.dbca", tdbca);
\r
311 AssertionHelper.AssertEqualsArray ("t.dbscontainer.at.doublestring", expdbca.doublestring, tdbca.doublestring);
\r
313 AnotherTestPart tat = tdbca.at as AnotherTestPart;
\r
314 AnotherTestPart expat = expdbca.at as AnotherTestPart;
\r
315 AssertNotNull ("t.dbscontainer.dbca.at", tat);
\r
316 AssertEquals ("t.dbscontainer.dbca.at.lo", expat.lo, tat.lo);
\r
319 void CheckParts (string id, TestPart[] exp, TestPart[] parts)
\r
321 AssertionHelper.AssertType (id, exp, parts);
\r
322 AssertEquals (id + " Len", exp.Length, parts.Length);
\r
323 for (int n=0; n<exp.Length; n++)
\r
324 TestPart.AssertEquals (id + "[" + n + "]", exp[n], parts[n]);
\r
327 void CheckTaArray (string id, TA[][][] exp, TA[][][] arr)
\r
329 AssertionHelper.AssertType (id, exp, arr);
\r
330 AssertEquals (id + " Len", exp.Length, arr.Length);
\r
331 for (int n=0; n<exp.Length; n++)
\r
333 TA[][] tar = arr[n];
\r
334 TA[][] expar = exp[n];
\r
336 AssertionHelper.AssertType (id, expar, tar);
\r
337 AssertEquals (expar.Length, tar.Length);
\r
339 for (int m=0; m<expar.Length; m++)
\r
341 TA[] tar2 = tar[m];
\r
342 TA[] expar2 = expar[m];
\r
344 AssertionHelper.AssertType (id, expar2, tar2);
\r
345 AssertEquals (id, expar2.Length, tar2.Length);
\r
347 for (int i=0; i<expar2.Length; i++)
\r
348 TA.AssertEquals (id + "[" + n + "][" + m + "][" + i + "]", expar2[i], tar2[i]);
\r
354 public class AssertionHelper
\r
356 public static bool AssertType (string id, object exp, object ob)
\r
359 Assertion.AssertNull (id, ob);
\r
363 Assertion.AssertNotNull (id, ob);
\r
364 Assertion.AssertEquals (id + " type", exp.GetType(), ob.GetType());
\r
369 public static void AssertEqualsXml (string id, XmlNode exp, XmlNode ob)
\r
371 if (!AssertType (id, exp, ob)) return;
\r
372 Assertion.AssertEquals (id, XmlSerializerTests.Infoset (exp), XmlSerializerTests.Infoset (ob));
\r
375 public static void AssertEqualsArray (string id, Array exp, Array ob)
\r
377 if (!AssertType (id, exp, ob)) return;
\r
378 Assertion.AssertEquals (id + " Length", exp.GetLength(0), ob.GetLength(0));
\r
379 for (int n=0; n<exp.GetLength(0); n++) {
\r
380 object it = exp.GetValue(n);
\r
382 AssertEqualsArray (id + "[" + n + "]", it as Array, ob.GetValue(n) as Array);
\r
384 Assertion.AssertEquals (id + "[" + n + "]", it, ob.GetValue(n));
\r
389 [XmlType(TypeName="")]
\r
390 [XmlRoot(ElementName="aaaaaa",Namespace="")]
\r
391 [XmlInclude(typeof(UknTestPart))]
\r
392 [SoapInclude(typeof(UknTestPart))]
\r
395 // public option op;elem.SchemaTypeName
\r
396 public object anot;
\r
398 [SoapElement(ElementName="suba")]
\r
399 [XmlElement(ElementName="suba",Namespace="kk")]
\r
403 public string bbis;
\r
406 [XmlAttribute (Namespace="attribns")]
\r
409 [XmlElement(Namespace="oo")]
\r
410 public TestPart part;
\r
414 public TestPart[] parts;
\r
416 [SoapElement(ElementName="multita")]
\r
417 [XmlArray(ElementName="multita")]
\r
418 // [XmlArrayItem(ElementName="itema",NestingLevel=1)]
\r
419 [XmlArrayItem(ElementName="itema",Type=typeof(TA),NestingLevel=1)]
\r
420 [XmlArrayItem(ElementName="itemb",Type=typeof(TB),NestingLevel=1)]
\r
421 public TA[][] tam = new TA[][] { new TA[] {new TA(), new TB()}, new TA[] {new TA(), new TA()}};
\r
423 // [SoapElement(ElementName="multita2")]
\r
425 [XmlArray(ElementName="multita2")]
\r
426 [XmlArrayItem(ElementName="data1",NestingLevel=0)]
\r
428 [XmlArrayItem(ElementName="data2",NestingLevel=1,Namespace="da2")]
\r
429 [XmlArrayItem(ElementName="data3a",Type=typeof(TA),NestingLevel=2,Namespace="da3")]
\r
430 [XmlArrayItem(ElementName="data3b",Type=typeof(TB),NestingLevel=2,Namespace="da3")]
\r
431 public TA[][][] tam2;
\r
434 public TA[][][] tam3;
\r
436 [SoapElement(IsNullable=true)]
\r
437 [XmlElement(IsNullable=true)]
\r
438 public string mayBeNull;
\r
440 public string[] strings;
\r
442 [XmlArray(Namespace="arrayNamespace")]
\r
443 public ushort[] ushorts;
\r
446 public TestPart[] flatParts;
\r
448 [SoapElement (ElementName="flatTAs")]
\r
449 [XmlElement (ElementName="flatTAs")]
\r
450 public TA[] flatParts2;
\r
454 [XmlElement (Namespace="uimp")]
\r
461 public XmlElement oneElem;
\r
464 [XmlElement (ElementName="unElement", Namespace="elemns")]
\r
465 public XmlElement oneElem2;
\r
468 [XmlElement (ElementName="unsElements", Namespace="elemns")]
\r
469 public XmlNode[] someElems;
\r
472 [XmlAnyElement ("extra1")]
\r
473 public XmlElement[] extraElems;
\r
476 [XmlAnyElement ("extra2")]
\r
477 [XmlAnyElement ("extra3")]
\r
478 [XmlAnyElement ("extra3","nnn")]
\r
479 public XmlElement[] extraElems23;
\r
483 public XmlElement extraElemsRest;
\r
485 public UnknownAttributeTester uktester;
\r
488 public option[] opArray;
\r
489 public object ukOpt;
\r
493 public option opAtt;
\r
496 public byte[] byteArray;
\r
498 public byte[][] byteByteArray;
\r
500 [XmlElement(Type=typeof(string))]
\r
501 [XmlElement(ElementName="kk",Type=typeof(int))]
\r
502 public object[] tt = new object[] { "aa",22 };
\r
504 public ArrayList ttList;
\r
507 public ArrayList RoList
\r
509 get { return roList; }
\r
510 set { roList = value; }
\r
515 public ArrayList[] multiList;
\r
519 public OneStruct struc;
\r
521 [DefaultValue("theDefValue")]
\r
522 public string defElem;
\r
525 [DefaultValue("theDefValue")]
\r
526 public string defAttr;
\r
528 [XmlText (Type=typeof(string))]
\r
529 [XmlElement (Type=typeof(int))]
\r
530 public object[] xmltext = new object[] {"aa",33,"bb",776};
\r
533 public CustomHashtable special;
\r
536 public XmlQualifiedName attqname;
\r
539 public DateTime[] arrayAttribute;
\r
541 [XmlArray (Namespace="mm")]
\r
542 public string[][] dummyStringArray = new string[][] {null,null};
\r
544 [XmlElement (Namespace="mm")]
\r
545 public DblStringContainerAnm dbscontainer;
\r
548 public class DblStringContainerAnm
\r
553 [XmlType(Namespace="mm")]
\r
554 public class DblStringContainer
\r
556 [XmlArrayItem (NestingLevel=1)]
\r
557 public string [][] doublestring;
\r
561 [SoapType(TypeName="TC")]
\r
562 [XmlType(TypeName="TC")]
\r
563 [XmlInclude(typeof(TB))]
\r
564 [SoapInclude(typeof(TB))]
\r
571 public XmlNode[] extraTextNodes;
\r
573 public static void AssertEquals (string id, TA expected, TA ob)
\r
575 if (!AssertionHelper.AssertType (id, expected, ob)) return;
\r
576 Assertion.AssertEquals (id + " xx", expected.xx, ob.xx);
\r
577 // TODO: extraTextNodes
\r
581 public class TB: TA
\r
585 public static void AssertEquals (string id, TB expected, TB ob)
\r
587 if (!AssertionHelper.AssertType (id, expected, ob)) return;
\r
588 Assertion.AssertEquals (id + " yy", expected.yy, ob.yy);
\r
589 TA.AssertEquals (id + " base", expected, ob);
\r
593 public class UnknownAttributeTester
\r
602 public XmlAttribute[] extraAtts;
\r
604 // [XmlText(Type=typeof(XmlNode))]
\r
605 // public XmlNode extraText;
\r
607 public static void AssertEquals (string id, UnknownAttributeTester exp, UnknownAttributeTester ob)
\r
609 if (!AssertionHelper.AssertType (id, exp, ob)) return;
\r
610 Assertion.AssertEquals (id + " aa", exp.aa, ob.aa);
\r
612 if (!AssertionHelper.AssertType (id + " extraAtts", exp.extraAtts, ob.extraAtts)) return;
\r
615 for (int n=0; n<ob.extraAtts.Length; n++)
\r
617 XmlAttribute at = ob.extraAtts [n];
\r
618 if (at.NamespaceURI == "http://www.w3.org/2000/xmlns/") continue;
\r
619 Assertion.Assert (id + " extraAtts length", p < exp.extraAtts.Length);
\r
620 AssertionHelper.AssertEqualsXml (id + ".extraAtts " + n, exp.extraAtts [p], ob.extraAtts[n]);
\r
626 [SoapType(TypeName="UnTestPart", Namespace="mm")]
\r
627 [XmlType(TypeName="UnTestPart", Namespace="mm")]
\r
628 public class TestPart
\r
630 public string name;
\r
633 public static void AssertEquals (string id, TestPart expected, TestPart ob)
\r
635 if (!AssertionHelper.AssertType (id, expected, ob)) return;
\r
636 Assertion.AssertEquals (id + " name", expected.name, ob.name);
\r
637 Assertion.AssertEquals (id + " bval", expected.bval, ob.bval);
\r
641 [SoapType(Namespace="mm")]
\r
642 [XmlType(Namespace="mm")]
\r
643 public class AnotherTestPart
\r
649 public class UknTestPart : Test
\r
651 [XmlElement(IsNullable=true)]
\r
652 public string uname;
\r
656 public struct OneStruct
\r
662 // [XmlType(Namespace="enum_namespace")]
\r
663 public enum option
\r
666 [SoapEnum(Name="xmlBB")]
\r
667 [XmlEnum(Name="xmlBB")]
\r
673 public class CustomHashtable : IXmlSerializable
\r
675 Hashtable data = new Hashtable ();
\r
677 public void Add (string key, string value)
\r
679 data.Add (key, value);
\r
682 public static void AssertEquals (string id, CustomHashtable exp, CustomHashtable ob)
\r
684 if (!AssertionHelper.AssertType (id, exp, ob)) return;
\r
685 if (!AssertionHelper.AssertType (id, exp.data, ob.data)) return;
\r
687 Assertion.AssertEquals (id + " data Count", exp.data.Count, ob.data.Count);
\r
689 foreach (DictionaryEntry entry in exp.data)
\r
690 Assertion.AssertEquals (entry.Value, ob.data[entry.Key]);
\r
693 public void ReadXml (XmlReader reader)
\r
695 // Read the element enclosing the object
\r
696 reader.ReadStartElement();
\r
697 reader.MoveToContent ();
\r
699 // Reads the "data" element
\r
700 reader.ReadStartElement();
\r
701 reader.MoveToContent ();
\r
702 while (reader.NodeType != XmlNodeType.EndElement)
\r
704 if (reader.NodeType == XmlNodeType.Element)
\r
706 string key = reader.LocalName;
\r
707 data [key] = reader.ReadElementString ();
\r
711 reader.MoveToContent ();
\r
714 reader.ReadEndElement ();
\r
717 public void WriteXml (XmlWriter writer)
\r
719 writer.WriteStartElement ("data");
\r
720 foreach (DictionaryEntry entry in data)
\r
722 writer.WriteElementString ((string)entry.Key, (string)entry.Value);
\r
724 writer.WriteEndElement ();
\r
727 public XmlSchema GetSchema ()
\r
729 XmlSchema s = new XmlSchema ();
\r
730 s.TargetNamespace = "http://www.go-mono.org/schemas";
\r
731 s.Id = "monoschema";
\r
732 XmlSchemaElement e = new XmlSchemaElement ();
\r
735 XmlSchemaComplexType cs = new XmlSchemaComplexType ();
\r
736 XmlSchemaSequence seq = new XmlSchemaSequence ();
\r
737 XmlSchemaAny any = new XmlSchemaAny ();
\r
739 any.MaxOccurs = decimal.MaxValue;
\r
740 seq.Items.Add (any);
\r