XmlSchemaExporterTests.cs 117 KB

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