XmlSchemaExporterTests.cs 103 KB

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