XmlSchemaExporterTests.cs 103 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396
  1. //
  2. // System.Xml.Serialization.XmlSchemaExporterTests
  3. //
  4. // Author:
  5. // Gert Driesen ([email protected])
  6. //
  7. // (C) 2005 Novell
  8. //
  9. using System;
  10. using System.Collections;
  11. using System.Globalization;
  12. using System.IO;
  13. using System.Xml;
  14. using System.Xml.Schema;
  15. using System.Xml.Serialization;
  16. using NUnit.Framework;
  17. using MonoTests.System.Xml.TestClasses;
  18. namespace MonoTests.System.XmlSerialization
  19. {
  20. [TestFixture]
  21. public class XmlSchemaExporterTests
  22. {
  23. private XmlSchemas Export (Type type)
  24. {
  25. return Export (type, string.Empty);
  26. }
  27. private XmlSchemas Export (Type type, string defaultNamespace)
  28. {
  29. XmlReflectionImporter ri = new XmlReflectionImporter (defaultNamespace);
  30. XmlSchemas schemas = new XmlSchemas ();
  31. XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
  32. XmlTypeMapping tm = ri.ImportTypeMapping (type);
  33. sx.ExportTypeMapping (tm);
  34. return schemas;
  35. }
  36. private XmlSchemas Export (Type type, XmlAttributeOverrides overrides)
  37. {
  38. return Export (type, overrides, string.Empty);
  39. }
  40. private XmlSchemas Export (Type type, XmlAttributeOverrides overrides, string defaultNamespace)
  41. {
  42. XmlReflectionImporter ri = new XmlReflectionImporter (overrides, defaultNamespace);
  43. XmlSchemas schemas = new XmlSchemas ();
  44. XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
  45. XmlTypeMapping tm = ri.ImportTypeMapping (type);
  46. sx.ExportTypeMapping (tm);
  47. return schemas;
  48. }
  49. [Test]
  50. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  51. public void ExportStruct ()
  52. {
  53. XmlSchemas schemas = Export (typeof (TimeSpan), "NSTimeSpan");
  54. Assert.AreEqual (1, schemas.Count, "#1");
  55. StringWriter sw = new StringWriter ();
  56. schemas[0].Write (sw);
  57. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  58. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  59. "<xs:schema xmlns:tns=\"NSTimeSpan\" elementFormDefault=\"qualified\" targetNamespace=\"NSTimeSpan\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  60. " <xs:element name=\"TimeSpan\" type=\"tns:TimeSpan\" />{0}" +
  61. " <xs:complexType name=\"TimeSpan\" />{0}" +
  62. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  63. schemas = Export (typeof (TimeSpan));
  64. Assert.AreEqual (1, schemas.Count, "#3");
  65. sw.GetStringBuilder ().Length = 0;
  66. schemas[0].Write (sw);
  67. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  68. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  69. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  70. " <xs:element name=\"TimeSpan\" type=\"TimeSpan\" />{0}" +
  71. " <xs:complexType name=\"TimeSpan\" />{0}" +
  72. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  73. }
  74. [Test]
  75. [Category ("NotDotNet")] // Mono bug ##77117
  76. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  77. public void ExportStruct_Array ()
  78. {
  79. XmlSchemas schemas = Export (typeof (TimeSpan[]), "NSTimeSpanArray");
  80. Assert.AreEqual (1, schemas.Count, "#1");
  81. StringWriter sw = new StringWriter ();
  82. schemas[0].Write (sw);
  83. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  84. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  85. "<xs:schema xmlns:tns=\"NSTimeSpanArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSTimeSpanArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  86. " <xs:element name=\"ArrayOfTimeSpan\" type=\"tns:ArrayOfTimeSpan\" />{0}" +
  87. " <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
  88. " <xs:sequence>{0}" +
  89. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" nillable=\"true\" type=\"tns:TimeSpan\" />{0}" +
  90. " </xs:sequence>{0}" +
  91. " </xs:complexType>{0}" +
  92. " <xs:complexType name=\"TimeSpan\" />{0}" +
  93. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  94. schemas = Export (typeof (TimeSpan[]));
  95. Assert.AreEqual (1, schemas.Count, "#3");
  96. sw.GetStringBuilder ().Length = 0;
  97. schemas[0].Write (sw);
  98. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  99. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  100. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  101. " <xs:element name=\"ArrayOfTimeSpan\" type=\"ArrayOfTimeSpan\" />{0}" +
  102. " <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
  103. " <xs:sequence>{0}" +
  104. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" nillable=\"true\" type=\"TimeSpan\" />{0}" +
  105. " </xs:sequence>{0}" +
  106. " </xs:complexType>{0}" +
  107. " <xs:complexType name=\"TimeSpan\" />{0}" +
  108. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  109. }
  110. [Test]
  111. [Category ("NotDotNet")] // Mono bug ##77117
  112. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  113. public void ExportClass_SimpleClass ()
  114. {
  115. XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
  116. XmlAttributes attr = new XmlAttributes ();
  117. XmlElementAttribute element = new XmlElementAttribute ();
  118. element.ElementName = "saying";
  119. element.IsNullable = true;
  120. attr.XmlElements.Add (element);
  121. overrides.Add (typeof (SimpleClass), "something", attr);
  122. XmlSchemas schemas = Export (typeof (SimpleClass), overrides, "NSSimpleClass");
  123. Assert.AreEqual (1, schemas.Count, "#1");
  124. StringWriter sw = new StringWriter ();
  125. schemas[0].Write (sw);
  126. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  127. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  128. "<xs:schema xmlns:tns=\"NSSimpleClass\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClass\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  129. " <xs:element name=\"SimpleClass\" type=\"tns:SimpleClass\" />{0}" +
  130. " <xs:complexType name=\"SimpleClass\">{0}" +
  131. " <xs:sequence>{0}" +
  132. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
  133. " </xs:sequence>{0}" +
  134. " </xs:complexType>{0}" +
  135. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  136. schemas = Export (typeof (SimpleClass), overrides);
  137. Assert.AreEqual (1, schemas.Count, "#3");
  138. sw.GetStringBuilder ().Length = 0;
  139. schemas[0].Write (sw);
  140. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  141. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  142. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  143. " <xs:element name=\"SimpleClass\" type=\"SimpleClass\" />{0}" +
  144. " <xs:complexType name=\"SimpleClass\">{0}" +
  145. " <xs:sequence>{0}" +
  146. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
  147. " </xs:sequence>{0}" +
  148. " </xs:complexType>{0}" +
  149. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  150. }
  151. [Test]
  152. [Category ("NotDotNet")] // Mono bug ##77117
  153. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  154. public void ExportClass_StringCollection ()
  155. {
  156. XmlSchemas schemas = Export (typeof (StringCollection), "NSStringCollection");
  157. Assert.AreEqual (1, schemas.Count, "#1");
  158. StringWriter sw = new StringWriter ();
  159. schemas[0].Write (sw);
  160. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  161. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  162. "<xs:schema xmlns:tns=\"NSStringCollection\" elementFormDefault=\"qualified\" targetNamespace=\"NSStringCollection\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  163. " <xs:element name=\"ArrayOfString\" type=\"tns:ArrayOfString\" />{0}" +
  164. " <xs:complexType name=\"ArrayOfString\">{0}" +
  165. " <xs:sequence>{0}" +
  166. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
  167. " </xs:sequence>{0}" +
  168. " </xs:complexType>{0}" +
  169. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  170. schemas = Export (typeof (StringCollection));
  171. Assert.AreEqual (1, schemas.Count, "#3");
  172. sw.GetStringBuilder ().Length = 0;
  173. schemas[0].Write (sw);
  174. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  175. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  176. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  177. " <xs:element name=\"ArrayOfString\" type=\"ArrayOfString\" />{0}" +
  178. " <xs:complexType name=\"ArrayOfString\">{0}" +
  179. " <xs:sequence>{0}" +
  180. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
  181. " </xs:sequence>{0}" +
  182. " </xs:complexType>{0}" +
  183. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  184. }
  185. [Test]
  186. [Category ("NotDotNet")] // Mono bug ##77117
  187. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  188. public void ExportClass_StringCollectionContainer ()
  189. {
  190. XmlSchemas schemas = Export (typeof (StringCollectionContainer), "NSStringCollectionContainer");
  191. Assert.AreEqual (1, schemas.Count, "#1");
  192. StringWriter sw = new StringWriter ();
  193. schemas[0].Write (sw);
  194. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  195. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  196. "<xs:schema xmlns:tns=\"NSStringCollectionContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSStringCollectionContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  197. " <xs:element name=\"StringCollectionContainer\" type=\"tns:StringCollectionContainer\" />{0}" +
  198. " <xs:complexType name=\"StringCollectionContainer\">{0}" +
  199. " <xs:sequence>{0}" +
  200. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Messages\" type=\"tns:ArrayOfString\" />{0}" +
  201. " </xs:sequence>{0}" +
  202. " </xs:complexType>{0}" +
  203. " <xs:complexType name=\"ArrayOfString\">{0}" +
  204. " <xs:sequence>{0}" +
  205. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
  206. " </xs:sequence>{0}" +
  207. " </xs:complexType>{0}" +
  208. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  209. schemas = Export (typeof (StringCollectionContainer));
  210. Assert.AreEqual (1, schemas.Count, "#3");
  211. sw.GetStringBuilder ().Length = 0;
  212. schemas[0].Write (sw);
  213. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  214. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  215. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  216. " <xs:element name=\"StringCollectionContainer\" type=\"StringCollectionContainer\" />{0}" +
  217. " <xs:complexType name=\"StringCollectionContainer\">{0}" +
  218. " <xs:sequence>{0}" +
  219. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Messages\" type=\"ArrayOfString\" />{0}" +
  220. " </xs:sequence>{0}" +
  221. " </xs:complexType>{0}" +
  222. " <xs:complexType name=\"ArrayOfString\">{0}" +
  223. " <xs:sequence>{0}" +
  224. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
  225. " </xs:sequence>{0}" +
  226. " </xs:complexType>{0}" +
  227. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  228. }
  229. [Test]
  230. [Category ("NotDotNet")] // Mono bug ##77117
  231. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  232. public void ExportClass_ArrayContainer ()
  233. {
  234. XmlSchemas schemas = Export (typeof (ArrayContainer), "NSArrayContainer");
  235. Assert.AreEqual (1, schemas.Count, "#1");
  236. StringWriter sw = new StringWriter ();
  237. schemas[0].Write (sw);
  238. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  239. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  240. "<xs:schema xmlns:tns=\"NSArrayContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  241. " <xs:element name=\"ArrayContainer\" type=\"tns:ArrayContainer\" />{0}" +
  242. " <xs:complexType name=\"ArrayContainer\">{0}" +
  243. " <xs:sequence>{0}" +
  244. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"tns:ArrayOfAnyType\" />{0}" +
  245. " </xs:sequence>{0}" +
  246. " </xs:complexType>{0}" +
  247. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  248. " <xs:sequence>{0}" +
  249. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
  250. " </xs:sequence>{0}" +
  251. " </xs:complexType>{0}" +
  252. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  253. schemas = Export (typeof (ArrayContainer));
  254. Assert.AreEqual (1, schemas.Count, "#3");
  255. sw.GetStringBuilder ().Length = 0;
  256. schemas[0].Write (sw);
  257. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  258. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  259. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  260. " <xs:element name=\"ArrayContainer\" type=\"ArrayContainer\" />{0}" +
  261. " <xs:complexType name=\"ArrayContainer\">{0}" +
  262. " <xs:sequence>{0}" +
  263. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"ArrayOfAnyType\" />{0}" +
  264. " </xs:sequence>{0}" +
  265. " </xs:complexType>{0}" +
  266. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  267. " <xs:sequence>{0}" +
  268. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
  269. " </xs:sequence>{0}" +
  270. " </xs:complexType>{0}" +
  271. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  272. }
  273. [Test]
  274. [Category ("NotDotNet")] // Mono bug ##77117
  275. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  276. public void ExportClass_ClassArrayContainer ()
  277. {
  278. XmlSchemas schemas = Export (typeof (ClassArrayContainer), "NSClassArrayContainer");
  279. Assert.AreEqual (1, schemas.Count, "#1");
  280. StringWriter sw = new StringWriter ();
  281. schemas[0].Write (sw);
  282. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  283. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  284. "<xs:schema xmlns:tns=\"NSClassArrayContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSClassArrayContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  285. " <xs:element name=\"ClassArrayContainer\" type=\"tns:ClassArrayContainer\" />{0}" +
  286. " <xs:complexType name=\"ClassArrayContainer\">{0}" +
  287. " <xs:sequence>{0}" +
  288. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"tns:ArrayOfSimpleClass\" />{0}" +
  289. " </xs:sequence>{0}" +
  290. " </xs:complexType>{0}" +
  291. " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
  292. " <xs:sequence>{0}" +
  293. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"tns:SimpleClass\" />{0}" +
  294. " </xs:sequence>{0}" +
  295. " </xs:complexType>{0}" +
  296. " <xs:complexType name=\"SimpleClass\">{0}" +
  297. " <xs:sequence>{0}" +
  298. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
  299. " </xs:sequence>{0}" +
  300. " </xs:complexType>{0}" +
  301. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  302. schemas = Export (typeof (ClassArrayContainer));
  303. Assert.AreEqual (1, schemas.Count, "#3");
  304. sw.GetStringBuilder ().Length = 0;
  305. schemas[0].Write (sw);
  306. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  307. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  308. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  309. " <xs:element name=\"ClassArrayContainer\" type=\"ClassArrayContainer\" />{0}" +
  310. " <xs:complexType name=\"ClassArrayContainer\">{0}" +
  311. " <xs:sequence>{0}" +
  312. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"items\" type=\"ArrayOfSimpleClass\" />{0}" +
  313. " </xs:sequence>{0}" +
  314. " </xs:complexType>{0}" +
  315. " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
  316. " <xs:sequence>{0}" +
  317. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"SimpleClass\" />{0}" +
  318. " </xs:sequence>{0}" +
  319. " </xs:complexType>{0}" +
  320. " <xs:complexType name=\"SimpleClass\">{0}" +
  321. " <xs:sequence>{0}" +
  322. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
  323. " </xs:sequence>{0}" +
  324. " </xs:complexType>{0}" +
  325. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  326. }
  327. [Test]
  328. [Category ("NotDotNet")] // Mono bug ##77117
  329. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  330. public void ExportClass_SimpleClassWithXmlAttributes ()
  331. {
  332. XmlSchemas schemas = Export (typeof (SimpleClassWithXmlAttributes), "NSSimpleClassWithXmlAttributes");
  333. Assert.AreEqual (1, schemas.Count, "#1");
  334. StringWriter sw = new StringWriter ();
  335. schemas[0].Write (sw);
  336. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  337. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  338. "<xs:schema xmlns:tns=\"NSSimpleClassWithXmlAttributes\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClassWithXmlAttributes\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  339. " <xs:element name=\"simple\" type=\"tns:SimpleClassWithXmlAttributes\" />{0}" +
  340. " <xs:complexType name=\"SimpleClassWithXmlAttributes\">{0}" +
  341. " <xs:attribute name=\"member\" type=\"xs:string\" />{0}" +
  342. " </xs:complexType>{0}" +
  343. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  344. schemas = Export (typeof (SimpleClassWithXmlAttributes));
  345. Assert.AreEqual (1, schemas.Count, "#3");
  346. sw.GetStringBuilder ().Length = 0;
  347. schemas[0].Write (sw);
  348. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  349. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  350. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  351. " <xs:element name=\"simple\" type=\"SimpleClassWithXmlAttributes\" />{0}" +
  352. " <xs:complexType name=\"SimpleClassWithXmlAttributes\">{0}" +
  353. " <xs:attribute name=\"member\" type=\"xs:string\" />{0}" +
  354. " </xs:complexType>{0}" +
  355. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  356. }
  357. [Test]
  358. [Category ("NotDotNet")] // Mono does not translate default values to corresponding enum fields
  359. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  360. public void ExportClass_Field ()
  361. {
  362. XmlSchemas schemas = Export (typeof (Field), "NSField");
  363. Assert.AreEqual (1, schemas.Count, "#1");
  364. StringWriter sw = new StringWriter ();
  365. schemas[0].Write (sw);
  366. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  367. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  368. "<xs:schema xmlns:tns=\"NSField\" elementFormDefault=\"qualified\" targetNamespace=\"NSField\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  369. " <xs:element name=\"field\" type=\"tns:Field\" />{0}" +
  370. " <xs:complexType name=\"Field\">{0}" +
  371. " <xs:attribute name=\"modifiers\" type=\"tns:MapModifiers\" use=\"required\" />{0}" +
  372. " <xs:attribute form=\"unqualified\" name=\"modifiers2\" type=\"tns:MapModifiers\" use=\"required\" />{0}" +
  373. " <xs:attribute default=\"0\" name=\"modifiers3\" type=\"tns:MapModifiers\" />{0}" +
  374. " <xs:attribute default=\"0\" form=\"unqualified\" name=\"modifiers4\" type=\"tns:MapModifiers\" />{0}" +
  375. " <xs:attribute name=\"names\">{0}" +
  376. " <xs:simpleType>{0}" +
  377. " <xs:list itemType=\"xs:string\" />{0}" +
  378. " </xs:simpleType>{0}" +
  379. " </xs:attribute>{0}" +
  380. " <xs:attribute name=\"street\" type=\"xs:string\" />{0}" +
  381. " </xs:complexType>{0}" +
  382. " <xs:simpleType name=\"MapModifiers\">{0}" +
  383. " <xs:list>{0}" +
  384. " <xs:simpleType>{0}" +
  385. " <xs:restriction base=\"xs:string\">{0}" +
  386. " <xs:enumeration value=\"public\" />{0}" +
  387. " <xs:enumeration value=\"protected\" />{0}" +
  388. " </xs:restriction>{0}" +
  389. " </xs:simpleType>{0}" +
  390. " </xs:list>{0}" +
  391. " </xs:simpleType>{0}" +
  392. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  393. schemas = Export (typeof (Field));
  394. Assert.AreEqual (1, schemas.Count, "#3");
  395. sw.GetStringBuilder ().Length = 0;
  396. schemas[0].Write (sw);
  397. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  398. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  399. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  400. " <xs:element name=\"field\" type=\"Field\" />{0}" +
  401. " <xs:complexType name=\"Field\">{0}" +
  402. " <xs:attribute name=\"modifiers\" type=\"MapModifiers\" use=\"required\" />{0}" +
  403. " <xs:attribute form=\"unqualified\" name=\"modifiers2\" type=\"MapModifiers\" use=\"required\" />{0}" +
  404. " <xs:attribute default=\"0\" name=\"modifiers3\" type=\"MapModifiers\" />{0}" +
  405. " <xs:attribute default=\"0\" form=\"unqualified\" name=\"modifiers4\" type=\"MapModifiers\" />{0}" +
  406. " <xs:attribute name=\"names\">{0}" +
  407. " <xs:simpleType>{0}" +
  408. " <xs:list itemType=\"xs:string\" />{0}" +
  409. " </xs:simpleType>{0}" +
  410. " </xs:attribute>{0}" +
  411. " <xs:attribute name=\"street\" type=\"xs:string\" />{0}" +
  412. " </xs:complexType>{0}" +
  413. " <xs:simpleType name=\"MapModifiers\">{0}" +
  414. " <xs:list>{0}" +
  415. " <xs:simpleType>{0}" +
  416. " <xs:restriction base=\"xs:string\">{0}" +
  417. " <xs:enumeration value=\"public\" />{0}" +
  418. " <xs:enumeration value=\"protected\" />{0}" +
  419. " </xs:restriction>{0}" +
  420. " </xs:simpleType>{0}" +
  421. " </xs:list>{0}" +
  422. " </xs:simpleType>{0}" +
  423. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  424. }
  425. [Test]
  426. [Category ("NotDotNet")] // Mono bug ##77117
  427. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  428. public void ExportClass_MyList ()
  429. {
  430. XmlSchemas schemas = Export (typeof (MyList), "NSMyList");
  431. Assert.AreEqual (1, schemas.Count, "#1");
  432. StringWriter sw = new StringWriter ();
  433. schemas[0].Write (sw);
  434. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  435. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  436. "<xs:schema xmlns:tns=\"NSMyList\" elementFormDefault=\"qualified\" targetNamespace=\"NSMyList\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  437. " <xs:element name=\"ArrayOfAnyType\" type=\"tns:ArrayOfAnyType\" />{0}" +
  438. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  439. " <xs:sequence>{0}" +
  440. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
  441. " </xs:sequence>{0}" +
  442. " </xs:complexType>{0}" +
  443. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  444. schemas = Export (typeof (MyList));
  445. Assert.AreEqual (1, schemas.Count, "#3");
  446. sw.GetStringBuilder ().Length = 0;
  447. schemas[0].Write (sw);
  448. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  449. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  450. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  451. " <xs:element name=\"ArrayOfAnyType\" type=\"ArrayOfAnyType\" />{0}" +
  452. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  453. " <xs:sequence>{0}" +
  454. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
  455. " </xs:sequence>{0}" +
  456. " </xs:complexType>{0}" +
  457. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  458. }
  459. [Test]
  460. [Category ("NotDotNet")] // Mono bug ##77117
  461. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  462. public void ExportClass_Container ()
  463. {
  464. XmlSchemas schemas = Export (typeof (Container), "NSContainer");
  465. Assert.AreEqual (1, schemas.Count, "#1");
  466. StringWriter sw = new StringWriter ();
  467. schemas[0].Write (sw);
  468. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  469. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  470. "<xs:schema xmlns:tns=\"NSContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  471. " <xs:element name=\"Container\" type=\"tns:Container\" />{0}" +
  472. " <xs:complexType name=\"Container\">{0}" +
  473. " <xs:sequence>{0}" +
  474. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
  475. " </xs:sequence>{0}" +
  476. " </xs:complexType>{0}" +
  477. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  478. " <xs:sequence>{0}" +
  479. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
  480. " </xs:sequence>{0}" +
  481. " </xs:complexType>{0}" +
  482. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  483. schemas = Export (typeof (Container));
  484. Assert.AreEqual (1, schemas.Count, "#3");
  485. sw.GetStringBuilder ().Length = 0;
  486. schemas[0].Write (sw);
  487. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  488. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  489. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  490. " <xs:element name=\"Container\" type=\"Container\" />{0}" +
  491. " <xs:complexType name=\"Container\">{0}" +
  492. " <xs:sequence>{0}" +
  493. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"ArrayOfAnyType\" />{0}" +
  494. " </xs:sequence>{0}" +
  495. " </xs:complexType>{0}" +
  496. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  497. " <xs:sequence>{0}" +
  498. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
  499. " </xs:sequence>{0}" +
  500. " </xs:complexType>{0}" +
  501. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  502. }
  503. [Test]
  504. [Category ("NotDotNet")] // Mono bug ##77117
  505. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  506. public void ExportClass_Container2 ()
  507. {
  508. XmlSchemas schemas = Export (typeof (Container2), "NSContainer2");
  509. Assert.AreEqual (1, schemas.Count, "#1");
  510. StringWriter sw = new StringWriter ();
  511. schemas[0].Write (sw);
  512. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  513. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  514. "<xs:schema xmlns:tns=\"NSContainer2\" elementFormDefault=\"qualified\" targetNamespace=\"NSContainer2\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  515. " <xs:element name=\"Container2\" type=\"tns:Container2\" />{0}" +
  516. " <xs:complexType name=\"Container2\">{0}" +
  517. " <xs:sequence>{0}" +
  518. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
  519. " </xs:sequence>{0}" +
  520. " </xs:complexType>{0}" +
  521. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  522. " <xs:sequence>{0}" +
  523. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
  524. " </xs:sequence>{0}" +
  525. " </xs:complexType>{0}" +
  526. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  527. schemas = Export (typeof (Container2));
  528. Assert.AreEqual (1, schemas.Count, "#3");
  529. sw.GetStringBuilder ().Length = 0;
  530. schemas[0].Write (sw);
  531. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  532. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  533. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  534. " <xs:element name=\"Container2\" type=\"Container2\" />{0}" +
  535. " <xs:complexType name=\"Container2\">{0}" +
  536. " <xs:sequence>{0}" +
  537. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Items\" type=\"ArrayOfAnyType\" />{0}" +
  538. " </xs:sequence>{0}" +
  539. " </xs:complexType>{0}" +
  540. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  541. " <xs:sequence>{0}" +
  542. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
  543. " </xs:sequence>{0}" +
  544. " </xs:complexType>{0}" +
  545. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  546. }
  547. [Test]
  548. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  549. [ExpectedException (typeof (InvalidOperationException))] // Cannot use wildcards at the top level of a schema.
  550. public void ExportClass_MyElem ()
  551. {
  552. Export (typeof (MyElem), "NSMyElem");
  553. }
  554. [Test]
  555. [Category ("NotDotNet")] // Mono bug ##77117
  556. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  557. public void ExportClass_CDataContainer ()
  558. {
  559. XmlSchemas schemas = Export (typeof (CDataContainer), "NSCDataContainer");
  560. Assert.AreEqual (1, schemas.Count, "#1");
  561. StringWriter sw = new StringWriter ();
  562. schemas[0].Write (sw);
  563. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  564. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  565. "<xs:schema xmlns:tns=\"NSCDataContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSCDataContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  566. " <xs:element name=\"CDataContainer\" type=\"tns:CDataContainer\" />{0}" +
  567. " <xs:complexType name=\"CDataContainer\">{0}" +
  568. " <xs:sequence>{0}" +
  569. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"cdata\">{0}" +
  570. " <xs:complexType mixed=\"true\">{0}" +
  571. " <xs:sequence>{0}" +
  572. " <xs:any />{0}" +
  573. " </xs:sequence>{0}" +
  574. " </xs:complexType>{0}" +
  575. " </xs:element>{0}" +
  576. " </xs:sequence>{0}" +
  577. " </xs:complexType>{0}" +
  578. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  579. schemas = Export (typeof (CDataContainer));
  580. Assert.AreEqual (1, schemas.Count, "#3");
  581. sw.GetStringBuilder ().Length = 0;
  582. schemas[0].Write (sw);
  583. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  584. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  585. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  586. " <xs:element name=\"CDataContainer\" type=\"CDataContainer\" />{0}" +
  587. " <xs:complexType name=\"CDataContainer\">{0}" +
  588. " <xs:sequence>{0}" +
  589. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"cdata\">{0}" +
  590. " <xs:complexType mixed=\"true\">{0}" +
  591. " <xs:sequence>{0}" +
  592. " <xs:any />{0}" +
  593. " </xs:sequence>{0}" +
  594. " </xs:complexType>{0}" +
  595. " </xs:element>{0}" +
  596. " </xs:sequence>{0}" +
  597. " </xs:complexType>{0}" +
  598. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  599. }
  600. [Test]
  601. [Category ("NotDotNet")] // Mono bug ##77117
  602. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  603. public void ExportClass_NodeContainer ()
  604. {
  605. XmlSchemas schemas = Export (typeof (NodeContainer), "NSNodeContainer");
  606. Assert.AreEqual (1, schemas.Count, "#1");
  607. StringWriter sw = new StringWriter ();
  608. schemas[0].Write (sw);
  609. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  610. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  611. "<xs:schema xmlns:tns=\"NSNodeContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSNodeContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  612. " <xs:element name=\"NodeContainer\" type=\"tns:NodeContainer\" />{0}" +
  613. " <xs:complexType name=\"NodeContainer\">{0}" +
  614. " <xs:sequence>{0}" +
  615. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"node\">{0}" +
  616. " <xs:complexType mixed=\"true\">{0}" +
  617. " <xs:sequence>{0}" +
  618. " <xs:any />{0}" +
  619. " </xs:sequence>{0}" +
  620. " </xs:complexType>{0}" +
  621. " </xs:element>{0}" +
  622. " </xs:sequence>{0}" +
  623. " </xs:complexType>{0}" +
  624. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  625. schemas = Export (typeof (NodeContainer));
  626. Assert.AreEqual (1, schemas.Count, "#3");
  627. sw.GetStringBuilder ().Length = 0;
  628. schemas[0].Write (sw);
  629. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  630. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  631. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  632. " <xs:element name=\"NodeContainer\" type=\"NodeContainer\" />{0}" +
  633. " <xs:complexType name=\"NodeContainer\">{0}" +
  634. " <xs:sequence>{0}" +
  635. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"node\">{0}" +
  636. " <xs:complexType mixed=\"true\">{0}" +
  637. " <xs:sequence>{0}" +
  638. " <xs:any />{0}" +
  639. " </xs:sequence>{0}" +
  640. " </xs:complexType>{0}" +
  641. " </xs:element>{0}" +
  642. " </xs:sequence>{0}" +
  643. " </xs:complexType>{0}" +
  644. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  645. }
  646. [Test]
  647. [Category ("NotWorking")] // Mono does not generate the <xs:choice> node
  648. [Category ("NotDotNet")] // Mono bug ##77117 and MS.NET randomly modifies the order of the elements!
  649. public void ExportClass_Choices ()
  650. {
  651. XmlSchemas schemas = Export (typeof (Choices), "NSChoices");
  652. Assert.AreEqual (1, schemas.Count, "#1");
  653. StringWriter sw = new StringWriter ();
  654. schemas[0].Write (sw);
  655. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  656. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  657. "<xs:schema xmlns:tns=\"NSChoices\" elementFormDefault=\"qualified\" targetNamespace=\"NSChoices\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  658. " <xs:element name=\"Choices\" type=\"tns:Choices\" />{0}" +
  659. " <xs:complexType name=\"Choices\">{0}" +
  660. " <xs:sequence>{0}" +
  661. " <xs:choice minOccurs=\"1\" maxOccurs=\"1\">{0}" +
  662. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceOne\" type=\"xs:string\" />{0}" +
  663. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceTwo\" type=\"xs:string\" />{0}" +
  664. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceZero\" type=\"xs:string\" />{0}" +
  665. " </xs:choice>{0}" +
  666. " </xs:sequence>{0}" +
  667. " </xs:complexType>{0}" +
  668. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  669. schemas = Export (typeof (Choices));
  670. Assert.AreEqual (1, schemas.Count, "#3");
  671. sw.GetStringBuilder ().Length = 0;
  672. schemas[0].Write (sw);
  673. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  674. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  675. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  676. " <xs:element name=\"Choices\" type=\"Choices\" />{0}" +
  677. " <xs:complexType name=\"Choices\">{0}" +
  678. " <xs:sequence>{0}" +
  679. " <xs:choice minOccurs=\"1\" maxOccurs=\"1\">{0}" +
  680. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceOne\" type=\"xs:string\" />{0}" +
  681. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceTwo\" type=\"xs:string\" />{0}" +
  682. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ChoiceZero\" type=\"xs:string\" />{0}" +
  683. " </xs:choice>{0}" +
  684. " </xs:sequence>{0}" +
  685. " </xs:complexType>{0}" +
  686. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  687. }
  688. [Test]
  689. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  690. #if ONLY_1_1
  691. [Category ("NotDotNet")] // MS.NET 1.x does not escape spaces in a type name, bug is fixed in .NET 2.0
  692. #else
  693. [Category ("NotDotNet")] // Mono bug ##77117
  694. #endif
  695. public void ExportClass_TestSpace ()
  696. {
  697. XmlSchemas schemas = Export (typeof (TestSpace), "NSTestSpace");
  698. Assert.AreEqual (1, schemas.Count, "#1");
  699. StringWriter sw = new StringWriter ();
  700. schemas[0].Write (sw);
  701. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  702. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  703. "<xs:schema xmlns:tns=\"NSTestSpace\" elementFormDefault=\"qualified\" targetNamespace=\"NSTestSpace\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  704. " <xs:element name=\"Type_x0020_with_x0020_space\" type=\"tns:Type_x0020_with_x0020_space\" />{0}" +
  705. " <xs:complexType name=\"Type_x0020_with_x0020_space\">{0}" +
  706. " <xs:sequence>{0}" +
  707. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Element_x0020_with_x0020_space\" type=\"xs:int\" />{0}" +
  708. " </xs:sequence>{0}" +
  709. " <xs:attribute name=\"Attribute_x0020_with_x0020_space\" type=\"xs:int\" use=\"required\" />{0}" +
  710. " </xs:complexType>{0}" +
  711. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  712. schemas = Export (typeof (TestSpace));
  713. Assert.AreEqual (1, schemas.Count, "#3");
  714. sw.GetStringBuilder ().Length = 0;
  715. schemas[0].Write (sw);
  716. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  717. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  718. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  719. " <xs:element name=\"Type_x0020_with_x0020_space\" type=\"Type_x0020_with_x0020_space\" />{0}" +
  720. " <xs:complexType name=\"Type_x0020_with_x0020_space\">{0}" +
  721. " <xs:sequence>{0}" +
  722. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Element_x0020_with_x0020_space\" type=\"xs:int\" />{0}" +
  723. " </xs:sequence>{0}" +
  724. " <xs:attribute name=\"Attribute_x0020_with_x0020_space\" type=\"xs:int\" use=\"required\" />{0}" +
  725. " </xs:complexType>{0}" +
  726. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  727. }
  728. [Test]
  729. [Category ("NotDotNet")] // Mono bug ##77117
  730. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  731. public void ExportClass_ReadOnlyProperties ()
  732. {
  733. XmlSchemas schemas = Export (typeof (ReadOnlyProperties), "NSReadOnlyProperties");
  734. Assert.AreEqual (1, schemas.Count, "#1");
  735. StringWriter sw = new StringWriter ();
  736. schemas[0].Write (sw);
  737. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  738. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  739. "<xs:schema xmlns:tns=\"NSReadOnlyProperties\" elementFormDefault=\"qualified\" targetNamespace=\"NSReadOnlyProperties\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  740. " <xs:element name=\"ReadOnlyProperties\" type=\"tns:ReadOnlyProperties\" />{0}" +
  741. " <xs:complexType name=\"ReadOnlyProperties\" />{0}" +
  742. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  743. schemas = Export (typeof (ReadOnlyProperties));
  744. Assert.AreEqual (1, schemas.Count, "#3");
  745. sw.GetStringBuilder ().Length = 0;
  746. schemas[0].Write (sw);
  747. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  748. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  749. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  750. " <xs:element name=\"ReadOnlyProperties\" type=\"ReadOnlyProperties\" />{0}" +
  751. " <xs:complexType name=\"ReadOnlyProperties\" />{0}" +
  752. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  753. }
  754. [Test]
  755. [Category ("NotDotNet")] // Mono bug ##77117
  756. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  757. public void ExportClass_ListDefaults ()
  758. {
  759. XmlSchemas schemas = Export (typeof (ListDefaults), "NSListDefaults");
  760. Assert.AreEqual (1, schemas.Count, "#1");
  761. StringWriter sw = new StringWriter ();
  762. schemas[0].Write (sw);
  763. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  764. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  765. "<xs:schema xmlns:tns=\"NSListDefaults\" elementFormDefault=\"qualified\" targetNamespace=\"NSListDefaults\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  766. " <xs:element name=\"root\" type=\"tns:ListDefaults\" />{0}" +
  767. " <xs:complexType name=\"ListDefaults\">{0}" +
  768. " <xs:sequence>{0}" +
  769. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list2\" type=\"tns:ArrayOfAnyType\" />{0}" +
  770. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list3\" type=\"tns:ArrayOfAnyType\" />{0}" +
  771. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list4\" type=\"tns:ArrayOfString\" />{0}" +
  772. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"e\" type=\"tns:SimpleClass\" />{0}" +
  773. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ed\" type=\"tns:SimpleClass\" />{0}" +
  774. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"str\" type=\"xs:string\" />{0}" +
  775. " </xs:sequence>{0}" +
  776. " </xs:complexType>{0}" +
  777. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  778. " <xs:sequence>{0}" +
  779. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
  780. " </xs:sequence>{0}" +
  781. " </xs:complexType>{0}" +
  782. " <xs:complexType name=\"ArrayOfString\">{0}" +
  783. " <xs:sequence>{0}" +
  784. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
  785. " </xs:sequence>{0}" +
  786. " </xs:complexType>{0}" +
  787. " <xs:complexType name=\"SimpleClass\">{0}" +
  788. " <xs:sequence>{0}" +
  789. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
  790. " </xs:sequence>{0}" +
  791. " </xs:complexType>{0}" +
  792. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  793. schemas = Export (typeof (ListDefaults));
  794. Assert.AreEqual (1, schemas.Count, "#3");
  795. sw.GetStringBuilder ().Length = 0;
  796. schemas[0].Write (sw);
  797. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  798. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  799. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  800. " <xs:element name=\"root\" type=\"ListDefaults\" />{0}" +
  801. " <xs:complexType name=\"ListDefaults\">{0}" +
  802. " <xs:sequence>{0}" +
  803. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list2\" type=\"ArrayOfAnyType\" />{0}" +
  804. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list3\" type=\"ArrayOfAnyType\" />{0}" +
  805. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"list4\" type=\"ArrayOfString\" />{0}" +
  806. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"e\" type=\"SimpleClass\" />{0}" +
  807. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"ed\" type=\"SimpleClass\" />{0}" +
  808. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"str\" type=\"xs:string\" />{0}" +
  809. " </xs:sequence>{0}" +
  810. " </xs:complexType>{0}" +
  811. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  812. " <xs:sequence>{0}" +
  813. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
  814. " </xs:sequence>{0}" +
  815. " </xs:complexType>{0}" +
  816. " <xs:complexType name=\"ArrayOfString\">{0}" +
  817. " <xs:sequence>{0}" +
  818. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"string\" nillable=\"true\" type=\"xs:string\" />{0}" +
  819. " </xs:sequence>{0}" +
  820. " </xs:complexType>{0}" +
  821. " <xs:complexType name=\"SimpleClass\">{0}" +
  822. " <xs:sequence>{0}" +
  823. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
  824. " </xs:sequence>{0}" +
  825. " </xs:complexType>{0}" +
  826. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  827. }
  828. [Test]
  829. [Category ("NotDotNet")] // Mono bug ##77117
  830. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  831. public void ExportClass_ClsPerson ()
  832. {
  833. XmlSchemas schemas = Export (typeof (clsPerson), "NSClsPerson");
  834. Assert.AreEqual (1, schemas.Count, "#1");
  835. StringWriter sw = new StringWriter ();
  836. schemas[0].Write (sw);
  837. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  838. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  839. "<xs:schema xmlns:tns=\"NSClsPerson\" elementFormDefault=\"qualified\" targetNamespace=\"NSClsPerson\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  840. " <xs:element name=\"clsPerson\" type=\"tns:clsPerson\" />{0}" +
  841. " <xs:complexType name=\"clsPerson\">{0}" +
  842. " <xs:sequence>{0}" +
  843. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"EmailAccounts\" type=\"tns:ArrayOfAnyType\" />{0}" +
  844. " </xs:sequence>{0}" +
  845. " </xs:complexType>{0}" +
  846. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  847. " <xs:sequence>{0}" +
  848. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
  849. " </xs:sequence>{0}" +
  850. " </xs:complexType>{0}" +
  851. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  852. schemas = Export (typeof (clsPerson));
  853. Assert.AreEqual (1, schemas.Count, "#3");
  854. sw.GetStringBuilder ().Length = 0;
  855. schemas[0].Write (sw);
  856. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  857. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  858. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  859. " <xs:element name=\"clsPerson\" type=\"clsPerson\" />{0}" +
  860. " <xs:complexType name=\"clsPerson\">{0}" +
  861. " <xs:sequence>{0}" +
  862. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"EmailAccounts\" type=\"ArrayOfAnyType\" />{0}" +
  863. " </xs:sequence>{0}" +
  864. " </xs:complexType>{0}" +
  865. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  866. " <xs:sequence>{0}" +
  867. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
  868. " </xs:sequence>{0}" +
  869. " </xs:complexType>{0}" +
  870. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  871. }
  872. [Test]
  873. [Category ("NotDotNet")] // Mono bug ##77117
  874. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  875. public void ExportClass_ArrayClass ()
  876. {
  877. XmlSchemas schemas = Export (typeof (ArrayClass), "NSArrayClass");
  878. Assert.AreEqual (1, schemas.Count, "#1");
  879. StringWriter sw = new StringWriter ();
  880. schemas[0].Write (sw);
  881. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  882. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  883. "<xs:schema xmlns:tns=\"NSArrayClass\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayClass\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  884. " <xs:element name=\"ArrayClass\" type=\"tns:ArrayClass\" />{0}" +
  885. " <xs:complexType name=\"ArrayClass\">{0}" +
  886. " <xs:sequence>{0}" +
  887. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"names\" />{0}" +
  888. " </xs:sequence>{0}" +
  889. " </xs:complexType>{0}" +
  890. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  891. schemas = Export (typeof (ArrayClass));
  892. Assert.AreEqual (1, schemas.Count, "#3");
  893. sw.GetStringBuilder ().Length = 0;
  894. schemas[0].Write (sw);
  895. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  896. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  897. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  898. " <xs:element name=\"ArrayClass\" type=\"ArrayClass\" />{0}" +
  899. " <xs:complexType name=\"ArrayClass\">{0}" +
  900. " <xs:sequence>{0}" +
  901. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"names\" />{0}" +
  902. " </xs:sequence>{0}" +
  903. " </xs:complexType>{0}" +
  904. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  905. }
  906. [Test]
  907. [Category ("NotDotNet")] // Mono bug ##77117
  908. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  909. public void ExportClass_StructContainer ()
  910. {
  911. XmlSchemas schemas = Export (typeof (StructContainer), "NSStructContainer");
  912. Assert.AreEqual (1, schemas.Count, "#1");
  913. StringWriter sw = new StringWriter ();
  914. schemas[0].Write (sw);
  915. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  916. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  917. "<xs:schema xmlns:tns=\"NSStructContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSStructContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  918. " <xs:element name=\"StructContainer\" type=\"tns:StructContainer\" />{0}" +
  919. " <xs:complexType name=\"StructContainer\">{0}" +
  920. " <xs:sequence>{0}" +
  921. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Value\" type=\"tns:EnumDefaultValue\" />{0}" +
  922. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Times\" type=\"tns:ArrayOfTimeSpan\" />{0}" +
  923. " </xs:sequence>{0}" +
  924. " </xs:complexType>{0}" +
  925. " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
  926. " <xs:list>{0}" +
  927. " <xs:simpleType>{0}" +
  928. " <xs:restriction base=\"xs:string\">{0}" +
  929. " <xs:enumeration value=\"e1\" />{0}" +
  930. " <xs:enumeration value=\"e2\" />{0}" +
  931. " <xs:enumeration value=\"e3\" />{0}" +
  932. " </xs:restriction>{0}" +
  933. " </xs:simpleType>{0}" +
  934. " </xs:list>{0}" +
  935. " </xs:simpleType>{0}" +
  936. " <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
  937. " <xs:sequence>{0}" +
  938. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" nillable=\"true\" type=\"tns:TimeSpan\" />{0}" +
  939. " </xs:sequence>{0}" +
  940. " </xs:complexType>{0}" +
  941. " <xs:complexType name=\"TimeSpan\" />{0}" +
  942. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  943. schemas = Export (typeof (StructContainer));
  944. Assert.AreEqual (1, schemas.Count, "#3");
  945. sw.GetStringBuilder ().Length = 0;
  946. schemas[0].Write (sw);
  947. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  948. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  949. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  950. " <xs:element name=\"StructContainer\" type=\"StructContainer\" />{0}" +
  951. " <xs:complexType name=\"StructContainer\">{0}" +
  952. " <xs:sequence>{0}" +
  953. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Value\" type=\"EnumDefaultValue\" />{0}" +
  954. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Times\" type=\"ArrayOfTimeSpan\" />{0}" +
  955. " </xs:sequence>{0}" +
  956. " </xs:complexType>{0}" +
  957. " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
  958. " <xs:list>{0}" +
  959. " <xs:simpleType>{0}" +
  960. " <xs:restriction base=\"xs:string\">{0}" +
  961. " <xs:enumeration value=\"e1\" />{0}" +
  962. " <xs:enumeration value=\"e2\" />{0}" +
  963. " <xs:enumeration value=\"e3\" />{0}" +
  964. " </xs:restriction>{0}" +
  965. " </xs:simpleType>{0}" +
  966. " </xs:list>{0}" +
  967. " </xs:simpleType>{0}" +
  968. " <xs:complexType name=\"ArrayOfTimeSpan\">{0}" +
  969. " <xs:sequence>{0}" +
  970. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"TimeSpan\" nillable=\"true\" type=\"TimeSpan\" />{0}" +
  971. " </xs:sequence>{0}" +
  972. " </xs:complexType>{0}" +
  973. " <xs:complexType name=\"TimeSpan\" />{0}" +
  974. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  975. }
  976. [Test]
  977. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  978. [ExpectedException (typeof (InvalidOperationException))] // Cannot use wildcards at the top level of a schema.
  979. public void ExportClass_XmlElement ()
  980. {
  981. XmlSchemas schemas = Export (typeof (XmlElement), "NS1");
  982. }
  983. [Test]
  984. [Category ("NotDotNet")] // Mono bug ##77117
  985. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  986. public void ExportClass_Array ()
  987. {
  988. XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
  989. XmlAttributes attr = new XmlAttributes ();
  990. XmlElementAttribute element = new XmlElementAttribute ();
  991. element.ElementName = "saying";
  992. element.IsNullable = true;
  993. attr.XmlElements.Add (element);
  994. overrides.Add (typeof (SimpleClass), "something", attr);
  995. XmlSchemas schemas = Export (typeof (SimpleClass[]), overrides, "NSSimpleClassArray");
  996. Assert.AreEqual (1, schemas.Count, "#1");
  997. StringWriter sw = new StringWriter ();
  998. schemas[0].Write (sw);
  999. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1000. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1001. "<xs:schema xmlns:tns=\"NSSimpleClassArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClassArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1002. " <xs:element name=\"ArrayOfSimpleClass\" type=\"tns:ArrayOfSimpleClass\" />{0}" +
  1003. " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
  1004. " <xs:sequence>{0}" +
  1005. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"tns:SimpleClass\" />{0}" +
  1006. " </xs:sequence>{0}" +
  1007. " </xs:complexType>{0}" +
  1008. " <xs:complexType name=\"SimpleClass\">{0}" +
  1009. " <xs:sequence>{0}" +
  1010. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
  1011. " </xs:sequence>{0}" +
  1012. " </xs:complexType>{0}" +
  1013. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  1014. schemas = Export (typeof (SimpleClass[]), overrides);
  1015. Assert.AreEqual (1, schemas.Count, "#3");
  1016. sw.GetStringBuilder ().Length = 0;
  1017. schemas[0].Write (sw);
  1018. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1019. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1020. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1021. " <xs:element name=\"ArrayOfSimpleClass\" type=\"ArrayOfSimpleClass\" />{0}" +
  1022. " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
  1023. " <xs:sequence>{0}" +
  1024. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"SimpleClass\" nillable=\"true\" type=\"SimpleClass\" />{0}" +
  1025. " </xs:sequence>{0}" +
  1026. " </xs:complexType>{0}" +
  1027. " <xs:complexType name=\"SimpleClass\">{0}" +
  1028. " <xs:sequence>{0}" +
  1029. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
  1030. " </xs:sequence>{0}" +
  1031. " </xs:complexType>{0}" +
  1032. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  1033. }
  1034. [Test]
  1035. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1036. public void ExportEnum ()
  1037. {
  1038. XmlSchemas schemas = Export (typeof (EnumDefaultValue), "NSEnumDefaultValue");
  1039. Assert.AreEqual (1, schemas.Count, "#1");
  1040. StringWriter sw = new StringWriter ();
  1041. schemas[0].Write (sw);
  1042. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1043. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1044. "<xs:schema xmlns:tns=\"NSEnumDefaultValue\" elementFormDefault=\"qualified\" targetNamespace=\"NSEnumDefaultValue\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1045. " <xs:element name=\"EnumDefaultValue\" type=\"tns:EnumDefaultValue\" />{0}" +
  1046. " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
  1047. " <xs:list>{0}" +
  1048. " <xs:simpleType>{0}" +
  1049. " <xs:restriction base=\"xs:string\">{0}" +
  1050. " <xs:enumeration value=\"e1\" />{0}" +
  1051. " <xs:enumeration value=\"e2\" />{0}" +
  1052. " <xs:enumeration value=\"e3\" />{0}" +
  1053. " </xs:restriction>{0}" +
  1054. " </xs:simpleType>{0}" +
  1055. " </xs:list>{0}" +
  1056. " </xs:simpleType>{0}" +
  1057. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  1058. schemas = Export (typeof (EnumDefaultValueNF), "NSEnumDefaultValueNF");
  1059. Assert.AreEqual (1, schemas.Count, "#3");
  1060. sw.GetStringBuilder ().Length = 0;
  1061. schemas[0].Write (sw);
  1062. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1063. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1064. "<xs:schema xmlns:tns=\"NSEnumDefaultValueNF\" elementFormDefault=\"qualified\" targetNamespace=\"NSEnumDefaultValueNF\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1065. " <xs:element name=\"EnumDefaultValueNF\" type=\"tns:EnumDefaultValueNF\" />{0}" +
  1066. " <xs:simpleType name=\"EnumDefaultValueNF\">{0}" +
  1067. " <xs:restriction base=\"xs:string\">{0}" +
  1068. " <xs:enumeration value=\"e1\" />{0}" +
  1069. " <xs:enumeration value=\"e2\" />{0}" +
  1070. " <xs:enumeration value=\"e3\" />{0}" +
  1071. " </xs:restriction>{0}" +
  1072. " </xs:simpleType>{0}" +
  1073. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  1074. schemas = Export (typeof (EnumDefaultValue));
  1075. Assert.AreEqual (1, schemas.Count, "#5");
  1076. sw.GetStringBuilder ().Length = 0;
  1077. schemas[0].Write (sw);
  1078. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1079. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1080. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1081. " <xs:element name=\"EnumDefaultValue\" type=\"EnumDefaultValue\" />{0}" +
  1082. " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
  1083. " <xs:list>{0}" +
  1084. " <xs:simpleType>{0}" +
  1085. " <xs:restriction base=\"xs:string\">{0}" +
  1086. " <xs:enumeration value=\"e1\" />{0}" +
  1087. " <xs:enumeration value=\"e2\" />{0}" +
  1088. " <xs:enumeration value=\"e3\" />{0}" +
  1089. " </xs:restriction>{0}" +
  1090. " </xs:simpleType>{0}" +
  1091. " </xs:list>{0}" +
  1092. " </xs:simpleType>{0}" +
  1093. "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
  1094. schemas = Export (typeof (EnumDefaultValueNF));
  1095. Assert.AreEqual (1, schemas.Count, "#7");
  1096. sw.GetStringBuilder ().Length = 0;
  1097. schemas[0].Write (sw);
  1098. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1099. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1100. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1101. " <xs:element name=\"EnumDefaultValueNF\" type=\"EnumDefaultValueNF\" />{0}" +
  1102. " <xs:simpleType name=\"EnumDefaultValueNF\">{0}" +
  1103. " <xs:restriction base=\"xs:string\">{0}" +
  1104. " <xs:enumeration value=\"e1\" />{0}" +
  1105. " <xs:enumeration value=\"e2\" />{0}" +
  1106. " <xs:enumeration value=\"e3\" />{0}" +
  1107. " </xs:restriction>{0}" +
  1108. " </xs:simpleType>{0}" +
  1109. "</xs:schema>", Environment.NewLine), sw.ToString (), "#8");
  1110. }
  1111. [Test]
  1112. [Category ("NotDotNet")] // Mono bug ##77117
  1113. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1114. public void ExportXmlSerializable ()
  1115. {
  1116. XmlSchemas schemas = Export (typeof (Employee), "NSEmployee");
  1117. Assert.AreEqual (1, schemas.Count, "#1");
  1118. StringWriter sw = new StringWriter ();
  1119. schemas[0].Write (sw);
  1120. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1121. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1122. "<xs:schema xmlns:tns=\"NSEmployee\" elementFormDefault=\"qualified\" targetNamespace=\"NSEmployee\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1123. " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
  1124. " <xs:element name=\"Employee\">{0}" +
  1125. " <xs:complexType>{0}" +
  1126. " <xs:sequence>{0}" +
  1127. " <xs:element ref=\"xs:schema\" />{0}" +
  1128. " <xs:any />{0}" +
  1129. " </xs:sequence>{0}" +
  1130. " </xs:complexType>{0}" +
  1131. " </xs:element>{0}" +
  1132. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  1133. schemas = Export (typeof (Employee));
  1134. Assert.AreEqual (1, schemas.Count, "#3");
  1135. sw.GetStringBuilder ().Length = 0;
  1136. schemas[0].Write (sw);
  1137. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1138. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1139. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1140. " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
  1141. " <xs:element name=\"Employee\">{0}" +
  1142. " <xs:complexType>{0}" +
  1143. " <xs:sequence>{0}" +
  1144. " <xs:element ref=\"xs:schema\" />{0}" +
  1145. " <xs:any />{0}" +
  1146. " </xs:sequence>{0}" +
  1147. " </xs:complexType>{0}" +
  1148. " </xs:element>{0}" +
  1149. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  1150. }
  1151. [Test]
  1152. [Category ("NotDotNet")] // Mono bug ##77117
  1153. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1154. public void ExportXmlSerializable_Schema ()
  1155. {
  1156. XmlSchemas schemas = Export (typeof (EmployeeSchema), "NSEmployeeSchema");
  1157. Assert.AreEqual (2, schemas.Count, "#1");
  1158. StringWriter sw = new StringWriter ();
  1159. schemas[0].Write (sw);
  1160. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1161. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1162. "<xs:schema xmlns:tns=\"NSEmployeeSchema\" elementFormDefault=\"qualified\" targetNamespace=\"NSEmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1163. #if ONLY_1_1
  1164. " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
  1165. #endif
  1166. " <xs:element name=\"EmployeeSchema\">{0}" +
  1167. " <xs:complexType>{0}" +
  1168. " <xs:sequence>{0}" +
  1169. " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
  1170. " </xs:sequence>{0}" +
  1171. " </xs:complexType>{0}" +
  1172. " </xs:element>{0}" +
  1173. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  1174. sw.GetStringBuilder ().Length = 0;
  1175. schemas[1].Write (sw);
  1176. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1177. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1178. "<xs:schema xmlns:tns=\"urn:types-devx-com\" targetNamespace=\"urn:types-devx-com\" id=\"EmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1179. " <xs:complexType name=\"employeeRoot\">{0}" +
  1180. " <xs:attribute name=\"firstName\" />{0}" +
  1181. " <xs:attribute name=\"lastName\" />{0}" +
  1182. " <xs:attribute name=\"address\" />{0}" +
  1183. " </xs:complexType>{0}" +
  1184. " <xs:element name=\"employee\" type=\"tns:employeeRoot\" />{0}" +
  1185. "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
  1186. schemas = Export (typeof (EmployeeSchema));
  1187. Assert.AreEqual (2, schemas.Count, "#4");
  1188. sw.GetStringBuilder ().Length = 0;
  1189. schemas[0].Write (sw);
  1190. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1191. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1192. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1193. #if ONLY_1_1
  1194. " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
  1195. #endif
  1196. " <xs:element name=\"EmployeeSchema\">{0}" +
  1197. " <xs:complexType>{0}" +
  1198. " <xs:sequence>{0}" +
  1199. " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
  1200. " </xs:sequence>{0}" +
  1201. " </xs:complexType>{0}" +
  1202. " </xs:element>{0}" +
  1203. "</xs:schema>", Environment.NewLine), sw.ToString (), "#5");
  1204. sw.GetStringBuilder ().Length = 0;
  1205. schemas[1].Write (sw);
  1206. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1207. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1208. "<xs:schema xmlns:tns=\"urn:types-devx-com\" targetNamespace=\"urn:types-devx-com\" id=\"EmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1209. " <xs:complexType name=\"employeeRoot\">{0}" +
  1210. " <xs:attribute name=\"firstName\" />{0}" +
  1211. " <xs:attribute name=\"lastName\" />{0}" +
  1212. " <xs:attribute name=\"address\" />{0}" +
  1213. " </xs:complexType>{0}" +
  1214. " <xs:element name=\"employee\" type=\"tns:employeeRoot\" />{0}" +
  1215. "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
  1216. schemas = Export (typeof (PrimitiveSchema), "NSPrimitiveSchema");
  1217. Assert.AreEqual (2, schemas.Count, "#7");
  1218. sw.GetStringBuilder ().Length = 0;
  1219. schemas[0].Write (sw);
  1220. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1221. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1222. "<xs:schema xmlns:tns=\"NSPrimitiveSchema\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimitiveSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1223. " <xs:element name=\"PrimitiveSchema\">{0}" +
  1224. " <xs:complexType>{0}" +
  1225. " <xs:sequence>{0}" +
  1226. " <xs:any namespace=\"\" />{0}" +
  1227. " </xs:sequence>{0}" +
  1228. " </xs:complexType>{0}" +
  1229. " </xs:element>{0}" +
  1230. "</xs:schema>", Environment.NewLine), sw.ToString (), "#8");
  1231. sw.GetStringBuilder ().Length = 0;
  1232. schemas[1].Write (sw);
  1233. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1234. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1235. "<xs:schema id=\"LuckyNumberSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1236. " <xs:element name=\"LuckyNumber\" type=\"xs:int\" />{0}" +
  1237. "</xs:schema>", Environment.NewLine), sw.ToString (), "#9");
  1238. }
  1239. [Test]
  1240. [ExpectedException (typeof (InvalidOperationException))] // Schema Id is missing
  1241. public void ExportXmlSerializable_MissingID ()
  1242. {
  1243. Export (typeof (MissingIDSchema));
  1244. }
  1245. [ExpectedException (typeof (InvalidOperationException))]
  1246. public void ExportXmlSerializable_DuplicateNamespace ()
  1247. {
  1248. try {
  1249. Export (typeof (PrimitiveSchema));
  1250. Assert.Fail ("#1");
  1251. } catch (InvalidOperationException) {
  1252. // The namespace, , is a duplicate.
  1253. }
  1254. try {
  1255. Export (typeof (XmlSerializableContainer));
  1256. Assert.Fail ("#2");
  1257. } catch (InvalidOperationException) {
  1258. // The namespace, , is a duplicate.
  1259. }
  1260. }
  1261. [Test]
  1262. [Category ("NotDotNet")] // Mono bug ##77117
  1263. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1264. #if NET_2_0
  1265. [Category ("NotWorking")] // support for XmlSchemaProvider is not implemented
  1266. #endif
  1267. public void ExportXmlSerializable_SchemaProvider ()
  1268. {
  1269. XmlSchemas schemas = Export (typeof (EmployeeSchemaProvider), "NSEmployeeSchemaProvider");
  1270. Assert.AreEqual (1, schemas.Count, "#1");
  1271. StringWriter sw = new StringWriter ();
  1272. schemas[0].Write (sw);
  1273. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1274. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1275. "<xs:schema xmlns:tns=\"NSEmployeeSchemaProvider\" elementFormDefault=\"qualified\" targetNamespace=\"NSEmployeeSchemaProvider\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1276. #if NET_2_0
  1277. " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
  1278. " <xs:element name=\"employeeRoot\" nillable=\"true\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
  1279. #else
  1280. " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
  1281. " <xs:element name=\"EmployeeSchemaProvider\">{0}" +
  1282. " <xs:complexType>{0}" +
  1283. " <xs:sequence>{0}" +
  1284. " <xs:element ref=\"xs:schema\" />{0}" +
  1285. " <xs:any />{0}" +
  1286. " </xs:sequence>{0}" +
  1287. " </xs:complexType>{0}" +
  1288. " </xs:element>{0}" +
  1289. #endif
  1290. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  1291. schemas = Export (typeof (EmployeeSchemaProvider));
  1292. Assert.AreEqual (1, schemas.Count, "#3");
  1293. sw.GetStringBuilder ().Length = 0;
  1294. schemas[0].Write (sw);
  1295. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1296. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1297. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1298. #if NET_2_0
  1299. " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
  1300. " <xs:element name=\"employeeRoot\" nillable=\"true\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
  1301. #else
  1302. " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
  1303. " <xs:element name=\"EmployeeSchemaProvider\">{0}" +
  1304. " <xs:complexType>{0}" +
  1305. " <xs:sequence>{0}" +
  1306. " <xs:element ref=\"xs:schema\" />{0}" +
  1307. " <xs:any />{0}" +
  1308. " </xs:sequence>{0}" +
  1309. " </xs:complexType>{0}" +
  1310. " </xs:element>{0}" +
  1311. #endif
  1312. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  1313. schemas = Export (typeof (PrimitiveSchemaProvider), "NSPrimitiveSchemaProvider");
  1314. Assert.AreEqual (1, schemas.Count, "#5");
  1315. sw.GetStringBuilder ().Length = 0;
  1316. schemas[0].Write (sw);
  1317. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1318. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1319. "<xs:schema xmlns:tns=\"NSPrimitiveSchemaProvider\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimitiveSchemaProvider\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1320. #if NET_2_0
  1321. " <xs:import />{0}" +
  1322. " <xs:element name=\"int\" nillable=\"true\" type=\"xs:int\" />{0}" +
  1323. #else
  1324. " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
  1325. " <xs:element name=\"PrimitiveSchemaProvider\">{0}" +
  1326. " <xs:complexType>{0}" +
  1327. " <xs:sequence>{0}" +
  1328. " <xs:element ref=\"xs:schema\" />{0}" +
  1329. " <xs:any />{0}" +
  1330. " </xs:sequence>{0}" +
  1331. " </xs:complexType>{0}" +
  1332. " </xs:element>{0}" +
  1333. #endif
  1334. "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
  1335. schemas = Export (typeof (PrimitiveSchemaProvider));
  1336. Assert.AreEqual (1, schemas.Count, "#7");
  1337. sw.GetStringBuilder ().Length = 0;
  1338. schemas[0].Write (sw);
  1339. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1340. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1341. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1342. #if NET_2_0
  1343. " <xs:element name=\"int\" nillable=\"true\" type=\"xs:int\" />{0}" +
  1344. #else
  1345. " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
  1346. " <xs:element name=\"PrimitiveSchemaProvider\">{0}" +
  1347. " <xs:complexType>{0}" +
  1348. " <xs:sequence>{0}" +
  1349. " <xs:element ref=\"xs:schema\" />{0}" +
  1350. " <xs:any />{0}" +
  1351. " </xs:sequence>{0}" +
  1352. " </xs:complexType>{0}" +
  1353. " </xs:element>{0}" +
  1354. #endif
  1355. "</xs:schema>", Environment.NewLine), sw.ToString (), "#8");
  1356. }
  1357. [Test]
  1358. [Category ("NotDotNet")] // Mono bug ##77117
  1359. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1360. #if NET_2_0
  1361. [Category ("NotWorking")] // support for XmlSchemaProvider is not implemented
  1362. #endif
  1363. public void ExportXmlSerializable_Container ()
  1364. {
  1365. XmlSchemas schemas = Export (typeof (XmlSerializableContainer), "NSXmlSerializableContainer");
  1366. Assert.AreEqual (3, schemas.Count, "#1");
  1367. StringWriter sw = new StringWriter ();
  1368. schemas[0].Write (sw);
  1369. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1370. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1371. "<xs:schema xmlns:tns=\"NSXmlSerializableContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSXmlSerializableContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1372. " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
  1373. " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
  1374. #if NET_2_0
  1375. " <xs:import />{0}" +
  1376. #endif
  1377. " <xs:element name=\"XmlSerializableContainer\" type=\"tns:XmlSerializableContainer\" />{0}" +
  1378. " <xs:complexType name=\"XmlSerializableContainer\">{0}" +
  1379. " <xs:sequence>{0}" +
  1380. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Slave\">{0}" +
  1381. " <xs:complexType>{0}" +
  1382. " <xs:sequence>{0}" +
  1383. " <xs:element ref=\"xs:schema\" />{0}" +
  1384. " <xs:any />{0}" +
  1385. " </xs:sequence>{0}" +
  1386. " </xs:complexType>{0}" +
  1387. " </xs:element>{0}" +
  1388. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"SlaveSchema\">{0}" +
  1389. " <xs:complexType>{0}" +
  1390. " <xs:sequence>{0}" +
  1391. " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
  1392. " </xs:sequence>{0}" +
  1393. " </xs:complexType>{0}" +
  1394. " </xs:element>{0}" +
  1395. #if NET_2_0
  1396. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"SlaveSchemaProvider\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
  1397. #else
  1398. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"SlaveSchemaProvider\">{0}" +
  1399. " <xs:complexType>{0}" +
  1400. " <xs:sequence>{0}" +
  1401. " <xs:element ref=\"xs:schema\" />{0}" +
  1402. " <xs:any />{0}" +
  1403. " </xs:sequence>{0}" +
  1404. " </xs:complexType>{0}" +
  1405. " </xs:element>{0}" +
  1406. #endif
  1407. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"NativeSchema\">{0}" +
  1408. " <xs:complexType>{0}" +
  1409. " <xs:sequence>{0}" +
  1410. " <xs:any namespace=\"\" />{0}" +
  1411. " </xs:sequence>{0}" +
  1412. " </xs:complexType>{0}" +
  1413. " </xs:element>{0}" +
  1414. #if NET_2_0
  1415. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"NativeSchemaProvider\" type=\"xs:int\" />{0}" +
  1416. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q2=\"urn:types-devx-com\" ref=\"q2:SlaveNamespace\" />{0}" +
  1417. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q3=\"urn:types-devx-com\" ref=\"q3:SlaveSchemaNamespace\" />{0}" +
  1418. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q4=\"urn:types-devx-com\" ref=\"q4:SlaveSchemaProviderNamespace\" />{0}" +
  1419. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q5=\"urn:types-devx-com\" ref=\"q5:NativeSchemaNamespace\" />{0}" +
  1420. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q6=\"urn:types-devx-com\" ref=\"q6:NativeSchemaProviderNamespace\" />{0}" +
  1421. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q7=\"urn:types-devx-com\" ref=\"q7:SlaveNSOnly\" />{0}" +
  1422. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q8=\"urn:types-devx-com\" ref=\"q8:SlaveSchemaNSOnly\" />{0}" +
  1423. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q9=\"urn:types-devx-com\" ref=\"q9:SlaveSchemaProviderNSOnly\" />{0}" +
  1424. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q10=\"urn:types-devx-com\" ref=\"q10:NativeSchemaNSOnly\" />{0}" +
  1425. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q11=\"urn:types-devx-com\" ref=\"q11:NativeSchemaProviderNSOnly\" />{0}" +
  1426. #else
  1427. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"NativeSchemaProvider\">{0}" +
  1428. " <xs:complexType>{0}" +
  1429. " <xs:sequence>{0}" +
  1430. " <xs:element ref=\"xs:schema\" />{0}" +
  1431. " <xs:any />{0}" +
  1432. " </xs:sequence>{0}" +
  1433. " </xs:complexType>{0}" +
  1434. " </xs:element>{0}" +
  1435. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q1=\"urn:types-devx-com\" ref=\"q1:SlaveNamespace\" />{0}" +
  1436. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q2=\"urn:types-devx-com\" ref=\"q2:SlaveSchemaNamespace\" />{0}" +
  1437. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q3=\"urn:types-devx-com\" ref=\"q3:SlaveSchemaProviderNamespace\" />{0}" +
  1438. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q4=\"urn:types-devx-com\" ref=\"q4:NativeSchemaNamespace\" />{0}" +
  1439. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q5=\"urn:types-devx-com\" ref=\"q5:NativeSchemaProviderNamespace\" />{0}" +
  1440. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q6=\"urn:types-devx-com\" ref=\"q6:SlaveNSOnly\" />{0}" +
  1441. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q7=\"urn:types-devx-com\" ref=\"q7:SlaveSchemaNSOnly\" />{0}" +
  1442. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q8=\"urn:types-devx-com\" ref=\"q8:SlaveSchemaProviderNSOnly\" />{0}" +
  1443. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q9=\"urn:types-devx-com\" ref=\"q9:NativeSchemaNSOnly\" />{0}" +
  1444. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q10=\"urn:types-devx-com\" ref=\"q10:NativeSchemaProviderNSOnly\" />{0}" +
  1445. #endif
  1446. " </xs:sequence>{0}" +
  1447. " </xs:complexType>{0}" +
  1448. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  1449. sw.GetStringBuilder ().Length = 0;
  1450. schemas[1].Write (sw);
  1451. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1452. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1453. "<xs:schema xmlns:tns=\"urn:types-devx-com\" targetNamespace=\"urn:types-devx-com\" id=\"EmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1454. " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
  1455. #if NET_2_0
  1456. " <xs:import />{0}" +
  1457. #endif
  1458. " <xs:complexType name=\"employeeRoot\">{0}" +
  1459. " <xs:attribute name=\"firstName\" />{0}" +
  1460. " <xs:attribute name=\"lastName\" />{0}" +
  1461. " <xs:attribute name=\"address\" />{0}" +
  1462. " </xs:complexType>{0}" +
  1463. " <xs:element name=\"employee\" type=\"tns:employeeRoot\" />{0}" +
  1464. " <xs:element name=\"SlaveNamespace\">{0}" +
  1465. " <xs:complexType>{0}" +
  1466. " <xs:sequence>{0}" +
  1467. " <xs:element ref=\"xs:schema\" />{0}" +
  1468. " <xs:any />{0}" +
  1469. " </xs:sequence>{0}" +
  1470. " </xs:complexType>{0}" +
  1471. " </xs:element>{0}" +
  1472. " <xs:element name=\"SlaveSchemaNamespace\">{0}" +
  1473. " <xs:complexType>{0}" +
  1474. " <xs:sequence>{0}" +
  1475. " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
  1476. " </xs:sequence>{0}" +
  1477. " </xs:complexType>{0}" +
  1478. " </xs:element>{0}" +
  1479. #if NET_2_0
  1480. " <xs:element name=\"SlaveSchemaProviderNamespace\" type=\"tns:employeeRoot\" />{0}" +
  1481. #else
  1482. " <xs:element name=\"SlaveSchemaProviderNamespace\">{0}" +
  1483. " <xs:complexType>{0}" +
  1484. " <xs:sequence>{0}" +
  1485. " <xs:element ref=\"xs:schema\" />{0}" +
  1486. " <xs:any />{0}" +
  1487. " </xs:sequence>{0}" +
  1488. " </xs:complexType>{0}" +
  1489. " </xs:element>{0}" +
  1490. #endif
  1491. " <xs:element name=\"NativeSchemaNamespace\">{0}" +
  1492. " <xs:complexType>{0}" +
  1493. " <xs:sequence>{0}" +
  1494. " <xs:any namespace=\"\" />{0}" +
  1495. " </xs:sequence>{0}" +
  1496. " </xs:complexType>{0}" +
  1497. " </xs:element>{0}" +
  1498. #if NET_2_0
  1499. " <xs:element name=\"NativeSchemaProviderNamespace\" type=\"xs:int\" />{0}" +
  1500. #else
  1501. " <xs:element name=\"NativeSchemaProviderNamespace\">{0}" +
  1502. " <xs:complexType>{0}" +
  1503. " <xs:sequence>{0}" +
  1504. " <xs:element ref=\"xs:schema\" />{0}" +
  1505. " <xs:any />{0}" +
  1506. " </xs:sequence>{0}" +
  1507. " </xs:complexType>{0}" +
  1508. " </xs:element>{0}" +
  1509. #endif
  1510. " <xs:element name=\"SlaveNSOnly\">{0}" +
  1511. " <xs:complexType>{0}" +
  1512. " <xs:sequence>{0}" +
  1513. " <xs:element ref=\"xs:schema\" />{0}" +
  1514. " <xs:any />{0}" +
  1515. " </xs:sequence>{0}" +
  1516. " </xs:complexType>{0}" +
  1517. " </xs:element>{0}" +
  1518. " <xs:element name=\"SlaveSchemaNSOnly\">{0}" +
  1519. " <xs:complexType>{0}" +
  1520. " <xs:sequence>{0}" +
  1521. " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
  1522. " </xs:sequence>{0}" +
  1523. " </xs:complexType>{0}" +
  1524. " </xs:element>{0}" +
  1525. #if NET_2_0
  1526. " <xs:element name=\"SlaveSchemaProviderNSOnly\" type=\"tns:employeeRoot\" />{0}" +
  1527. #else
  1528. " <xs:element name=\"SlaveSchemaProviderNSOnly\">{0}" +
  1529. " <xs:complexType>{0}" +
  1530. " <xs:sequence>{0}" +
  1531. " <xs:element ref=\"xs:schema\" />{0}" +
  1532. " <xs:any />{0}" +
  1533. " </xs:sequence>{0}" +
  1534. " </xs:complexType>{0}" +
  1535. " </xs:element>{0}" +
  1536. #endif
  1537. " <xs:element name=\"NativeSchemaNSOnly\">{0}" +
  1538. " <xs:complexType>{0}" +
  1539. " <xs:sequence>{0}" +
  1540. " <xs:any namespace=\"\" />{0}" +
  1541. " </xs:sequence>{0}" +
  1542. " </xs:complexType>{0}" +
  1543. " </xs:element>{0}" +
  1544. #if NET_2_0
  1545. " <xs:element name=\"NativeSchemaProviderNSOnly\" type=\"xs:int\" />{0}" +
  1546. #else
  1547. " <xs:element name=\"NativeSchemaProviderNSOnly\">{0}" +
  1548. " <xs:complexType>{0}" +
  1549. " <xs:sequence>{0}" +
  1550. " <xs:element ref=\"xs:schema\" />{0}" +
  1551. " <xs:any />{0}" +
  1552. " </xs:sequence>{0}" +
  1553. " </xs:complexType>{0}" +
  1554. " </xs:element>{0}" +
  1555. #endif
  1556. "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
  1557. sw.GetStringBuilder ().Length = 0;
  1558. schemas[2].Write (sw);
  1559. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1560. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1561. "<xs:schema id=\"LuckyNumberSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1562. " <xs:element name=\"LuckyNumber\" type=\"xs:int\" />{0}" +
  1563. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  1564. }
  1565. [Test]
  1566. [Category ("NotDotNet")] // Mono bug ##77117
  1567. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1568. public void ExportXsdPrimitive ()
  1569. {
  1570. ArrayList types = new ArrayList ();
  1571. types.Add (new TypeDescription (typeof (byte), true, "unsignedByte", "Byte"));
  1572. types.Add (new TypeDescription (typeof (sbyte), true, "byte", "Byte"));
  1573. types.Add (new TypeDescription (typeof (bool), true, "boolean", "Boolean"));
  1574. types.Add (new TypeDescription (typeof (short), true, "short", "Short"));
  1575. types.Add (new TypeDescription (typeof (int), true, "int", "Int"));
  1576. types.Add (new TypeDescription (typeof (long), true, "long", "Long"));
  1577. types.Add (new TypeDescription (typeof (float), true, "float", "Float"));
  1578. types.Add (new TypeDescription (typeof (double), true, "double", "Double"));
  1579. types.Add (new TypeDescription (typeof (decimal), true, "decimal", "Decimal"));
  1580. types.Add (new TypeDescription (typeof (ushort), true, "unsignedShort", "UnsignedShort"));
  1581. types.Add (new TypeDescription (typeof (uint), true, "unsignedInt", "UnsignedInt"));
  1582. types.Add (new TypeDescription (typeof (ulong), true, "unsignedLong", "UnsignedLong"));
  1583. types.Add (new TypeDescription (typeof (DateTime), true, "dateTime", "DateTime"));
  1584. #if NET_2_0
  1585. types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName", true));
  1586. #else
  1587. types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName"));
  1588. #endif
  1589. types.Add (new TypeDescription (typeof (string), true, "string", "String", true));
  1590. foreach (TypeDescription typeDesc in types) {
  1591. XmlSchemas schemas = Export (typeDesc.Type, typeDesc.Type.Name);
  1592. Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1");
  1593. StringWriter sw = new StringWriter ();
  1594. schemas[0].Write (sw);
  1595. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1596. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1597. "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1598. " <xs:element name=\"{2}\" {3}type=\"xs:{2}\" />{0}" +
  1599. "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.XmlType, ""),
  1600. sw.ToString (), typeDesc.Type.FullName + "#2");
  1601. schemas = Export (typeDesc.Type);
  1602. Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#3");
  1603. sw.GetStringBuilder ().Length = 0;
  1604. schemas[0].Write (sw);
  1605. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1606. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1607. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1608. " <xs:element name=\"{1}\" {2}type=\"xs:{1}\" />{0}" +
  1609. "</xs:schema>", Environment.NewLine, typeDesc.XmlType, ""),
  1610. sw.ToString (), typeDesc.Type.FullName + "#4");
  1611. }
  1612. }
  1613. [Test]
  1614. [Category ("NotDotNet")] // Mono bug ##77117
  1615. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1616. public void ExportXsdPrimitive_Object ()
  1617. {
  1618. XmlSchemas schemas = Export (typeof (object), "NSAnyType");
  1619. Assert.AreEqual (1, schemas.Count, "#1");
  1620. StringWriter sw = new StringWriter ();
  1621. schemas[0].Write (sw);
  1622. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1623. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1624. "<xs:schema xmlns:tns=\"NSAnyType\" elementFormDefault=\"qualified\" targetNamespace=\"NSAnyType\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1625. " <xs:element name=\"anyType\" />{0}" +
  1626. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  1627. schemas = Export (typeof (object));
  1628. Assert.AreEqual (1, schemas.Count, "#3");
  1629. sw.GetStringBuilder ().Length = 0;
  1630. schemas[0].Write (sw);
  1631. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1632. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1633. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1634. " <xs:element name=\"anyType\" />{0}" +
  1635. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  1636. }
  1637. [Test]
  1638. [Category ("NotDotNet")] // Mono bug ##77117
  1639. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1640. public void ExportXsdPrimitive_ByteArray ()
  1641. {
  1642. XmlSchemas schemas = Export (typeof (byte[]), "NSByteArray");
  1643. Assert.AreEqual (1, schemas.Count, "#1");
  1644. StringWriter sw = new StringWriter ();
  1645. schemas[0].Write (sw);
  1646. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1647. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1648. "<xs:schema xmlns:tns=\"NSByteArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSByteArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1649. " <xs:element name=\"base64Binary\" type=\"xs:base64Binary\" />{0}" +
  1650. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  1651. schemas = Export (typeof (byte[]));
  1652. Assert.AreEqual (1, schemas.Count, "#3");
  1653. sw.GetStringBuilder ().Length = 0;
  1654. schemas[0].Write (sw);
  1655. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1656. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1657. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1658. " <xs:element name=\"base64Binary\" type=\"xs:base64Binary\" />{0}" +
  1659. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  1660. }
  1661. [Test]
  1662. [Category ("NotDotNet")] // Mono bug ##77117
  1663. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1664. public void ExportXsdPrimitive_Arrays ()
  1665. {
  1666. ArrayList types = new ArrayList ();
  1667. types.Add (new TypeDescription (typeof (sbyte[]), true, "byte", "Byte"));
  1668. types.Add (new TypeDescription (typeof (bool[]), true, "boolean", "Boolean"));
  1669. types.Add (new TypeDescription (typeof (short[]), true, "short", "Short"));
  1670. types.Add (new TypeDescription (typeof (int[]), true, "int", "Int"));
  1671. types.Add (new TypeDescription (typeof (long[]), true, "long", "Long"));
  1672. types.Add (new TypeDescription (typeof (float[]), true, "float", "Float"));
  1673. types.Add (new TypeDescription (typeof (double[]), true, "double", "Double"));
  1674. types.Add (new TypeDescription (typeof (decimal[]), true, "decimal", "Decimal"));
  1675. types.Add (new TypeDescription (typeof (ushort[]), true, "unsignedShort", "UnsignedShort"));
  1676. types.Add (new TypeDescription (typeof (uint[]), true, "unsignedInt", "UnsignedInt"));
  1677. types.Add (new TypeDescription (typeof (ulong[]), true, "unsignedLong", "UnsignedLong"));
  1678. types.Add (new TypeDescription (typeof (DateTime[]), true, "dateTime", "DateTime"));
  1679. #if NET_2_0
  1680. types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName", true));
  1681. #else
  1682. types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName"));
  1683. #endif
  1684. types.Add (new TypeDescription (typeof (string[]), true, "string", "String", true));
  1685. foreach (TypeDescription typeDesc in types) {
  1686. XmlSchemas schemas = Export (typeDesc.Type, typeDesc.Type.Name);
  1687. Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1");
  1688. StringWriter sw = new StringWriter ();
  1689. schemas[0].Write (sw);
  1690. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1691. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1692. "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1693. " <xs:element name=\"ArrayOf{2}\" type=\"tns:ArrayOf{2}\" />{0}" +
  1694. " <xs:complexType name=\"ArrayOf{2}\">{0}" +
  1695. " <xs:sequence>{0}" +
  1696. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"{3}\" {5}type=\"{4}:{3}\" />{0}" +
  1697. " </xs:sequence>{0}" +
  1698. " </xs:complexType>{0}" +
  1699. "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.ArrayType, typeDesc.XmlType,
  1700. typeDesc.XsdType ? "xs" : "tns", typeDesc.IsNillable ? "nillable=\"true\" " : ""),
  1701. sw.ToString (), typeDesc.Type.FullName + "#2");
  1702. schemas = Export (typeDesc.Type);
  1703. Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#3");
  1704. sw.GetStringBuilder ().Length = 0;
  1705. schemas[0].Write (sw);
  1706. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1707. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1708. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1709. " <xs:element name=\"ArrayOf{1}\" type=\"ArrayOf{1}\" />{0}" +
  1710. " <xs:complexType name=\"ArrayOf{1}\">{0}" +
  1711. " <xs:sequence>{0}" +
  1712. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"{2}\" {4}type=\"{3}:{2}\" />{0}" +
  1713. " </xs:sequence>{0}" +
  1714. " </xs:complexType>{0}" +
  1715. "</xs:schema>", Environment.NewLine, typeDesc.ArrayType, typeDesc.XmlType,
  1716. typeDesc.XsdType ? "xs" : "tns", typeDesc.IsNillable ? "nillable=\"true\" " : ""),
  1717. sw.ToString (), typeDesc.Type.FullName + "#4");
  1718. }
  1719. }
  1720. [Test]
  1721. [Category ("NotDotNet")] // Mono bug ##77117
  1722. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1723. public void ExportXsdPrimitive_Object_Arrays ()
  1724. {
  1725. XmlSchemas schemas = Export (typeof (object[]), "NSArrayOfAnyType");
  1726. Assert.AreEqual (1, schemas.Count, "#1");
  1727. StringWriter sw = new StringWriter ();
  1728. schemas[0].Write (sw);
  1729. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1730. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1731. "<xs:schema xmlns:tns=\"NSArrayOfAnyType\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayOfAnyType\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1732. " <xs:element name=\"ArrayOfAnyType\" type=\"tns:ArrayOfAnyType\" />{0}" +
  1733. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  1734. " <xs:sequence>{0}" +
  1735. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
  1736. " </xs:sequence>{0}" +
  1737. " </xs:complexType>{0}" +
  1738. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  1739. schemas = Export (typeof (object[]));
  1740. Assert.AreEqual (1, schemas.Count, "#3");
  1741. sw.GetStringBuilder ().Length = 0;
  1742. schemas[0].Write (sw);
  1743. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1744. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1745. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1746. " <xs:element name=\"ArrayOfAnyType\" type=\"ArrayOfAnyType\" />{0}" +
  1747. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  1748. " <xs:sequence>{0}" +
  1749. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
  1750. " </xs:sequence>{0}" +
  1751. " </xs:complexType>{0}" +
  1752. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  1753. }
  1754. [Test]
  1755. public void ExportNonXsdPrimitive_Guid ()
  1756. {
  1757. XmlSchemas schemas = Export (typeof (Guid), "NSPrimGuid");
  1758. Assert.AreEqual (2, schemas.Count, "#1");
  1759. StringWriter sw = new StringWriter ();
  1760. schemas[0].Write (sw);
  1761. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1762. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1763. "<xs:schema xmlns:tns=\"NSPrimGuid\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimGuid\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1764. " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
  1765. " <xs:element name=\"guid\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:guid\" />{0}" +
  1766. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  1767. sw.GetStringBuilder ().Length = 0;
  1768. schemas[1].Write (sw);
  1769. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1770. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1771. "<xs:schema xmlns:tns=\"http://microsoft.com/wsdl/types/\" elementFormDefault=\"qualified\" targetNamespace=\"http://microsoft.com/wsdl/types/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1772. " <xs:simpleType name=\"guid\">{0}" +
  1773. " <xs:restriction base=\"xs:string\">{0}" +
  1774. " <xs:pattern value=\"[0-9a-fA-F]{{8}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{12}}\" />{0}" +
  1775. " </xs:restriction>{0}" +
  1776. " </xs:simpleType>{0}" +
  1777. "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
  1778. schemas = Export (typeof (Guid));
  1779. Assert.AreEqual (2, schemas.Count, "#4");
  1780. sw.GetStringBuilder ().Length = 0;
  1781. schemas[0].Write (sw);
  1782. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1783. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1784. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1785. " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
  1786. " <xs:element name=\"guid\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:guid\" />{0}" +
  1787. "</xs:schema>", Environment.NewLine), sw.ToString (), "#5");
  1788. sw.GetStringBuilder ().Length = 0;
  1789. schemas[1].Write (sw);
  1790. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1791. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1792. "<xs:schema xmlns:tns=\"http://microsoft.com/wsdl/types/\" elementFormDefault=\"qualified\" targetNamespace=\"http://microsoft.com/wsdl/types/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1793. " <xs:simpleType name=\"guid\">{0}" +
  1794. " <xs:restriction base=\"xs:string\">{0}" +
  1795. " <xs:pattern value=\"[0-9a-fA-F]{{8}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{4}}-[0-9a-fA-F]{{12}}\" />{0}" +
  1796. " </xs:restriction>{0}" +
  1797. " </xs:simpleType>{0}" +
  1798. "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
  1799. }
  1800. [Test]
  1801. public void ExportNonXsdPrimitive_Char ()
  1802. {
  1803. XmlSchemas schemas = Export (typeof (char), "NSPrimChar");
  1804. Assert.AreEqual (2, schemas.Count, "#1");
  1805. StringWriter sw = new StringWriter ();
  1806. schemas[0].Write (sw);
  1807. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1808. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1809. "<xs:schema xmlns:tns=\"NSPrimChar\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimChar\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1810. " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
  1811. " <xs:element name=\"char\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:char\" />{0}" +
  1812. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  1813. sw.GetStringBuilder ().Length = 0;
  1814. schemas[1].Write (sw);
  1815. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1816. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1817. "<xs:schema xmlns:tns=\"http://microsoft.com/wsdl/types/\" elementFormDefault=\"qualified\" targetNamespace=\"http://microsoft.com/wsdl/types/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1818. " <xs:simpleType name=\"char\">{0}" +
  1819. " <xs:restriction base=\"xs:unsignedShort\" />{0}" +
  1820. " </xs:simpleType>{0}" +
  1821. "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
  1822. schemas = Export (typeof (char));
  1823. Assert.AreEqual (2, schemas.Count, "#4");
  1824. sw.GetStringBuilder ().Length = 0;
  1825. schemas[0].Write (sw);
  1826. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1827. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1828. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1829. " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
  1830. " <xs:element name=\"char\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:char\" />{0}" +
  1831. "</xs:schema>", Environment.NewLine), sw.ToString (), "#5");
  1832. sw.GetStringBuilder ().Length = 0;
  1833. schemas[1].Write (sw);
  1834. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1835. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1836. "<xs:schema xmlns:tns=\"http://microsoft.com/wsdl/types/\" elementFormDefault=\"qualified\" targetNamespace=\"http://microsoft.com/wsdl/types/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1837. " <xs:simpleType name=\"char\">{0}" +
  1838. " <xs:restriction base=\"xs:unsignedShort\" />{0}" +
  1839. " </xs:simpleType>{0}" +
  1840. "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
  1841. }
  1842. public class Employee : IXmlSerializable
  1843. {
  1844. private string _firstName;
  1845. private string _lastName;
  1846. private string _address;
  1847. public virtual XmlSchema GetSchema ()
  1848. {
  1849. return null;
  1850. }
  1851. public void WriteXml (XmlWriter writer)
  1852. {
  1853. writer.WriteStartElement ("employee", "urn:devx-com");
  1854. writer.WriteAttributeString ("firstName", _firstName);
  1855. writer.WriteAttributeString ("lastName", _lastName);
  1856. writer.WriteAttributeString ("address", _address);
  1857. writer.WriteEndElement ();
  1858. }
  1859. public void ReadXml (XmlReader reader)
  1860. {
  1861. XmlNodeType type = reader.MoveToContent ();
  1862. if (type == XmlNodeType.Element && reader.LocalName == "employee") {
  1863. _firstName = reader["firstName"];
  1864. _lastName = reader["lastName"];
  1865. _address = reader["address"];
  1866. }
  1867. }
  1868. }
  1869. public class EmployeeSchema : IXmlSerializable
  1870. {
  1871. private string _firstName;
  1872. private string _lastName;
  1873. private string _address;
  1874. public virtual XmlSchema GetSchema ()
  1875. {
  1876. return CreateSchema ();
  1877. }
  1878. public void WriteXml (XmlWriter writer)
  1879. {
  1880. writer.WriteStartElement ("employee", "urn:devx-com");
  1881. writer.WriteAttributeString ("firstName", _firstName);
  1882. writer.WriteAttributeString ("lastName", _lastName);
  1883. writer.WriteAttributeString ("address", _address);
  1884. writer.WriteEndElement ();
  1885. }
  1886. public void ReadXml (XmlReader reader)
  1887. {
  1888. XmlNodeType type = reader.MoveToContent ();
  1889. if (type == XmlNodeType.Element && reader.LocalName == "employee") {
  1890. _firstName = reader["firstName"];
  1891. _lastName = reader["lastName"];
  1892. _address = reader["address"];
  1893. }
  1894. }
  1895. protected static XmlSchema CreateSchema ()
  1896. {
  1897. XmlSchema schema = new XmlSchema ();
  1898. schema.Id = "EmployeeSchema";
  1899. schema.TargetNamespace = "urn:types-devx-com";
  1900. XmlSchemaComplexType type = new XmlSchemaComplexType ();
  1901. type.Name = "employeeRoot";
  1902. XmlSchemaAttribute firstNameAttr = new XmlSchemaAttribute ();
  1903. firstNameAttr.Name = "firstName";
  1904. type.Attributes.Add (firstNameAttr);
  1905. XmlSchemaAttribute lastNameAttr = new XmlSchemaAttribute ();
  1906. lastNameAttr.Name = "lastName";
  1907. type.Attributes.Add (lastNameAttr);
  1908. XmlSchemaAttribute addressAttr = new XmlSchemaAttribute ();
  1909. addressAttr.Name = "address";
  1910. type.Attributes.Add (addressAttr);
  1911. XmlSchemaElement employeeElement = new XmlSchemaElement ();
  1912. employeeElement.Name = "employee";
  1913. XmlQualifiedName name = new XmlQualifiedName ("employeeRoot", "urn:types-devx-com");
  1914. employeeElement.SchemaTypeName = name;
  1915. schema.Items.Add (type);
  1916. schema.Items.Add (employeeElement);
  1917. return schema;
  1918. }
  1919. }
  1920. public class PrimitiveSchema : IXmlSerializable
  1921. {
  1922. private string _firstName;
  1923. private string _lastName;
  1924. private string _address;
  1925. public virtual XmlSchema GetSchema ()
  1926. {
  1927. XmlSchema schema = new XmlSchema ();
  1928. schema.Id = "LuckyNumberSchema";
  1929. XmlSchemaElement luckyNumberElement = new XmlSchemaElement ();
  1930. luckyNumberElement.Name = "LuckyNumber";
  1931. luckyNumberElement.SchemaTypeName = new XmlQualifiedName ("int", "http://www.w3.org/2001/XMLSchema");
  1932. schema.Items.Add (luckyNumberElement);
  1933. return schema;
  1934. }
  1935. public void WriteXml (XmlWriter writer)
  1936. {
  1937. writer.WriteStartElement ("employee", "urn:devx-com");
  1938. writer.WriteAttributeString ("firstName", _firstName);
  1939. writer.WriteAttributeString ("lastName", _lastName);
  1940. writer.WriteAttributeString ("address", _address);
  1941. writer.WriteEndElement ();
  1942. }
  1943. public void ReadXml (XmlReader reader)
  1944. {
  1945. XmlNodeType type = reader.MoveToContent ();
  1946. if (type == XmlNodeType.Element && reader.LocalName == "employee") {
  1947. _firstName = reader["firstName"];
  1948. _lastName = reader["lastName"];
  1949. _address = reader["address"];
  1950. }
  1951. }
  1952. }
  1953. public class MissingIDSchema : IXmlSerializable
  1954. {
  1955. private string _firstName;
  1956. private string _lastName;
  1957. private string _address;
  1958. public virtual XmlSchema GetSchema ()
  1959. {
  1960. XmlSchema schema = new XmlSchema ();
  1961. XmlSchemaElement luckyNumberElement = new XmlSchemaElement ();
  1962. luckyNumberElement.Name = "LuckyNumber";
  1963. luckyNumberElement.SchemaTypeName = new XmlQualifiedName ("int", "http://www.w3.org/2001/XMLSchema");
  1964. return schema;
  1965. }
  1966. public void WriteXml (XmlWriter writer)
  1967. {
  1968. writer.WriteStartElement ("employee", "urn:devx-com");
  1969. writer.WriteAttributeString ("firstName", _firstName);
  1970. writer.WriteAttributeString ("lastName", _lastName);
  1971. writer.WriteAttributeString ("address", _address);
  1972. writer.WriteEndElement ();
  1973. }
  1974. public void ReadXml (XmlReader reader)
  1975. {
  1976. XmlNodeType type = reader.MoveToContent ();
  1977. if (type == XmlNodeType.Element && reader.LocalName == "employee") {
  1978. _firstName = reader["firstName"];
  1979. _lastName = reader["lastName"];
  1980. _address = reader["address"];
  1981. }
  1982. }
  1983. }
  1984. #if NET_2_0
  1985. [XmlSchemaProvider ("CreateEmployeeSchema")]
  1986. #endif
  1987. public class EmployeeSchemaProvider : EmployeeSchema
  1988. {
  1989. #if NET_2_0
  1990. public static XmlQualifiedName CreateEmployeeSchema (XmlSchemaSet schemaSet)
  1991. {
  1992. schemaSet.Add (CreateSchema ());
  1993. return new XmlQualifiedName ("employeeRoot", "urn:types-devx-com");
  1994. }
  1995. #else
  1996. public override XmlSchema GetSchema ()
  1997. {
  1998. return null;
  1999. }
  2000. #endif
  2001. }
  2002. #if NET_2_0
  2003. [XmlSchemaProvider ("CreateLuckyNumberSchema")]
  2004. #endif
  2005. public class PrimitiveSchemaProvider : IXmlSerializable
  2006. {
  2007. #if NET_2_0
  2008. public static XmlQualifiedName CreateLuckyNumberSchema (XmlSchemaSet schemaSet)
  2009. {
  2010. XmlSchema schema = new XmlSchema ();
  2011. XmlSchemaElement luckyNumberElement = new XmlSchemaElement ();
  2012. luckyNumberElement.Name = "LuckyNumber";
  2013. XmlQualifiedName typeName = new XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema");
  2014. luckyNumberElement.SchemaTypeName = typeName;
  2015. schema.Items.Add (luckyNumberElement);
  2016. schemaSet.Add (schema);
  2017. return typeName;
  2018. }
  2019. #endif
  2020. public XmlSchema GetSchema ()
  2021. {
  2022. return null;
  2023. }
  2024. public void WriteXml (XmlWriter writer)
  2025. {
  2026. writer.WriteElementString ("LuckyNumber", "7");
  2027. }
  2028. public void ReadXml (XmlReader reader)
  2029. {
  2030. XmlNodeType type = reader.MoveToContent ();
  2031. if (type == XmlNodeType.Element && reader.LocalName == "LuckyNumber") {
  2032. }
  2033. }
  2034. }
  2035. private class TypeDescription
  2036. {
  2037. public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType) : this (type, xsdType, xmlType, arrayType, false)
  2038. {
  2039. }
  2040. public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType, bool isNillable)
  2041. {
  2042. _type = type;
  2043. _xsdType = xsdType;
  2044. _xmlType = xmlType;
  2045. _arrayType = arrayType;
  2046. _isNillable = isNillable;
  2047. }
  2048. public Type Type {
  2049. get { return _type; }
  2050. }
  2051. public string XmlType {
  2052. get { return _xmlType; }
  2053. }
  2054. public string ArrayType {
  2055. get { return _arrayType; }
  2056. }
  2057. public bool XsdType {
  2058. get { return _xsdType; }
  2059. }
  2060. public bool IsNillable {
  2061. get { return _isNillable; }
  2062. }
  2063. private Type _type;
  2064. private bool _xsdType;
  2065. private string _xmlType;
  2066. private string _arrayType;
  2067. private bool _isNillable;
  2068. }
  2069. public class StructContainer
  2070. {
  2071. public EnumDefaultValue Value;
  2072. public TimeSpan[] Times;
  2073. }
  2074. public class XmlSerializableContainer
  2075. {
  2076. public Employee Slave;
  2077. public EmployeeSchema SlaveSchema;
  2078. public EmployeeSchemaProvider SlaveSchemaProvider;
  2079. public PrimitiveSchema NativeSchema;
  2080. public PrimitiveSchemaProvider NativeSchemaProvider;
  2081. [XmlElement ("SlaveNamespace", Namespace = "urn:types-devx-com")]
  2082. public Employee SlaveNS;
  2083. [XmlElement ("SlaveSchemaNamespace", Namespace = "urn:types-devx-com")]
  2084. public EmployeeSchema SlaveSchemaNS;
  2085. [XmlElement ("SlaveSchemaProviderNamespace", Namespace = "urn:types-devx-com")]
  2086. public EmployeeSchemaProvider SlaveSchemaProviderNS;
  2087. [XmlElement ("NativeSchemaNamespace", Namespace = "urn:types-devx-com")]
  2088. public PrimitiveSchema NativeSchemaNS;
  2089. [XmlElement ("NativeSchemaProviderNamespace", Namespace = "urn:types-devx-com")]
  2090. public PrimitiveSchemaProvider NativeSchemaProviderNS;
  2091. [XmlElement (Namespace = "urn:types-devx-com")]
  2092. public Employee SlaveNSOnly;
  2093. [XmlElement (Namespace = "urn:types-devx-com")]
  2094. public EmployeeSchema SlaveSchemaNSOnly;
  2095. [XmlElement (Namespace = "urn:types-devx-com")]
  2096. public EmployeeSchemaProvider SlaveSchemaProviderNSOnly;
  2097. [XmlElement (Namespace = "urn:types-devx-com")]
  2098. public PrimitiveSchema NativeSchemaNSOnly;
  2099. [XmlElement (Namespace = "urn:types-devx-com")]
  2100. public PrimitiveSchemaProvider NativeSchemaProviderNSOnly;
  2101. }
  2102. }
  2103. }