XmlSchemaExporterTests.cs 116 KB

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