XmlSchemaExporterTests.cs 117 KB

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