SoapSchemaExporterTests.cs 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  1. //
  2. // System.Xml.Serialization.SoapSchemaExporterTests
  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 SoapSchemaExporterTests
  22. {
  23. private XmlSchemas Export (Type type)
  24. {
  25. return Export (type, string.Empty);
  26. }
  27. private XmlSchemas Export (Type type, string defaultNamespace)
  28. {
  29. SoapReflectionImporter ri = new SoapReflectionImporter (defaultNamespace);
  30. XmlSchemas schemas = new XmlSchemas ();
  31. SoapSchemaExporter sx = new SoapSchemaExporter (schemas);
  32. XmlTypeMapping tm = ri.ImportTypeMapping (type);
  33. sx.ExportTypeMapping (tm);
  34. return schemas;
  35. }
  36. private XmlSchemas Export (Type type, SoapAttributeOverrides overrides)
  37. {
  38. return Export (type, overrides, string.Empty);
  39. }
  40. private XmlSchemas Export (Type type, SoapAttributeOverrides overrides, string defaultNamespace)
  41. {
  42. SoapReflectionImporter ri = new SoapReflectionImporter (overrides, defaultNamespace);
  43. XmlSchemas schemas = new XmlSchemas ();
  44. SoapSchemaExporter sx = new SoapSchemaExporter (schemas);
  45. XmlTypeMapping tm = ri.ImportTypeMapping (type);
  46. sx.ExportTypeMapping (tm);
  47. return schemas;
  48. }
  49. [Test]
  50. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  51. public void ExportStruct ()
  52. {
  53. XmlSchemas schemas = Export (typeof (TimeSpan), "NSTimeSpan");
  54. Assert.AreEqual (1, schemas.Count, "#1");
  55. StringWriter sw = new StringWriter ();
  56. schemas[0].Write (sw);
  57. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  58. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  59. #if NET_2_0
  60. "<xs:schema xmlns:tns=\"NSTimeSpan\" elementFormDefault=\"qualified\" targetNamespace=\"NSTimeSpan\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  61. #else
  62. "<xs:schema xmlns:tns=\"NSTimeSpan\" targetNamespace=\"NSTimeSpan\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  63. #endif
  64. " <xs:complexType name=\"TimeSpan\" />{0}" +
  65. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  66. schemas = Export (typeof (TimeSpan));
  67. Assert.AreEqual (1, schemas.Count, "#3");
  68. sw = new StringWriter ();
  69. schemas[0].Write (sw);
  70. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  71. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  72. #if NET_2_0
  73. "<xs:schema elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  74. #else
  75. "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  76. #endif
  77. " <xs:complexType name=\"TimeSpan\" />{0}" +
  78. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  79. }
  80. [Test]
  81. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  82. /*
  83. #if NET_2_0
  84. [Category ("NotWorking")] // minOccurs is 1 on Mono
  85. #endif
  86. */
  87. public void ExportClass_SimpleClass ()
  88. {
  89. SoapAttributeOverrides overrides = new SoapAttributeOverrides ();
  90. SoapAttributes attr = new SoapAttributes ();
  91. SoapElementAttribute element = new SoapElementAttribute ();
  92. element.ElementName = "saying";
  93. element.IsNullable = true;
  94. attr.SoapElement = element;
  95. overrides.Add (typeof (SimpleClass), "something", attr);
  96. XmlSchemas schemas = Export (typeof (SimpleClass), overrides, "NSSimpleClass");
  97. Assert.AreEqual (1, schemas.Count, "#1");
  98. StringWriter sw = new StringWriter ();
  99. schemas[0].Write (sw);
  100. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  101. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  102. #if NET_2_0
  103. "<xs:schema xmlns:tns=\"NSSimpleClass\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClass\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  104. #else
  105. "<xs:schema xmlns:tns=\"NSSimpleClass\" targetNamespace=\"NSSimpleClass\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  106. #endif
  107. " <xs:complexType name=\"SimpleClass\">{0}" +
  108. " <xs:sequence>{0}" +
  109. #if NET_2_0
  110. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
  111. #else
  112. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" type=\"xs:string\" />{0}" +
  113. #endif
  114. " </xs:sequence>{0}" +
  115. " </xs:complexType>{0}" +
  116. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  117. }
  118. [Test]
  119. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  120. public void ExportClass_StringCollection ()
  121. {
  122. XmlSchemas schemas = Export (typeof (StringCollection), "NSStringCollection");
  123. Assert.AreEqual (1, schemas.Count, "#1");
  124. StringWriter sw = new StringWriter ();
  125. schemas[0].Write (sw);
  126. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  127. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  128. #if NET_2_0
  129. "<xs:schema xmlns:tns=\"NSStringCollection\" elementFormDefault=\"qualified\" targetNamespace=\"NSStringCollection\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  130. #else
  131. "<xs:schema xmlns:tns=\"NSStringCollection\" targetNamespace=\"NSStringCollection\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  132. #endif
  133. " <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
  134. " <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  135. " <xs:complexType name=\"ArrayOfString\">{0}" +
  136. " <xs:complexContent mixed=\"false\">{0}" +
  137. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  138. " <xs:attribute d5p1:arrayType=\"xs:string[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  139. " </xs:restriction>{0}" +
  140. " </xs:complexContent>{0}" +
  141. " </xs:complexType>{0}" +
  142. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  143. }
  144. [Test]
  145. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  146. public void ExportClass_StringCollectionContainer ()
  147. {
  148. XmlSchemas schemas = Export (typeof (StringCollectionContainer), "NSStringCollectionContainer");
  149. Assert.AreEqual (1, schemas.Count, "#1");
  150. StringWriter sw = new StringWriter ();
  151. schemas[0].Write (sw);
  152. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  153. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  154. #if NET_2_0
  155. "<xs:schema xmlns:tns=\"NSStringCollectionContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSStringCollectionContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  156. #else
  157. "<xs:schema xmlns:tns=\"NSStringCollectionContainer\" targetNamespace=\"NSStringCollectionContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  158. #endif
  159. " <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
  160. " <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  161. " <xs:complexType name=\"StringCollectionContainer\">{0}" +
  162. " <xs:sequence>{0}" +
  163. #if NET_2_0
  164. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"Messages\" type=\"tns:ArrayOfString\" />{0}" +
  165. #else
  166. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Messages\" type=\"tns:ArrayOfString\" />{0}" +
  167. #endif
  168. " </xs:sequence>{0}" +
  169. " </xs:complexType>{0}" +
  170. " <xs:complexType name=\"ArrayOfString\">{0}" +
  171. " <xs:complexContent mixed=\"false\">{0}" +
  172. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  173. " <xs:attribute d5p1:arrayType=\"xs:string[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  174. " </xs:restriction>{0}" +
  175. " </xs:complexContent>{0}" +
  176. " </xs:complexType>{0}" +
  177. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  178. }
  179. [Test]
  180. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  181. public void ExportClass_ArrayContainer ()
  182. {
  183. XmlSchemas schemas = Export (typeof (ArrayContainer), "NSArrayContainer");
  184. Assert.AreEqual (1, schemas.Count, "#1");
  185. StringWriter sw = new StringWriter ();
  186. schemas[0].Write (sw);
  187. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  188. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  189. #if NET_2_0
  190. "<xs:schema xmlns:tns=\"NSArrayContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  191. #else
  192. "<xs:schema xmlns:tns=\"NSArrayContainer\" targetNamespace=\"NSArrayContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  193. #endif
  194. " <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
  195. " <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  196. " <xs:complexType name=\"ArrayContainer\">{0}" +
  197. " <xs:sequence>{0}" +
  198. #if NET_2_0
  199. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"items\" type=\"tns:ArrayOfAnyType\" />{0}" +
  200. #else
  201. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"items\" type=\"tns:ArrayOfAnyType\" />{0}" +
  202. #endif
  203. " </xs:sequence>{0}" +
  204. " </xs:complexType>{0}" +
  205. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  206. " <xs:complexContent mixed=\"false\">{0}" +
  207. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  208. " <xs:attribute d5p1:arrayType=\"xs:anyType[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  209. " </xs:restriction>{0}" +
  210. " </xs:complexContent>{0}" +
  211. " </xs:complexType>{0}" +
  212. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  213. }
  214. [Test]
  215. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  216. public void ExportClass_ClassArrayContainer ()
  217. {
  218. XmlSchemas schemas = Export (typeof (ClassArrayContainer), "NSClassArrayContainer");
  219. Assert.AreEqual (1, schemas.Count, "#1");
  220. StringWriter sw = new StringWriter ();
  221. schemas[0].Write (sw);
  222. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  223. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  224. #if NET_2_0
  225. "<xs:schema xmlns:tns=\"NSClassArrayContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSClassArrayContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  226. #else
  227. "<xs:schema xmlns:tns=\"NSClassArrayContainer\" targetNamespace=\"NSClassArrayContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  228. #endif
  229. " <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
  230. " <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  231. " <xs:complexType name=\"ClassArrayContainer\">{0}" +
  232. " <xs:sequence>{0}" +
  233. #if NET_2_0
  234. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"items\" type=\"tns:ArrayOfSimpleClass\" />{0}" +
  235. #else
  236. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"items\" type=\"tns:ArrayOfSimpleClass\" />{0}" +
  237. #endif
  238. " </xs:sequence>{0}" +
  239. " </xs:complexType>{0}" +
  240. " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
  241. " <xs:complexContent mixed=\"false\">{0}" +
  242. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  243. " <xs:attribute d5p1:arrayType=\"tns:SimpleClass[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  244. " </xs:restriction>{0}" +
  245. " </xs:complexContent>{0}" +
  246. " </xs:complexType>{0}" +
  247. " <xs:complexType name=\"SimpleClass\">{0}" +
  248. " <xs:sequence>{0}" +
  249. #if NET_2_0
  250. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"something\" type=\"xs:string\" />{0}" +
  251. #else
  252. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
  253. #endif
  254. " </xs:sequence>{0}" +
  255. " </xs:complexType>{0}" +
  256. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  257. }
  258. [Test]
  259. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  260. public void ExportClass_SimpleClassWithXmlAttributes ()
  261. {
  262. XmlSchemas schemas = Export (typeof (SimpleClassWithXmlAttributes), "NSSimpleClassWithXmlAttributes");
  263. Assert.AreEqual (1, schemas.Count, "#1");
  264. StringWriter sw = new StringWriter ();
  265. schemas[0].Write (sw);
  266. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  267. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  268. #if NET_2_0
  269. "<xs:schema xmlns:tns=\"NSSimpleClassWithXmlAttributes\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClassWithXmlAttributes\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  270. #else
  271. "<xs:schema xmlns:tns=\"NSSimpleClassWithXmlAttributes\" targetNamespace=\"NSSimpleClassWithXmlAttributes\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  272. #endif
  273. " <xs:complexType name=\"SimpleClassWithXmlAttributes\">{0}" +
  274. " <xs:sequence>{0}" +
  275. #if NET_2_0
  276. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"something\" type=\"xs:string\" />{0}" +
  277. #else
  278. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
  279. #endif
  280. " </xs:sequence>{0}" +
  281. " </xs:complexType>{0}" +
  282. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  283. }
  284. [Test]
  285. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  286. public void ExportClass_Field ()
  287. {
  288. XmlSchemas schemas = Export (typeof (Field), "NSField");
  289. Assert.AreEqual (1, schemas.Count, "#1");
  290. StringWriter sw = new StringWriter ();
  291. schemas[0].Write (sw);
  292. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  293. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  294. #if NET_2_0
  295. "<xs:schema xmlns:tns=\"NSField\" elementFormDefault=\"qualified\" targetNamespace=\"NSField\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  296. #else
  297. "<xs:schema xmlns:tns=\"NSField\" targetNamespace=\"NSField\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  298. #endif
  299. " <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
  300. " <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  301. " <xs:complexType name=\"Field\">{0}" +
  302. " <xs:sequence>{0}" +
  303. #if NET_2_0
  304. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Modifiers\" type=\"tns:MapModifiers\" />{0}" +
  305. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Modifiers2\" type=\"tns:MapModifiers\" />{0}" +
  306. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Modifiers3\" type=\"tns:MapModifiers\" />{0}" +
  307. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Modifiers4\" type=\"tns:MapModifiers\" />{0}" +
  308. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"Names\" type=\"tns:ArrayOfString\" />{0}" +
  309. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"Street\" type=\"xs:string\" />{0}" +
  310. #else
  311. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Modifiers\" type=\"tns:MapModifiers\" />{0}" +
  312. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Modifiers2\" type=\"tns:MapModifiers\" />{0}" +
  313. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Modifiers3\" type=\"tns:MapModifiers\" />{0}" +
  314. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Modifiers4\" type=\"tns:MapModifiers\" />{0}" +
  315. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Names\" type=\"tns:ArrayOfString\" />{0}" +
  316. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Street\" type=\"xs:string\" />{0}" +
  317. #endif
  318. " </xs:sequence>{0}" +
  319. " </xs:complexType>{0}" +
  320. " <xs:simpleType name=\"MapModifiers\">{0}" +
  321. " <xs:list>{0}" +
  322. " <xs:simpleType>{0}" +
  323. " <xs:restriction base=\"xs:string\">{0}" +
  324. " <xs:enumeration value=\"Public\" />{0}" +
  325. " <xs:enumeration value=\"Protected\" />{0}" +
  326. " </xs:restriction>{0}" +
  327. " </xs:simpleType>{0}" +
  328. " </xs:list>{0}" +
  329. " </xs:simpleType>{0}" +
  330. " <xs:complexType name=\"ArrayOfString\">{0}" +
  331. " <xs:complexContent mixed=\"false\">{0}" +
  332. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  333. " <xs:attribute d5p1:arrayType=\"xs:string[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  334. " </xs:restriction>{0}" +
  335. " </xs:complexContent>{0}" +
  336. " </xs:complexType>{0}" +
  337. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  338. }
  339. [Test]
  340. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  341. public void ExportClass_MyList ()
  342. {
  343. XmlSchemas schemas = Export (typeof (MyList), "NSMyList");
  344. Assert.AreEqual (1, schemas.Count, "#1");
  345. StringWriter sw = new StringWriter ();
  346. schemas[0].Write (sw);
  347. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  348. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  349. #if NET_2_0
  350. "<xs:schema xmlns:tns=\"NSMyList\" elementFormDefault=\"qualified\" targetNamespace=\"NSMyList\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  351. #else
  352. "<xs:schema xmlns:tns=\"NSMyList\" targetNamespace=\"NSMyList\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  353. #endif
  354. " <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
  355. " <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  356. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  357. " <xs:complexContent mixed=\"false\">{0}" +
  358. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  359. " <xs:attribute d5p1:arrayType=\"xs:anyType[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  360. " </xs:restriction>{0}" +
  361. " </xs:complexContent>{0}" +
  362. " </xs:complexType>{0}" +
  363. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  364. }
  365. [Test]
  366. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  367. public void ExportClass_Container ()
  368. {
  369. XmlSchemas schemas = Export (typeof (Container), "NSContainer");
  370. Assert.AreEqual (1, schemas.Count, "#1");
  371. StringWriter sw = new StringWriter ();
  372. schemas[0].Write (sw);
  373. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  374. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  375. #if NET_2_0
  376. "<xs:schema xmlns:tns=\"NSContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  377. #else
  378. "<xs:schema xmlns:tns=\"NSContainer\" targetNamespace=\"NSContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  379. #endif
  380. " <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
  381. " <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  382. " <xs:complexType name=\"Container\">{0}" +
  383. " <xs:sequence>{0}" +
  384. #if NET_2_0
  385. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
  386. #else
  387. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
  388. #endif
  389. " </xs:sequence>{0}" +
  390. " </xs:complexType>{0}" +
  391. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  392. " <xs:complexContent mixed=\"false\">{0}" +
  393. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  394. " <xs:attribute d5p1:arrayType=\"xs:anyType[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  395. " </xs:restriction>{0}" +
  396. " </xs:complexContent>{0}" +
  397. " </xs:complexType>{0}" +
  398. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  399. }
  400. [Test]
  401. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  402. public void ExportClass_Container2 ()
  403. {
  404. XmlSchemas schemas = Export (typeof (Container2), "NSContainer2");
  405. Assert.AreEqual (1, schemas.Count, "#1");
  406. StringWriter sw = new StringWriter ();
  407. schemas[0].Write (sw);
  408. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  409. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  410. #if NET_2_0
  411. "<xs:schema xmlns:tns=\"NSContainer2\" elementFormDefault=\"qualified\" targetNamespace=\"NSContainer2\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  412. #else
  413. "<xs:schema xmlns:tns=\"NSContainer2\" targetNamespace=\"NSContainer2\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  414. #endif
  415. " <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
  416. " <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  417. " <xs:complexType name=\"Container2\">{0}" +
  418. " <xs:sequence>{0}" +
  419. #if NET_2_0
  420. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
  421. #else
  422. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
  423. #endif
  424. " </xs:sequence>{0}" +
  425. " </xs:complexType>{0}" +
  426. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  427. " <xs:complexContent mixed=\"false\">{0}" +
  428. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  429. " <xs:attribute d5p1:arrayType=\"xs:anyType[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  430. " </xs:restriction>{0}" +
  431. " </xs:complexContent>{0}" +
  432. " </xs:complexType>{0}" +
  433. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  434. }
  435. [Test]
  436. [ExpectedException (typeof (NotSupportedException))]
  437. public void ExportClass_MyElem ()
  438. {
  439. Export (typeof (MyElem), "NSMyElem");
  440. }
  441. [Test]
  442. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  443. [ExpectedException (typeof (NotSupportedException))] // The type System.Xml.XmlCDataSection may not be serialized with SOAP-encoded messages.
  444. public void ExportClass_CDataContainer ()
  445. {
  446. Export (typeof (CDataContainer), "NSCDataContainer");
  447. }
  448. [Test]
  449. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  450. [ExpectedException (typeof (NotSupportedException))] // The type System.Xml.XmlCDataSection may not be serialized with SOAP-encoded messages.
  451. public void ExportClass_NodeContainer ()
  452. {
  453. Export (typeof (NodeContainer), "NSNodeContainer");
  454. }
  455. [Test]
  456. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  457. public void ExportClass_Choices ()
  458. {
  459. XmlSchemas schemas = Export (typeof (Choices), "NSChoices");
  460. Assert.AreEqual (1, schemas.Count, "#1");
  461. StringWriter sw = new StringWriter ();
  462. schemas[0].Write (sw);
  463. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  464. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  465. #if NET_2_0
  466. "<xs:schema xmlns:tns=\"NSChoices\" elementFormDefault=\"qualified\" targetNamespace=\"NSChoices\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  467. #else
  468. "<xs:schema xmlns:tns=\"NSChoices\" targetNamespace=\"NSChoices\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  469. #endif
  470. " <xs:complexType name=\"Choices\">{0}" +
  471. " <xs:sequence>{0}" +
  472. #if NET_2_0
  473. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"MyChoice\" type=\"xs:string\" />{0}" +
  474. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"ItemType\" type=\"tns:ItemChoiceType\" />{0}" +
  475. #else
  476. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"MyChoice\" type=\"xs:string\" />{0}" +
  477. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"ItemType\" type=\"tns:ItemChoiceType\" />{0}" +
  478. #endif
  479. " </xs:sequence>{0}" +
  480. " </xs:complexType>{0}" +
  481. " <xs:simpleType name=\"ItemChoiceType\">{0}" +
  482. " <xs:restriction base=\"xs:string\">{0}" +
  483. " <xs:enumeration value=\"ChoiceZero\" />{0}" +
  484. " <xs:enumeration value=\"StrangeOne\" />{0}" +
  485. " <xs:enumeration value=\"ChoiceTwo\" />{0}" +
  486. " </xs:restriction>{0}" +
  487. " </xs:simpleType>{0}" +
  488. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  489. }
  490. [Test]
  491. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  492. public void ExportClass_WrongChoices ()
  493. {
  494. XmlSchemas schemas = Export (typeof (WrongChoices), "NSWrongChoices");
  495. Assert.AreEqual (1, schemas.Count, "#1");
  496. StringWriter sw = new StringWriter ();
  497. schemas[0].Write (sw);
  498. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  499. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  500. #if NET_2_0
  501. "<xs:schema xmlns:tns=\"NSWrongChoices\" elementFormDefault=\"qualified\" targetNamespace=\"NSWrongChoices\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  502. #else
  503. "<xs:schema xmlns:tns=\"NSWrongChoices\" targetNamespace=\"NSWrongChoices\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  504. #endif
  505. " <xs:complexType name=\"WrongChoices\">{0}" +
  506. " <xs:sequence>{0}" +
  507. #if NET_2_0
  508. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"MyChoice\" type=\"xs:string\" />{0}" +
  509. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"ItemType\" type=\"tns:ItemChoiceType\" />{0}" +
  510. #else
  511. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"MyChoice\" type=\"xs:string\" />{0}" +
  512. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"ItemType\" type=\"tns:ItemChoiceType\" />{0}" +
  513. #endif
  514. " </xs:sequence>{0}" +
  515. " </xs:complexType>{0}" +
  516. " <xs:simpleType name=\"ItemChoiceType\">{0}" +
  517. " <xs:restriction base=\"xs:string\">{0}" +
  518. " <xs:enumeration value=\"ChoiceZero\" />{0}" +
  519. " <xs:enumeration value=\"StrangeOne\" />{0}" +
  520. " <xs:enumeration value=\"ChoiceTwo\" />{0}" +
  521. " </xs:restriction>{0}" +
  522. " </xs:simpleType>{0}" +
  523. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  524. }
  525. [Test]
  526. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  527. public void ExportClass_TestSpace ()
  528. {
  529. XmlSchemas schemas = Export (typeof (TestSpace), "NSTestSpace");
  530. Assert.AreEqual (1, schemas.Count, "#1");
  531. StringWriter sw = new StringWriter ();
  532. schemas[0].Write (sw);
  533. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  534. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  535. #if NET_2_0
  536. "<xs:schema xmlns:tns=\"NSTestSpace\" elementFormDefault=\"qualified\" targetNamespace=\"NSTestSpace\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  537. #else
  538. "<xs:schema xmlns:tns=\"NSTestSpace\" targetNamespace=\"NSTestSpace\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  539. #endif
  540. " <xs:complexType name=\"TestSpace\">{0}" +
  541. " <xs:sequence>{0}" +
  542. #if NET_2_0
  543. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"elem\" type=\"xs:int\" />{0}" +
  544. #else
  545. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"elem\" type=\"xs:int\" />{0}" +
  546. #endif
  547. #if NET_2_0
  548. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"attr\" type=\"xs:int\" />{0}" +
  549. #else
  550. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"attr\" type=\"xs:int\" />{0}" +
  551. #endif
  552. " </xs:sequence>{0}" +
  553. " </xs:complexType>{0}" +
  554. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  555. }
  556. [Test]
  557. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  558. public void ExportClass_ReadOnlyProperties ()
  559. {
  560. XmlSchemas schemas = Export (typeof (ReadOnlyProperties), "NSReadOnlyProperties");
  561. Assert.AreEqual (1, schemas.Count, "#1");
  562. StringWriter sw = new StringWriter ();
  563. schemas[0].Write (sw);
  564. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  565. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  566. #if NET_2_0
  567. "<xs:schema xmlns:tns=\"NSReadOnlyProperties\" elementFormDefault=\"qualified\" targetNamespace=\"NSReadOnlyProperties\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  568. #else
  569. "<xs:schema xmlns:tns=\"NSReadOnlyProperties\" targetNamespace=\"NSReadOnlyProperties\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  570. #endif
  571. " <xs:complexType name=\"ReadOnlyProperties\" />{0}" +
  572. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  573. }
  574. [Test]
  575. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  576. public void ExportClass_ListDefaults ()
  577. {
  578. XmlSchemas schemas = Export (typeof (ListDefaults), "NSListDefaults");
  579. Assert.AreEqual (1, schemas.Count, "#1");
  580. StringWriter sw = new StringWriter ();
  581. schemas[0].Write (sw);
  582. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  583. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  584. #if NET_2_0
  585. "<xs:schema xmlns:tns=\"NSListDefaults\" elementFormDefault=\"qualified\" targetNamespace=\"NSListDefaults\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  586. #else
  587. "<xs:schema xmlns:tns=\"NSListDefaults\" targetNamespace=\"NSListDefaults\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  588. #endif
  589. " <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
  590. " <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  591. " <xs:complexType name=\"ListDefaults\">{0}" +
  592. " <xs:sequence>{0}" +
  593. #if NET_2_0
  594. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"list2\" type=\"tns:ArrayOfAnyType\" />{0}" +
  595. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"list3\" type=\"tns:ArrayOfAnyType\" />{0}" +
  596. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"list4\" type=\"tns:ArrayOfString\" />{0}" +
  597. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"list5\" type=\"tns:ArrayOfAnyType\" />{0}" +
  598. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"ed\" type=\"tns:SimpleClass\" />{0}" +
  599. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"str\" type=\"xs:string\" />{0}" +
  600. #else
  601. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"list2\" type=\"tns:ArrayOfAnyType\" />{0}" +
  602. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"list3\" type=\"tns:ArrayOfAnyType\" />{0}" +
  603. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"list4\" type=\"tns:ArrayOfString\" />{0}" +
  604. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"list5\" type=\"tns:ArrayOfAnyType\" />{0}" +
  605. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"ed\" type=\"tns:SimpleClass\" />{0}" +
  606. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"str\" type=\"xs:string\" />{0}" +
  607. #endif
  608. " </xs:sequence>{0}" +
  609. " </xs:complexType>{0}" +
  610. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  611. " <xs:complexContent mixed=\"false\">{0}" +
  612. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  613. " <xs:attribute d5p1:arrayType=\"xs:anyType[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  614. " </xs:restriction>{0}" +
  615. " </xs:complexContent>{0}" +
  616. " </xs:complexType>{0}" +
  617. " <xs:complexType name=\"SimpleClass\">{0}" +
  618. " <xs:sequence>{0}" +
  619. #if NET_2_0
  620. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"something\" type=\"xs:string\" />{0}" +
  621. #else
  622. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
  623. #endif
  624. " </xs:sequence>{0}" +
  625. " </xs:complexType>{0}" +
  626. " <xs:complexType name=\"ArrayOfString\">{0}" +
  627. " <xs:complexContent mixed=\"false\">{0}" +
  628. " <xs:restriction xmlns:q2=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q2:Array\">{0}" +
  629. " <xs:attribute d5p1:arrayType=\"xs:string[]\" ref=\"q2:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  630. " </xs:restriction>{0}" +
  631. " </xs:complexContent>{0}" +
  632. " </xs:complexType>{0}" +
  633. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  634. }
  635. [Test]
  636. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  637. public void ExportClass_ClsPerson ()
  638. {
  639. XmlSchemas schemas = Export (typeof (clsPerson), "NSClsPerson");
  640. Assert.AreEqual (1, schemas.Count, "#1");
  641. StringWriter sw = new StringWriter ();
  642. schemas[0].Write (sw);
  643. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  644. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  645. #if NET_2_0
  646. "<xs:schema xmlns:tns=\"NSClsPerson\" elementFormDefault=\"qualified\" targetNamespace=\"NSClsPerson\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  647. #else
  648. "<xs:schema xmlns:tns=\"NSClsPerson\" targetNamespace=\"NSClsPerson\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  649. #endif
  650. " <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
  651. " <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  652. " <xs:complexType name=\"clsPerson\">{0}" +
  653. " <xs:sequence>{0}" +
  654. #if NET_2_0
  655. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"EmailAccounts\" type=\"tns:ArrayOfAnyType\" />{0}" +
  656. #else
  657. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"EmailAccounts\" type=\"tns:ArrayOfAnyType\" />{0}" +
  658. #endif
  659. " </xs:sequence>{0}" +
  660. " </xs:complexType>{0}" +
  661. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  662. " <xs:complexContent mixed=\"false\">{0}" +
  663. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  664. " <xs:attribute d5p1:arrayType=\"xs:anyType[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  665. " </xs:restriction>{0}" +
  666. " </xs:complexContent>{0}" +
  667. " </xs:complexType>{0}" +
  668. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  669. }
  670. [Test]
  671. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  672. public void ExportClass_ArrayClass ()
  673. {
  674. XmlSchemas schemas = Export (typeof (ArrayClass), "NSArrayClass");
  675. Assert.AreEqual (1, schemas.Count, "#1");
  676. StringWriter sw = new StringWriter ();
  677. schemas[0].Write (sw);
  678. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  679. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  680. #if NET_2_0
  681. "<xs:schema xmlns:tns=\"NSArrayClass\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayClass\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  682. #else
  683. "<xs:schema xmlns:tns=\"NSArrayClass\" targetNamespace=\"NSArrayClass\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  684. #endif
  685. " <xs:complexType name=\"ArrayClass\">{0}" +
  686. " <xs:sequence>{0}" +
  687. #if NET_2_0
  688. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"names\" type=\"xs:anyType\" />{0}" +
  689. #else
  690. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"names\" type=\"xs:anyType\" />{0}" +
  691. #endif
  692. " </xs:sequence>{0}" +
  693. " </xs:complexType>{0}" +
  694. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  695. }
  696. [Test]
  697. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  698. public void ExportClass_StructContainer ()
  699. {
  700. XmlSchemas schemas = Export (typeof (StructContainer), "NSStructContainer");
  701. Assert.AreEqual (1, schemas.Count, "#1");
  702. StringWriter sw = new StringWriter ();
  703. schemas[0].Write (sw);
  704. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  705. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  706. #if NET_2_0
  707. "<xs:schema xmlns:tns=\"NSStructContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSStructContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  708. #else
  709. "<xs:schema xmlns:tns=\"NSStructContainer\" targetNamespace=\"NSStructContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  710. #endif
  711. " <xs:complexType name=\"StructContainer\">{0}" +
  712. " <xs:sequence>{0}" +
  713. #if NET_2_0
  714. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Value\" type=\"tns:EnumDefaultValue\" />{0}" +
  715. #else
  716. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Value\" type=\"tns:EnumDefaultValue\" />{0}" +
  717. #endif
  718. " </xs:sequence>{0}" +
  719. " </xs:complexType>{0}" +
  720. " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
  721. " <xs:list>{0}" +
  722. " <xs:simpleType>{0}" +
  723. " <xs:restriction base=\"xs:string\">{0}" +
  724. " <xs:enumeration value=\"e1\" />{0}" +
  725. " <xs:enumeration value=\"e2\" />{0}" +
  726. " <xs:enumeration value=\"e3\" />{0}" +
  727. " </xs:restriction>{0}" +
  728. " </xs:simpleType>{0}" +
  729. " </xs:list>{0}" +
  730. " </xs:simpleType>{0}" +
  731. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  732. }
  733. [Test]
  734. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  735. /*
  736. #if NET_2_0
  737. [Category ("NotWorking")] // minOccurs is 1 on Mono
  738. #endif
  739. */
  740. public void ExportClass_SimpleClass_Array ()
  741. {
  742. SoapAttributeOverrides overrides = new SoapAttributeOverrides ();
  743. SoapAttributes attr = new SoapAttributes ();
  744. SoapElementAttribute element = new SoapElementAttribute ();
  745. element.ElementName = "saying";
  746. element.IsNullable = true;
  747. attr.SoapElement = element;
  748. overrides.Add (typeof (SimpleClass), "something", attr);
  749. SoapReflectionImporter ri = new SoapReflectionImporter (overrides, "NSSimpleClassArray");
  750. XmlSchemas schemas = new XmlSchemas ();
  751. SoapSchemaExporter sx = new SoapSchemaExporter (schemas);
  752. XmlTypeMapping tm = ri.ImportTypeMapping (typeof (SimpleClass[]));
  753. sx.ExportTypeMapping (tm);
  754. Assert.AreEqual (1, schemas.Count, "#1");
  755. StringWriter sw = new StringWriter ();
  756. schemas[0].Write (sw);
  757. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  758. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  759. #if NET_2_0
  760. "<xs:schema xmlns:tns=\"NSSimpleClassArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClassArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  761. #else
  762. "<xs:schema xmlns:tns=\"NSSimpleClassArray\" targetNamespace=\"NSSimpleClassArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  763. #endif
  764. " <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
  765. " <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  766. " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
  767. " <xs:complexContent mixed=\"false\">{0}" +
  768. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  769. " <xs:attribute d5p1:arrayType=\"tns:SimpleClass[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  770. " </xs:restriction>{0}" +
  771. " </xs:complexContent>{0}" +
  772. " </xs:complexType>{0}" +
  773. " <xs:complexType name=\"SimpleClass\">{0}" +
  774. " <xs:sequence>{0}" +
  775. #if NET_2_0
  776. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
  777. #else
  778. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" type=\"xs:string\" />{0}" +
  779. #endif
  780. " </xs:sequence>{0}" +
  781. " </xs:complexType>{0}" +
  782. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  783. }
  784. [Test]
  785. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  786. public void ExportEnum ()
  787. {
  788. XmlSchemas schemas = Export (typeof (EnumDefaultValue), "NSEnumDefaultValue");
  789. Assert.AreEqual (1, schemas.Count, "#1");
  790. StringWriter sw = new StringWriter ();
  791. schemas[0].Write (sw);
  792. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  793. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  794. #if NET_2_0
  795. "<xs:schema xmlns:tns=\"NSEnumDefaultValue\" elementFormDefault=\"qualified\" targetNamespace=\"NSEnumDefaultValue\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  796. #else
  797. "<xs:schema xmlns:tns=\"NSEnumDefaultValue\" targetNamespace=\"NSEnumDefaultValue\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  798. #endif
  799. " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
  800. " <xs:list>{0}" +
  801. " <xs:simpleType>{0}" +
  802. " <xs:restriction base=\"xs:string\">{0}" +
  803. " <xs:enumeration value=\"e1\" />{0}" +
  804. " <xs:enumeration value=\"e2\" />{0}" +
  805. " <xs:enumeration value=\"e3\" />{0}" +
  806. " </xs:restriction>{0}" +
  807. " </xs:simpleType>{0}" +
  808. " </xs:list>{0}" +
  809. " </xs:simpleType>{0}" +
  810. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  811. schemas = Export (typeof (EnumDefaultValueNF), "NSEnumDefaultValueNF");
  812. Assert.AreEqual (1, schemas.Count, "#3");
  813. sw = new StringWriter ();
  814. schemas[0].Write (sw);
  815. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  816. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  817. #if NET_2_0
  818. "<xs:schema xmlns:tns=\"NSEnumDefaultValueNF\" elementFormDefault=\"qualified\" targetNamespace=\"NSEnumDefaultValueNF\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  819. #else
  820. "<xs:schema xmlns:tns=\"NSEnumDefaultValueNF\" targetNamespace=\"NSEnumDefaultValueNF\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  821. #endif
  822. " <xs:simpleType name=\"EnumDefaultValueNF\">{0}" +
  823. " <xs:restriction base=\"xs:string\">{0}" +
  824. " <xs:enumeration value=\"e1\" />{0}" +
  825. " <xs:enumeration value=\"e2\" />{0}" +
  826. " <xs:enumeration value=\"e3\" />{0}" +
  827. " </xs:restriction>{0}" +
  828. " </xs:simpleType>{0}" +
  829. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  830. }
  831. [Test]
  832. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  833. public void ExportXsdPrimitive ()
  834. {
  835. ArrayList types = new ArrayList ();
  836. types.Add (new TypeDescription (typeof (object), true, "anyType", "Object"));
  837. types.Add (new TypeDescription (typeof (byte), true, "unsignedByte", "Byte"));
  838. types.Add (new TypeDescription (typeof (sbyte), true, "byte", "Byte"));
  839. types.Add (new TypeDescription (typeof (bool), true, "boolean", "Boolean"));
  840. types.Add (new TypeDescription (typeof (short), true, "short", "Short"));
  841. types.Add (new TypeDescription (typeof (int), true, "int", "Int"));
  842. types.Add (new TypeDescription (typeof (long), true, "long", "Long"));
  843. types.Add (new TypeDescription (typeof (float), true, "float", "Float"));
  844. types.Add (new TypeDescription (typeof (double), true, "double", "Double"));
  845. types.Add (new TypeDescription (typeof (decimal), true, "decimal", "Decimal"));
  846. types.Add (new TypeDescription (typeof (ushort), true, "unsignedShort", "UnsignedShort"));
  847. types.Add (new TypeDescription (typeof (uint), true, "unsignedInt", "UnsignedInt"));
  848. types.Add (new TypeDescription (typeof (ulong), true, "unsignedLong", "UnsignedLong"));
  849. types.Add (new TypeDescription (typeof (DateTime), true, "dateTime", "DateTime"));
  850. #if NET_2_0
  851. types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName", true));
  852. #else
  853. types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName"));
  854. #endif
  855. types.Add (new TypeDescription (typeof (string), true, "string", "String", true));
  856. foreach (TypeDescription typeDesc in types) {
  857. XmlSchemas schemas = Export (typeDesc.Type, typeDesc.Type.Name);
  858. Assert.AreEqual (0, schemas.Count, typeDesc.Type.FullName + "#1");
  859. }
  860. }
  861. [Test]
  862. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  863. public void ExportXsdPrimitive_ByteArray ()
  864. {
  865. XmlSchemas schemas = Export (typeof (byte[]), "ByteArray");
  866. Assert.AreEqual (0, schemas.Count, "#1");
  867. }
  868. [Test]
  869. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  870. public void ExportXsdPrimitive_Arrays ()
  871. {
  872. ArrayList types = new ArrayList ();
  873. types.Add (new TypeDescription (typeof (object[]), true, "anyType", "AnyType"));
  874. types.Add (new TypeDescription (typeof (sbyte[]), true, "byte", "Byte"));
  875. types.Add (new TypeDescription (typeof (bool[]), true, "boolean", "Boolean"));
  876. types.Add (new TypeDescription (typeof (short[]), true, "short", "Short"));
  877. types.Add (new TypeDescription (typeof (int[]), true, "int", "Int"));
  878. types.Add (new TypeDescription (typeof (long[]), true, "long", "Long"));
  879. types.Add (new TypeDescription (typeof (float[]), true, "float", "Float"));
  880. types.Add (new TypeDescription (typeof (double[]), true, "double", "Double"));
  881. types.Add (new TypeDescription (typeof (decimal[]), true, "decimal", "Decimal"));
  882. types.Add (new TypeDescription (typeof (ushort[]), true, "unsignedShort", "UnsignedShort"));
  883. types.Add (new TypeDescription (typeof (uint[]), true, "unsignedInt", "UnsignedInt"));
  884. types.Add (new TypeDescription (typeof (ulong[]), true, "unsignedLong", "UnsignedLong"));
  885. types.Add (new TypeDescription (typeof (DateTime[]), true, "dateTime", "DateTime"));
  886. #if NET_2_0
  887. types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName", true));
  888. #else
  889. types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName"));
  890. #endif
  891. types.Add (new TypeDescription (typeof (string[]), true, "string", "String", true));
  892. foreach (TypeDescription typeDesc in types) {
  893. XmlSchemas schemas = Export (typeDesc.Type, typeDesc.Type.Name);
  894. Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1");
  895. StringWriter sw = new StringWriter ();
  896. schemas[0].Write (sw);
  897. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  898. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  899. #if NET_2_0
  900. "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  901. #else
  902. "<xs:schema xmlns:tns=\"{1}\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  903. #endif
  904. " <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
  905. " <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  906. " <xs:complexType name=\"ArrayOf{2}\">{0}" +
  907. " <xs:complexContent mixed=\"false\">{0}" +
  908. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  909. " <xs:attribute d5p1:arrayType=\"xs:{3}[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  910. " </xs:restriction>{0}" +
  911. " </xs:complexContent>{0}" +
  912. " </xs:complexType>{0}" +
  913. "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.ArrayType, typeDesc.XmlType,
  914. typeDesc.XsdType ? "xs" : "tns", typeDesc.IsNillable ? "nillable=\"true\" " : ""),
  915. sw.ToString (), typeDesc.Type.FullName + "#2");
  916. }
  917. }
  918. [Test]
  919. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  920. public void ExportNonXsdPrimitive_Guid ()
  921. {
  922. XmlSchemas schemas = Export (typeof (Guid), "NSPrimGuid");
  923. Assert.AreEqual (1, schemas.Count, "#1");
  924. StringWriter sw = new StringWriter ();
  925. schemas[0].Write (sw);
  926. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  927. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  928. #if NET_2_0
  929. "<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}" +
  930. #else
  931. "<xs:schema xmlns:tns=\"http://microsoft.com/wsdl/types/\" targetNamespace=\"http://microsoft.com/wsdl/types/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  932. #endif
  933. " <xs:simpleType name=\"guid\">{0}" +
  934. " <xs:restriction base=\"xs:string\">{0}" +
  935. " <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}" +
  936. " </xs:restriction>{0}" +
  937. " </xs:simpleType>{0}" +
  938. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  939. }
  940. [Test]
  941. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  942. public void ExportNonXsdPrimitive_Char ()
  943. {
  944. XmlSchemas schemas = Export (typeof (Char), "NSPrimChar");
  945. Assert.AreEqual (1, schemas.Count, "#1");
  946. StringWriter sw = new StringWriter ();
  947. schemas[0].Write (sw);
  948. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  949. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  950. #if NET_2_0
  951. "<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}" +
  952. #else
  953. "<xs:schema xmlns:tns=\"http://microsoft.com/wsdl/types/\" targetNamespace=\"http://microsoft.com/wsdl/types/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  954. #endif
  955. " <xs:simpleType name=\"char\">{0}" +
  956. " <xs:restriction base=\"xs:unsignedShort\" />{0}" +
  957. " </xs:simpleType>{0}" +
  958. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  959. }
  960. public class Employee : IXmlSerializable
  961. {
  962. private string _firstName;
  963. private string _lastName;
  964. private string _address;
  965. public XmlSchema GetSchema ()
  966. {
  967. return null;
  968. }
  969. public void WriteXml (XmlWriter writer)
  970. {
  971. writer.WriteStartElement ("employee", "urn:devx-com");
  972. writer.WriteAttributeString ("firstName", _firstName);
  973. writer.WriteAttributeString ("lastName", _lastName);
  974. writer.WriteAttributeString ("address", _address);
  975. writer.WriteEndElement ();
  976. }
  977. public void ReadXml (XmlReader reader)
  978. {
  979. XmlNodeType type = reader.MoveToContent ();
  980. if (type == XmlNodeType.Element && reader.LocalName == "employee") {
  981. _firstName = reader["firstName"];
  982. _lastName = reader["lastName"];
  983. _address = reader["address"];
  984. }
  985. }
  986. }
  987. public class StructContainer
  988. {
  989. public EnumDefaultValue Value;
  990. }
  991. private class TypeDescription
  992. {
  993. public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType)
  994. : this (type, xsdType, xmlType, arrayType, false)
  995. {
  996. }
  997. public TypeDescription (Type type, bool xsdType, string xmlType, string arrayType, bool isNillable)
  998. {
  999. _type = type;
  1000. _xsdType = xsdType;
  1001. _xmlType = xmlType;
  1002. _arrayType = arrayType;
  1003. _isNillable = isNillable;
  1004. }
  1005. public Type Type
  1006. {
  1007. get { return _type; }
  1008. }
  1009. public string XmlType
  1010. {
  1011. get { return _xmlType; }
  1012. }
  1013. public string ArrayType
  1014. {
  1015. get { return _arrayType; }
  1016. }
  1017. public bool XsdType
  1018. {
  1019. get { return _xsdType; }
  1020. }
  1021. public bool IsNillable
  1022. {
  1023. get { return _isNillable; }
  1024. }
  1025. private Type _type;
  1026. private bool _xsdType;
  1027. private string _xmlType;
  1028. private string _arrayType;
  1029. private bool _isNillable;
  1030. }
  1031. }
  1032. }