XmlSchemaExporterTests.cs 117 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662
  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! -> Of course. There is nothing strange. The test is rather strange.
  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. #if !NET_2_0
  1492. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1493. #endif
  1494. public void ExportXmlSerializable_SchemaProvider ()
  1495. {
  1496. XmlSchemas schemas = Export (typeof (EmployeeSchemaProvider), "NSEmployeeSchemaProvider");
  1497. //Assert.AreEqual (1, schemas.Count, "#1"); //# of returned schemas is checked in ExportXmlSerializable_SchemaProvider1
  1498. StringWriter sw = new StringWriter ();
  1499. schemas[0].Write (sw);
  1500. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1501. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1502. "<xs:schema xmlns:tns=\"NSEmployeeSchemaProvider\" elementFormDefault=\"qualified\" targetNamespace=\"NSEmployeeSchemaProvider\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1503. #if NET_2_0
  1504. " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
  1505. " <xs:element name=\"employeeRoot\" nillable=\"true\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
  1506. #else
  1507. " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
  1508. " <xs:element name=\"EmployeeSchemaProvider\" nillable=\"true\">{0}" +
  1509. " <xs:complexType>{0}" +
  1510. " <xs:sequence>{0}" +
  1511. " <xs:element ref=\"xs:schema\" />{0}" +
  1512. " <xs:any />{0}" +
  1513. " </xs:sequence>{0}" +
  1514. " </xs:complexType>{0}" +
  1515. " </xs:element>{0}" +
  1516. #endif
  1517. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  1518. schemas = Export (typeof (EmployeeSchemaProvider));
  1519. //Assert.AreEqual (1, schemas.Count, "#3");
  1520. sw.GetStringBuilder ().Length = 0;
  1521. schemas[0].Write (sw);
  1522. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1523. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1524. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1525. #if NET_2_0
  1526. " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
  1527. " <xs:element name=\"employeeRoot\" nillable=\"true\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
  1528. #else
  1529. " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
  1530. " <xs:element name=\"EmployeeSchemaProvider\" nillable=\"true\">{0}" +
  1531. " <xs:complexType>{0}" +
  1532. " <xs:sequence>{0}" +
  1533. " <xs:element ref=\"xs:schema\" />{0}" +
  1534. " <xs:any />{0}" +
  1535. " </xs:sequence>{0}" +
  1536. " </xs:complexType>{0}" +
  1537. " </xs:element>{0}" +
  1538. #endif
  1539. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  1540. schemas = Export (typeof (PrimitiveSchemaProvider), "NSPrimitiveSchemaProvider");
  1541. //Assert.AreEqual (1, schemas.Count, "#5");
  1542. sw.GetStringBuilder ().Length = 0;
  1543. schemas[0].Write (sw);
  1544. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1545. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1546. "<xs:schema xmlns:tns=\"NSPrimitiveSchemaProvider\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimitiveSchemaProvider\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1547. #if NET_2_0
  1548. //" <xs:import />{0}" +
  1549. " <xs:element name=\"int\" nillable=\"true\" type=\"xs:int\" />{0}" +
  1550. #else
  1551. " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
  1552. " <xs:element name=\"PrimitiveSchemaProvider\" nillable=\"true\">{0}" +
  1553. " <xs:complexType>{0}" +
  1554. " <xs:sequence>{0}" +
  1555. " <xs:element ref=\"xs:schema\" />{0}" +
  1556. " <xs:any />{0}" +
  1557. " </xs:sequence>{0}" +
  1558. " </xs:complexType>{0}" +
  1559. " </xs:element>{0}" +
  1560. #endif
  1561. "</xs:schema>", Environment.NewLine), sw.ToString ().Replace("<xs:import />" + Environment.NewLine, ""), "#6");
  1562. }
  1563. [Test]
  1564. #if NET_2_0
  1565. [Category ("NotWorking")] // support for XmlSchemaProvider is not implemented
  1566. #else
  1567. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1568. #endif
  1569. public void ExportXmlSerializable_SchemaProvider1 () {
  1570. XmlSchemas schemas = schemas = Export (typeof (PrimitiveSchemaProvider));
  1571. Assert.AreEqual (1, schemas.Count, "#1");
  1572. StringWriter sw = new StringWriter ();
  1573. schemas[0].Write (sw);
  1574. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1575. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1576. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1577. #if NET_2_0
  1578. " <xs:element name=\"int\" nillable=\"true\" type=\"xs:int\" />{0}" +
  1579. #else
  1580. " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
  1581. " <xs:element name=\"PrimitiveSchemaProvider\" nillable=\"true\">{0}" +
  1582. " <xs:complexType>{0}" +
  1583. " <xs:sequence>{0}" +
  1584. " <xs:element ref=\"xs:schema\" />{0}" +
  1585. " <xs:any />{0}" +
  1586. " </xs:sequence>{0}" +
  1587. " </xs:complexType>{0}" +
  1588. " </xs:element>{0}" +
  1589. #endif
  1590. "</xs:schema>", Environment.NewLine), sw.ToString (), "#8");
  1591. }
  1592. [Test]
  1593. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1594. #if NET_2_0
  1595. [Category ("NotWorking")] // support for XmlSchemaProvider is not implemented
  1596. #endif
  1597. public void ExportXmlSerializable_Container ()
  1598. {
  1599. XmlSchemas schemas = Export (typeof (XmlSerializableContainer), "NSXmlSerializableContainer");
  1600. Assert.AreEqual (3, schemas.Count, "#1");
  1601. StringWriter sw = new StringWriter ();
  1602. schemas[0].Write (sw);
  1603. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1604. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1605. "<xs:schema xmlns:tns=\"NSXmlSerializableContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSXmlSerializableContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1606. " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
  1607. " <xs:import namespace=\"urn:types-devx-com\" />{0}" +
  1608. #if NET_2_0
  1609. " <xs:import />{0}" +
  1610. #endif
  1611. " <xs:element name=\"XmlSerializableContainer\" nillable=\"true\" type=\"tns:XmlSerializableContainer\" />{0}" +
  1612. " <xs:complexType name=\"XmlSerializableContainer\">{0}" +
  1613. " <xs:sequence>{0}" +
  1614. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"Slave\">{0}" +
  1615. " <xs:complexType>{0}" +
  1616. " <xs:sequence>{0}" +
  1617. " <xs:element ref=\"xs:schema\" />{0}" +
  1618. " <xs:any />{0}" +
  1619. " </xs:sequence>{0}" +
  1620. " </xs:complexType>{0}" +
  1621. " </xs:element>{0}" +
  1622. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"SlaveSchema\">{0}" +
  1623. " <xs:complexType>{0}" +
  1624. " <xs:sequence>{0}" +
  1625. " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
  1626. " </xs:sequence>{0}" +
  1627. " </xs:complexType>{0}" +
  1628. " </xs:element>{0}" +
  1629. #if NET_2_0
  1630. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"SlaveSchemaProvider\" xmlns:q1=\"urn:types-devx-com\" type=\"q1:employeeRoot\" />{0}" +
  1631. #else
  1632. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"SlaveSchemaProvider\">{0}" +
  1633. " <xs:complexType>{0}" +
  1634. " <xs:sequence>{0}" +
  1635. " <xs:element ref=\"xs:schema\" />{0}" +
  1636. " <xs:any />{0}" +
  1637. " </xs:sequence>{0}" +
  1638. " </xs:complexType>{0}" +
  1639. " </xs:element>{0}" +
  1640. #endif
  1641. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"NativeSchema\">{0}" +
  1642. " <xs:complexType>{0}" +
  1643. " <xs:sequence>{0}" +
  1644. " <xs:any namespace=\"\" />{0}" +
  1645. " </xs:sequence>{0}" +
  1646. " </xs:complexType>{0}" +
  1647. " </xs:element>{0}" +
  1648. #if NET_2_0
  1649. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"NativeSchemaProvider\" type=\"xs:int\" />{0}" +
  1650. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q2=\"urn:types-devx-com\" ref=\"q2:SlaveNamespace\" />{0}" +
  1651. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q3=\"urn:types-devx-com\" ref=\"q3:SlaveSchemaNamespace\" />{0}" +
  1652. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q4=\"urn:types-devx-com\" ref=\"q4:SlaveSchemaProviderNamespace\" />{0}" +
  1653. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q5=\"urn:types-devx-com\" ref=\"q5:NativeSchemaNamespace\" />{0}" +
  1654. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q6=\"urn:types-devx-com\" ref=\"q6:NativeSchemaProviderNamespace\" />{0}" +
  1655. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q7=\"urn:types-devx-com\" ref=\"q7:SlaveNSOnly\" />{0}" +
  1656. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q8=\"urn:types-devx-com\" ref=\"q8:SlaveSchemaNSOnly\" />{0}" +
  1657. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q9=\"urn:types-devx-com\" ref=\"q9:SlaveSchemaProviderNSOnly\" />{0}" +
  1658. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q10=\"urn:types-devx-com\" ref=\"q10:NativeSchemaNSOnly\" />{0}" +
  1659. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q11=\"urn:types-devx-com\" ref=\"q11:NativeSchemaProviderNSOnly\" />{0}" +
  1660. #else
  1661. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" name=\"NativeSchemaProvider\">{0}" +
  1662. " <xs:complexType>{0}" +
  1663. " <xs:sequence>{0}" +
  1664. " <xs:element ref=\"xs:schema\" />{0}" +
  1665. " <xs:any />{0}" +
  1666. " </xs:sequence>{0}" +
  1667. " </xs:complexType>{0}" +
  1668. " </xs:element>{0}" +
  1669. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q1=\"urn:types-devx-com\" ref=\"q1:SlaveNamespace\" />{0}" +
  1670. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q2=\"urn:types-devx-com\" ref=\"q2:SlaveSchemaNamespace\" />{0}" +
  1671. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q3=\"urn:types-devx-com\" ref=\"q3:SlaveSchemaProviderNamespace\" />{0}" +
  1672. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q4=\"urn:types-devx-com\" ref=\"q4:NativeSchemaNamespace\" />{0}" +
  1673. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q5=\"urn:types-devx-com\" ref=\"q5:NativeSchemaProviderNamespace\" />{0}" +
  1674. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q6=\"urn:types-devx-com\" ref=\"q6:SlaveNSOnly\" />{0}" +
  1675. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q7=\"urn:types-devx-com\" ref=\"q7:SlaveSchemaNSOnly\" />{0}" +
  1676. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q8=\"urn:types-devx-com\" ref=\"q8:SlaveSchemaProviderNSOnly\" />{0}" +
  1677. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q9=\"urn:types-devx-com\" ref=\"q9:NativeSchemaNSOnly\" />{0}" +
  1678. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" xmlns:q10=\"urn:types-devx-com\" ref=\"q10:NativeSchemaProviderNSOnly\" />{0}" +
  1679. #endif
  1680. " </xs:sequence>{0}" +
  1681. " </xs:complexType>{0}" +
  1682. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  1683. sw.GetStringBuilder ().Length = 0;
  1684. schemas[1].Write (sw);
  1685. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1686. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1687. "<xs:schema xmlns:tns=\"urn:types-devx-com\" targetNamespace=\"urn:types-devx-com\" id=\"EmployeeSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1688. " <xs:import namespace=\"http://www.w3.org/2001/XMLSchema\" />{0}" +
  1689. #if NET_2_0
  1690. " <xs:import />{0}" +
  1691. #endif
  1692. " <xs:complexType name=\"employeeRoot\">{0}" +
  1693. " <xs:attribute name=\"firstName\" />{0}" +
  1694. " <xs:attribute name=\"lastName\" />{0}" +
  1695. " <xs:attribute name=\"address\" />{0}" +
  1696. " </xs:complexType>{0}" +
  1697. " <xs:element name=\"employee\" type=\"tns:employeeRoot\" />{0}" +
  1698. " <xs:element name=\"SlaveNamespace\">{0}" +
  1699. " <xs:complexType>{0}" +
  1700. " <xs:sequence>{0}" +
  1701. " <xs:element ref=\"xs:schema\" />{0}" +
  1702. " <xs:any />{0}" +
  1703. " </xs:sequence>{0}" +
  1704. " </xs:complexType>{0}" +
  1705. " </xs:element>{0}" +
  1706. " <xs:element name=\"SlaveSchemaNamespace\">{0}" +
  1707. " <xs:complexType>{0}" +
  1708. " <xs:sequence>{0}" +
  1709. " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
  1710. " </xs:sequence>{0}" +
  1711. " </xs:complexType>{0}" +
  1712. " </xs:element>{0}" +
  1713. #if NET_2_0
  1714. " <xs:element name=\"SlaveSchemaProviderNamespace\" type=\"tns:employeeRoot\" />{0}" +
  1715. #else
  1716. " <xs:element name=\"SlaveSchemaProviderNamespace\">{0}" +
  1717. " <xs:complexType>{0}" +
  1718. " <xs:sequence>{0}" +
  1719. " <xs:element ref=\"xs:schema\" />{0}" +
  1720. " <xs:any />{0}" +
  1721. " </xs:sequence>{0}" +
  1722. " </xs:complexType>{0}" +
  1723. " </xs:element>{0}" +
  1724. #endif
  1725. " <xs:element name=\"NativeSchemaNamespace\">{0}" +
  1726. " <xs:complexType>{0}" +
  1727. " <xs:sequence>{0}" +
  1728. " <xs:any namespace=\"\" />{0}" +
  1729. " </xs:sequence>{0}" +
  1730. " </xs:complexType>{0}" +
  1731. " </xs:element>{0}" +
  1732. #if NET_2_0
  1733. " <xs:element name=\"NativeSchemaProviderNamespace\" type=\"xs:int\" />{0}" +
  1734. #else
  1735. " <xs:element name=\"NativeSchemaProviderNamespace\">{0}" +
  1736. " <xs:complexType>{0}" +
  1737. " <xs:sequence>{0}" +
  1738. " <xs:element ref=\"xs:schema\" />{0}" +
  1739. " <xs:any />{0}" +
  1740. " </xs:sequence>{0}" +
  1741. " </xs:complexType>{0}" +
  1742. " </xs:element>{0}" +
  1743. #endif
  1744. " <xs:element name=\"SlaveNSOnly\">{0}" +
  1745. " <xs:complexType>{0}" +
  1746. " <xs:sequence>{0}" +
  1747. " <xs:element ref=\"xs:schema\" />{0}" +
  1748. " <xs:any />{0}" +
  1749. " </xs:sequence>{0}" +
  1750. " </xs:complexType>{0}" +
  1751. " </xs:element>{0}" +
  1752. " <xs:element name=\"SlaveSchemaNSOnly\">{0}" +
  1753. " <xs:complexType>{0}" +
  1754. " <xs:sequence>{0}" +
  1755. " <xs:any namespace=\"urn:types-devx-com\" />{0}" +
  1756. " </xs:sequence>{0}" +
  1757. " </xs:complexType>{0}" +
  1758. " </xs:element>{0}" +
  1759. #if NET_2_0
  1760. " <xs:element name=\"SlaveSchemaProviderNSOnly\" type=\"tns:employeeRoot\" />{0}" +
  1761. #else
  1762. " <xs:element name=\"SlaveSchemaProviderNSOnly\">{0}" +
  1763. " <xs:complexType>{0}" +
  1764. " <xs:sequence>{0}" +
  1765. " <xs:element ref=\"xs:schema\" />{0}" +
  1766. " <xs:any />{0}" +
  1767. " </xs:sequence>{0}" +
  1768. " </xs:complexType>{0}" +
  1769. " </xs:element>{0}" +
  1770. #endif
  1771. " <xs:element name=\"NativeSchemaNSOnly\">{0}" +
  1772. " <xs:complexType>{0}" +
  1773. " <xs:sequence>{0}" +
  1774. " <xs:any namespace=\"\" />{0}" +
  1775. " </xs:sequence>{0}" +
  1776. " </xs:complexType>{0}" +
  1777. " </xs:element>{0}" +
  1778. #if NET_2_0
  1779. " <xs:element name=\"NativeSchemaProviderNSOnly\" type=\"xs:int\" />{0}" +
  1780. #else
  1781. " <xs:element name=\"NativeSchemaProviderNSOnly\">{0}" +
  1782. " <xs:complexType>{0}" +
  1783. " <xs:sequence>{0}" +
  1784. " <xs:element ref=\"xs:schema\" />{0}" +
  1785. " <xs:any />{0}" +
  1786. " </xs:sequence>{0}" +
  1787. " </xs:complexType>{0}" +
  1788. " </xs:element>{0}" +
  1789. #endif
  1790. "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
  1791. sw.GetStringBuilder ().Length = 0;
  1792. schemas[2].Write (sw);
  1793. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1794. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1795. "<xs:schema id=\"LuckyNumberSchema\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1796. " <xs:element name=\"LuckyNumber\" type=\"xs:int\" />{0}" +
  1797. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  1798. }
  1799. [Test]
  1800. public void ExportXsdPrimitive ()
  1801. {
  1802. ArrayList types = new ArrayList ();
  1803. types.Add (new TypeDescription (typeof (byte), true, "unsignedByte", "Byte"));
  1804. types.Add (new TypeDescription (typeof (sbyte), true, "byte", "Byte"));
  1805. types.Add (new TypeDescription (typeof (bool), true, "boolean", "Boolean"));
  1806. types.Add (new TypeDescription (typeof (short), true, "short", "Short"));
  1807. types.Add (new TypeDescription (typeof (int), true, "int", "Int"));
  1808. types.Add (new TypeDescription (typeof (long), true, "long", "Long"));
  1809. types.Add (new TypeDescription (typeof (float), true, "float", "Float"));
  1810. types.Add (new TypeDescription (typeof (double), true, "double", "Double"));
  1811. types.Add (new TypeDescription (typeof (decimal), true, "decimal", "Decimal"));
  1812. types.Add (new TypeDescription (typeof (ushort), true, "unsignedShort", "UnsignedShort"));
  1813. types.Add (new TypeDescription (typeof (uint), true, "unsignedInt", "UnsignedInt"));
  1814. types.Add (new TypeDescription (typeof (ulong), true, "unsignedLong", "UnsignedLong"));
  1815. types.Add (new TypeDescription (typeof (DateTime), true, "dateTime", "DateTime"));
  1816. #if NET_2_0
  1817. types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName", true));
  1818. #else
  1819. types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName"));
  1820. #endif
  1821. types.Add (new TypeDescription (typeof (string), true, "string", "String", true));
  1822. foreach (TypeDescription typeDesc in types) {
  1823. XmlSchemas schemas = Export (typeDesc.Type, typeDesc.Type.Name);
  1824. Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1");
  1825. StringWriter sw = new StringWriter ();
  1826. schemas[0].Write (sw);
  1827. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1828. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1829. "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1830. " <xs:element name=\"{2}\" {3}type=\"xs:{2}\" />{0}" +
  1831. "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.XmlType,
  1832. typeDesc.IsNillable ? "nillable=\"true\" " : ""),
  1833. sw.ToString (), typeDesc.Type.FullName + "#2");
  1834. schemas = Export (typeDesc.Type);
  1835. Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#3");
  1836. sw.GetStringBuilder ().Length = 0;
  1837. schemas[0].Write (sw);
  1838. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1839. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1840. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1841. " <xs:element name=\"{1}\" {2}type=\"xs:{1}\" />{0}" +
  1842. "</xs:schema>", Environment.NewLine, typeDesc.XmlType,
  1843. typeDesc.IsNillable ? "nillable=\"true\" " : ""),
  1844. sw.ToString (), typeDesc.Type.FullName + "#4");
  1845. }
  1846. }
  1847. [Test]
  1848. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1849. public void ExportXsdPrimitive_Object ()
  1850. {
  1851. XmlSchemas schemas = Export (typeof (object), "NSAnyType");
  1852. Assert.AreEqual (1, schemas.Count, "#1");
  1853. StringWriter sw = new StringWriter ();
  1854. schemas[0].Write (sw);
  1855. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1856. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1857. "<xs:schema xmlns:tns=\"NSAnyType\" elementFormDefault=\"qualified\" targetNamespace=\"NSAnyType\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1858. " <xs:element name=\"anyType\" nillable=\"true\" />{0}" +
  1859. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  1860. schemas = Export (typeof (object));
  1861. Assert.AreEqual (1, schemas.Count, "#3");
  1862. sw.GetStringBuilder ().Length = 0;
  1863. schemas[0].Write (sw);
  1864. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1865. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1866. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1867. " <xs:element name=\"anyType\" nillable=\"true\" />{0}" +
  1868. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  1869. }
  1870. [Test]
  1871. public void ExportXsdPrimitive_ByteArray ()
  1872. {
  1873. XmlSchemas schemas = Export (typeof (byte[]), "NSByteArray");
  1874. Assert.AreEqual (1, schemas.Count, "#1");
  1875. StringWriter sw = new StringWriter ();
  1876. schemas[0].Write (sw);
  1877. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1878. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1879. "<xs:schema xmlns:tns=\"NSByteArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSByteArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1880. " <xs:element name=\"base64Binary\" nillable=\"true\" type=\"xs:base64Binary\" />{0}" +
  1881. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  1882. schemas = Export (typeof (byte[]));
  1883. Assert.AreEqual (1, schemas.Count, "#3");
  1884. sw.GetStringBuilder ().Length = 0;
  1885. schemas[0].Write (sw);
  1886. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1887. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1888. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1889. " <xs:element name=\"base64Binary\" nillable=\"true\" type=\"xs:base64Binary\" />{0}" +
  1890. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  1891. }
  1892. [Test]
  1893. public void ExportXsdPrimitive_Arrays ()
  1894. {
  1895. ArrayList types = new ArrayList ();
  1896. types.Add (new TypeDescription (typeof (sbyte[]), true, "byte", "Byte", true));
  1897. types.Add (new TypeDescription (typeof (bool[]), true, "boolean", "Boolean", true));
  1898. types.Add (new TypeDescription (typeof (short[]), true, "short", "Short", true));
  1899. types.Add (new TypeDescription (typeof (int[]), true, "int", "Int", true));
  1900. types.Add (new TypeDescription (typeof (long[]), true, "long", "Long", true));
  1901. types.Add (new TypeDescription (typeof (float[]), true, "float", "Float", true));
  1902. types.Add (new TypeDescription (typeof (double[]), true, "double", "Double", true));
  1903. types.Add (new TypeDescription (typeof (decimal[]), true, "decimal", "Decimal", true));
  1904. types.Add (new TypeDescription (typeof (ushort[]), true, "unsignedShort", "UnsignedShort", true));
  1905. types.Add (new TypeDescription (typeof (uint[]), true, "unsignedInt", "UnsignedInt", true));
  1906. types.Add (new TypeDescription (typeof (ulong[]), true, "unsignedLong", "UnsignedLong", true));
  1907. types.Add (new TypeDescription (typeof (DateTime[]), true, "dateTime", "DateTime", true));
  1908. #if NET_2_0
  1909. types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName", true, true));
  1910. #else
  1911. types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName", true));
  1912. #endif
  1913. types.Add (new TypeDescription (typeof (string[]), true, "string", "String", true, true));
  1914. foreach (TypeDescription typeDesc in types) {
  1915. XmlSchemas schemas = Export (typeDesc.Type, typeDesc.Type.Name);
  1916. Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1");
  1917. StringWriter sw = new StringWriter ();
  1918. schemas[0].Write (sw);
  1919. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1920. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1921. "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1922. " <xs:element name=\"ArrayOf{2}\" {5}type=\"tns:ArrayOf{2}\" />{0}" +
  1923. " <xs:complexType name=\"ArrayOf{2}\">{0}" +
  1924. " <xs:sequence>{0}" +
  1925. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"{3}\" {6}type=\"{4}:{3}\" />{0}" +
  1926. " </xs:sequence>{0}" +
  1927. " </xs:complexType>{0}" +
  1928. "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.ArrayType, typeDesc.XmlType,
  1929. typeDesc.XsdType ? "xs" : "tns", typeDesc.IsNillable ? "nillable=\"true\" " : "",
  1930. typeDesc.IsElementNillable ? "nillable=\"true\" " : ""),
  1931. sw.ToString (), typeDesc.Type.FullName + "#2" + "|" + typeDesc.IsNillable);
  1932. schemas = Export (typeDesc.Type);
  1933. Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#3");
  1934. sw.GetStringBuilder ().Length = 0;
  1935. schemas[0].Write (sw);
  1936. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1937. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1938. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1939. " <xs:element name=\"ArrayOf{1}\" {4}type=\"ArrayOf{1}\" />{0}" +
  1940. " <xs:complexType name=\"ArrayOf{1}\">{0}" +
  1941. " <xs:sequence>{0}" +
  1942. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"{2}\" {5}type=\"{3}:{2}\" />{0}" +
  1943. " </xs:sequence>{0}" +
  1944. " </xs:complexType>{0}" +
  1945. "</xs:schema>", Environment.NewLine, typeDesc.ArrayType, typeDesc.XmlType,
  1946. typeDesc.XsdType ? "xs" : "tns", typeDesc.IsNillable ? "nillable=\"true\" " : "",
  1947. typeDesc.IsElementNillable ? "nillable=\"true\" " : ""),
  1948. sw.ToString (), typeDesc.Type.FullName + "#4");
  1949. }
  1950. }
  1951. [Test]
  1952. public void ExportXsdPrimitive_Object_Arrays ()
  1953. {
  1954. XmlSchemas schemas = Export (typeof (object[]), "NSArrayOfAnyType");
  1955. Assert.AreEqual (1, schemas.Count, "#1");
  1956. StringWriter sw = new StringWriter ();
  1957. schemas[0].Write (sw);
  1958. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1959. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1960. "<xs:schema xmlns:tns=\"NSArrayOfAnyType\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayOfAnyType\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1961. " <xs:element name=\"ArrayOfAnyType\" nillable=\"true\" type=\"tns:ArrayOfAnyType\" />{0}" +
  1962. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  1963. " <xs:sequence>{0}" +
  1964. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
  1965. " </xs:sequence>{0}" +
  1966. " </xs:complexType>{0}" +
  1967. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  1968. schemas = Export (typeof (object[]));
  1969. Assert.AreEqual (1, schemas.Count, "#3");
  1970. sw.GetStringBuilder ().Length = 0;
  1971. schemas[0].Write (sw);
  1972. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1973. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1974. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1975. " <xs:element name=\"ArrayOfAnyType\" nillable=\"true\" type=\"ArrayOfAnyType\" />{0}" +
  1976. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  1977. " <xs:sequence>{0}" +
  1978. " <xs:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"anyType\" nillable=\"true\" />{0}" +
  1979. " </xs:sequence>{0}" +
  1980. " </xs:complexType>{0}" +
  1981. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  1982. }
  1983. [Test]
  1984. public void ExportNonXsdPrimitive_Guid ()
  1985. {
  1986. XmlSchemas schemas = Export (typeof (Guid), "NSPrimGuid");
  1987. Assert.AreEqual (2, schemas.Count, "#1");
  1988. StringWriter sw = new StringWriter ();
  1989. schemas[0].Write (sw);
  1990. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1991. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  1992. "<xs:schema xmlns:tns=\"NSPrimGuid\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimGuid\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  1993. " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
  1994. " <xs:element name=\"guid\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:guid\" />{0}" +
  1995. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  1996. sw.GetStringBuilder ().Length = 0;
  1997. schemas[1].Write (sw);
  1998. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  1999. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  2000. "<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}" +
  2001. " <xs:simpleType name=\"guid\">{0}" +
  2002. " <xs:restriction base=\"xs:string\">{0}" +
  2003. " <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}" +
  2004. " </xs:restriction>{0}" +
  2005. " </xs:simpleType>{0}" +
  2006. "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
  2007. schemas = Export (typeof (Guid));
  2008. Assert.AreEqual (2, schemas.Count, "#4");
  2009. sw.GetStringBuilder ().Length = 0;
  2010. schemas[0].Write (sw);
  2011. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  2012. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  2013. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  2014. " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
  2015. " <xs:element name=\"guid\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:guid\" />{0}" +
  2016. "</xs:schema>", Environment.NewLine), sw.ToString (), "#5");
  2017. sw.GetStringBuilder ().Length = 0;
  2018. schemas[1].Write (sw);
  2019. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  2020. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  2021. "<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}" +
  2022. " <xs:simpleType name=\"guid\">{0}" +
  2023. " <xs:restriction base=\"xs:string\">{0}" +
  2024. " <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}" +
  2025. " </xs:restriction>{0}" +
  2026. " </xs:simpleType>{0}" +
  2027. "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
  2028. }
  2029. [Test]
  2030. public void ExportNonXsdPrimitive_Char ()
  2031. {
  2032. XmlSchemas schemas = Export (typeof (char), "NSPrimChar");
  2033. Assert.AreEqual (2, schemas.Count, "#1");
  2034. StringWriter sw = new StringWriter ();
  2035. schemas[0].Write (sw);
  2036. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  2037. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  2038. "<xs:schema xmlns:tns=\"NSPrimChar\" elementFormDefault=\"qualified\" targetNamespace=\"NSPrimChar\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  2039. " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
  2040. " <xs:element name=\"char\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:char\" />{0}" +
  2041. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  2042. sw.GetStringBuilder ().Length = 0;
  2043. schemas[1].Write (sw);
  2044. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  2045. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  2046. "<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}" +
  2047. " <xs:simpleType name=\"char\">{0}" +
  2048. " <xs:restriction base=\"xs:unsignedShort\" />{0}" +
  2049. " </xs:simpleType>{0}" +
  2050. "</xs:schema>", Environment.NewLine), sw.ToString (), "#3");
  2051. schemas = Export (typeof (char));
  2052. Assert.AreEqual (2, schemas.Count, "#4");
  2053. sw.GetStringBuilder ().Length = 0;
  2054. schemas[0].Write (sw);
  2055. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  2056. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  2057. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  2058. " <xs:import namespace=\"http://microsoft.com/wsdl/types/\" />{0}" +
  2059. " <xs:element name=\"char\" xmlns:q1=\"http://microsoft.com/wsdl/types/\" type=\"q1:char\" />{0}" +
  2060. "</xs:schema>", Environment.NewLine), sw.ToString (), "#5");
  2061. sw.GetStringBuilder ().Length = 0;
  2062. schemas[1].Write (sw);
  2063. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  2064. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  2065. "<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}" +
  2066. " <xs:simpleType name=\"char\">{0}" +
  2067. " <xs:restriction base=\"xs:unsignedShort\" />{0}" +
  2068. " </xs:simpleType>{0}" +
  2069. "</xs:schema>", Environment.NewLine), sw.ToString (), "#6");
  2070. }
  2071. public class Employee : IXmlSerializable
  2072. {
  2073. private string _firstName;
  2074. private string _lastName;
  2075. private string _address;
  2076. public virtual XmlSchema GetSchema ()
  2077. {
  2078. return null;
  2079. }
  2080. public void WriteXml (XmlWriter writer)
  2081. {
  2082. writer.WriteStartElement ("employee", "urn:devx-com");
  2083. writer.WriteAttributeString ("firstName", _firstName);
  2084. writer.WriteAttributeString ("lastName", _lastName);
  2085. writer.WriteAttributeString ("address", _address);
  2086. writer.WriteEndElement ();
  2087. }
  2088. public void ReadXml (XmlReader reader)
  2089. {
  2090. XmlNodeType type = reader.MoveToContent ();
  2091. if (type == XmlNodeType.Element && reader.LocalName == "employee") {
  2092. _firstName = reader["firstName"];
  2093. _lastName = reader["lastName"];
  2094. _address = reader["address"];
  2095. }
  2096. }
  2097. }
  2098. public class EmployeeSchema : IXmlSerializable
  2099. {
  2100. private string _firstName;
  2101. private string _lastName;
  2102. private string _address;
  2103. public virtual XmlSchema GetSchema ()
  2104. {
  2105. return CreateSchema ();
  2106. }
  2107. public void WriteXml (XmlWriter writer)
  2108. {
  2109. writer.WriteStartElement ("employee", "urn:devx-com");
  2110. writer.WriteAttributeString ("firstName", _firstName);
  2111. writer.WriteAttributeString ("lastName", _lastName);
  2112. writer.WriteAttributeString ("address", _address);
  2113. writer.WriteEndElement ();
  2114. }
  2115. public void ReadXml (XmlReader reader)
  2116. {
  2117. XmlNodeType type = reader.MoveToContent ();
  2118. if (type == XmlNodeType.Element && reader.LocalName == "employee") {
  2119. _firstName = reader["firstName"];
  2120. _lastName = reader["lastName"];
  2121. _address = reader["address"];
  2122. }
  2123. }
  2124. protected static XmlSchema CreateSchema ()
  2125. {
  2126. XmlSchema schema = new XmlSchema ();
  2127. schema.Id = "EmployeeSchema";
  2128. schema.TargetNamespace = "urn:types-devx-com";
  2129. XmlSchemaComplexType type = new XmlSchemaComplexType ();
  2130. type.Name = "employeeRoot";
  2131. XmlSchemaAttribute firstNameAttr = new XmlSchemaAttribute ();
  2132. firstNameAttr.Name = "firstName";
  2133. type.Attributes.Add (firstNameAttr);
  2134. XmlSchemaAttribute lastNameAttr = new XmlSchemaAttribute ();
  2135. lastNameAttr.Name = "lastName";
  2136. type.Attributes.Add (lastNameAttr);
  2137. XmlSchemaAttribute addressAttr = new XmlSchemaAttribute ();
  2138. addressAttr.Name = "address";
  2139. type.Attributes.Add (addressAttr);
  2140. XmlSchemaElement employeeElement = new XmlSchemaElement ();
  2141. employeeElement.Name = "employee";
  2142. XmlQualifiedName name = new XmlQualifiedName ("employeeRoot", "urn:types-devx-com");
  2143. employeeElement.SchemaTypeName = name;
  2144. schema.Items.Add (type);
  2145. schema.Items.Add (employeeElement);
  2146. return schema;
  2147. }
  2148. }
  2149. public class PrimitiveSchema : IXmlSerializable
  2150. {
  2151. private string _firstName;
  2152. private string _lastName;
  2153. private string _address;
  2154. public virtual XmlSchema GetSchema ()
  2155. {
  2156. XmlSchema schema = new XmlSchema ();
  2157. schema.Id = "LuckyNumberSchema";
  2158. XmlSchemaElement luckyNumberElement = new XmlSchemaElement ();
  2159. luckyNumberElement.Name = "LuckyNumber";
  2160. luckyNumberElement.SchemaTypeName = new XmlQualifiedName ("int", "http://www.w3.org/2001/XMLSchema");
  2161. schema.Items.Add (luckyNumberElement);
  2162. return schema;
  2163. }
  2164. public void WriteXml (XmlWriter writer)
  2165. {
  2166. writer.WriteStartElement ("employee", "urn:devx-com");
  2167. writer.WriteAttributeString ("firstName", _firstName);
  2168. writer.WriteAttributeString ("lastName", _lastName);
  2169. writer.WriteAttributeString ("address", _address);
  2170. writer.WriteEndElement ();
  2171. }
  2172. public void ReadXml (XmlReader reader)
  2173. {
  2174. XmlNodeType type = reader.MoveToContent ();
  2175. if (type == XmlNodeType.Element && reader.LocalName == "employee") {
  2176. _firstName = reader["firstName"];
  2177. _lastName = reader["lastName"];
  2178. _address = reader["address"];
  2179. }
  2180. }
  2181. }
  2182. public class MissingIDSchema : IXmlSerializable
  2183. {
  2184. private string _firstName;
  2185. private string _lastName;
  2186. private string _address;
  2187. public virtual XmlSchema GetSchema ()
  2188. {
  2189. XmlSchema schema = new XmlSchema ();
  2190. XmlSchemaElement luckyNumberElement = new XmlSchemaElement ();
  2191. luckyNumberElement.Name = "LuckyNumber";
  2192. luckyNumberElement.SchemaTypeName = new XmlQualifiedName ("int", "http://www.w3.org/2001/XMLSchema");
  2193. return schema;
  2194. }
  2195. public void WriteXml (XmlWriter writer)
  2196. {
  2197. writer.WriteStartElement ("employee", "urn:devx-com");
  2198. writer.WriteAttributeString ("firstName", _firstName);
  2199. writer.WriteAttributeString ("lastName", _lastName);
  2200. writer.WriteAttributeString ("address", _address);
  2201. writer.WriteEndElement ();
  2202. }
  2203. public void ReadXml (XmlReader reader)
  2204. {
  2205. XmlNodeType type = reader.MoveToContent ();
  2206. if (type == XmlNodeType.Element && reader.LocalName == "employee") {
  2207. _firstName = reader["firstName"];
  2208. _lastName = reader["lastName"];
  2209. _address = reader["address"];
  2210. }
  2211. }
  2212. }
  2213. #if NET_2_0
  2214. [XmlSchemaProvider ("CreateEmployeeSchema")]
  2215. #endif
  2216. public class EmployeeSchemaProvider : EmployeeSchema
  2217. {
  2218. #if NET_2_0
  2219. public static XmlQualifiedName CreateEmployeeSchema (XmlSchemaSet schemaSet)
  2220. {
  2221. schemaSet.Add (CreateSchema ());
  2222. return new XmlQualifiedName ("employeeRoot", "urn:types-devx-com");
  2223. }
  2224. #else
  2225. public override XmlSchema GetSchema ()
  2226. {
  2227. return null;
  2228. }
  2229. #endif
  2230. }
  2231. #if NET_2_0
  2232. [XmlSchemaProvider ("CreateLuckyNumberSchema")]
  2233. #endif
  2234. public class PrimitiveSchemaProvider : IXmlSerializable
  2235. {
  2236. #if NET_2_0
  2237. public static XmlQualifiedName CreateLuckyNumberSchema (XmlSchemaSet schemaSet)
  2238. {
  2239. XmlSchema schema = new XmlSchema ();
  2240. XmlSchemaElement luckyNumberElement = new XmlSchemaElement ();
  2241. luckyNumberElement.Name = "LuckyNumber";
  2242. XmlQualifiedName typeName = new XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema");
  2243. luckyNumberElement.SchemaTypeName = typeName;
  2244. schema.Items.Add (luckyNumberElement);
  2245. schemaSet.Add (schema);
  2246. return typeName;
  2247. }
  2248. #endif
  2249. public XmlSchema GetSchema ()
  2250. {
  2251. return null;
  2252. }
  2253. public void WriteXml (XmlWriter writer)
  2254. {
  2255. writer.WriteElementString ("LuckyNumber", "7");
  2256. }
  2257. public void ReadXml (XmlReader reader)
  2258. {
  2259. XmlNodeType type = reader.MoveToContent ();
  2260. if (type == XmlNodeType.Element && reader.LocalName == "LuckyNumber") {
  2261. }
  2262. }
  2263. }
  2264. private class TypeDescription
  2265. {
  2266. public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType) : this (type, xsdType, xmlType, arrayType, false)
  2267. {
  2268. }
  2269. public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType, bool isNillable) :
  2270. this (type, xsdType, xmlType, arrayType, isNillable, false)
  2271. {
  2272. }
  2273. public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType, bool isNillable, bool isElementNillable)
  2274. {
  2275. _type = type;
  2276. _xsdType = xsdType;
  2277. _xmlType = xmlType;
  2278. _arrayType = arrayType;
  2279. _isNillable = isNillable;
  2280. _isElementNillable = isElementNillable;
  2281. }
  2282. public Type Type {
  2283. get { return _type; }
  2284. }
  2285. public string XmlType {
  2286. get { return _xmlType; }
  2287. }
  2288. public string ArrayType {
  2289. get { return _arrayType; }
  2290. }
  2291. public bool XsdType {
  2292. get { return _xsdType; }
  2293. }
  2294. public bool IsNillable {
  2295. get { return _isNillable; }
  2296. }
  2297. public bool IsElementNillable {
  2298. get { return _isElementNillable; }
  2299. }
  2300. private Type _type;
  2301. private bool _xsdType;
  2302. private string _xmlType;
  2303. private string _arrayType;
  2304. private bool _isNillable;
  2305. private bool _isElementNillable;
  2306. }
  2307. public class StructContainer
  2308. {
  2309. public EnumDefaultValue Value;
  2310. public TimeSpan[] Times;
  2311. }
  2312. public class XmlSerializableContainer
  2313. {
  2314. public Employee Slave;
  2315. public EmployeeSchema SlaveSchema;
  2316. public EmployeeSchemaProvider SlaveSchemaProvider;
  2317. public PrimitiveSchema NativeSchema;
  2318. public PrimitiveSchemaProvider NativeSchemaProvider;
  2319. [XmlElement ("SlaveNamespace", Namespace = "urn:types-devx-com")]
  2320. public Employee SlaveNS;
  2321. [XmlElement ("SlaveSchemaNamespace", Namespace = "urn:types-devx-com")]
  2322. public EmployeeSchema SlaveSchemaNS;
  2323. [XmlElement ("SlaveSchemaProviderNamespace", Namespace = "urn:types-devx-com")]
  2324. public EmployeeSchemaProvider SlaveSchemaProviderNS;
  2325. [XmlElement ("NativeSchemaNamespace", Namespace = "urn:types-devx-com")]
  2326. public PrimitiveSchema NativeSchemaNS;
  2327. [XmlElement ("NativeSchemaProviderNamespace", Namespace = "urn:types-devx-com")]
  2328. public PrimitiveSchemaProvider NativeSchemaProviderNS;
  2329. [XmlElement (Namespace = "urn:types-devx-com")]
  2330. public Employee SlaveNSOnly;
  2331. [XmlElement (Namespace = "urn:types-devx-com")]
  2332. public EmployeeSchema SlaveSchemaNSOnly;
  2333. [XmlElement (Namespace = "urn:types-devx-com")]
  2334. public EmployeeSchemaProvider SlaveSchemaProviderNSOnly;
  2335. [XmlElement (Namespace = "urn:types-devx-com")]
  2336. public PrimitiveSchema NativeSchemaNSOnly;
  2337. [XmlElement (Namespace = "urn:types-devx-com")]
  2338. public PrimitiveSchemaProvider NativeSchemaProviderNSOnly;
  2339. }
  2340. }
  2341. }