/mcs/class/System.XML/Test/System.Xml.Serialization/SoapSchemaExporterTests.cs

https://github.com/iainlane/mono · C# · 1050 lines · 940 code · 92 blank · 18 comment · 0 complexity · 648b4f4aba1186675d1ff4a57a900efb MD5 · raw file

  1. //
  2. // System.Xml.Serialization.SoapSchemaExporterTests
  3. //
  4. // Author:
  5. // Gert Driesen (drieseng@users.sourceforge.net)
  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=\"Flags1\" type=\"tns:FlagEnum\" />{0}" +
  305. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Flags2\" type=\"tns:FlagEnum\" />{0}" +
  306. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Flags3\" type=\"tns:FlagEnum\" />{0}" +
  307. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Flags4\" type=\"tns:FlagEnum\" />{0}" +
  308. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Modifiers\" type=\"tns:MapModifiers\" />{0}" +
  309. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Modifiers2\" type=\"tns:MapModifiers\" />{0}" +
  310. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Modifiers3\" type=\"tns:MapModifiers\" />{0}" +
  311. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Modifiers4\" type=\"tns:MapModifiers\" />{0}" +
  312. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Modifiers5\" type=\"tns:MapModifiers\" />{0}" +
  313. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"Names\" type=\"tns:ArrayOfString\" />{0}" +
  314. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"Street\" type=\"xs:string\" />{0}" +
  315. #else
  316. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Flags1\" type=\"tns:FlagEnum\" />{0}" +
  317. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Flags2\" type=\"tns:FlagEnum\" />{0}" +
  318. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Flags3\" type=\"tns:FlagEnum\" />{0}" +
  319. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Flags4\" type=\"tns:FlagEnum\" />{0}" +
  320. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Modifiers\" type=\"tns:MapModifiers\" />{0}" +
  321. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Modifiers2\" type=\"tns:MapModifiers\" />{0}" +
  322. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Modifiers3\" type=\"tns:MapModifiers\" />{0}" +
  323. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Modifiers4\" type=\"tns:MapModifiers\" />{0}" +
  324. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Modifiers5\" type=\"tns:MapModifiers\" />{0}" +
  325. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Names\" type=\"tns:ArrayOfString\" />{0}" +
  326. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Street\" type=\"xs:string\" />{0}" +
  327. #endif
  328. " </xs:sequence>{0}" +
  329. " </xs:complexType>{0}" +
  330. " <xs:simpleType name=\"FlagEnum\">{0}" +
  331. " <xs:list>{0}" +
  332. " <xs:simpleType>{0}" +
  333. " <xs:restriction base=\"xs:string\">{0}" +
  334. " <xs:enumeration value=\"e1\" />{0}" +
  335. " <xs:enumeration value=\"e2\" />{0}" +
  336. " <xs:enumeration value=\"e4\" />{0}" +
  337. " </xs:restriction>{0}" +
  338. " </xs:simpleType>{0}" +
  339. " </xs:list>{0}" +
  340. " </xs:simpleType>{0}" +
  341. " <xs:simpleType name=\"MapModifiers\">{0}" +
  342. " <xs:list>{0}" +
  343. " <xs:simpleType>{0}" +
  344. " <xs:restriction base=\"xs:string\">{0}" +
  345. " <xs:enumeration value=\"Public\" />{0}" +
  346. " <xs:enumeration value=\"Protected\" />{0}" +
  347. " </xs:restriction>{0}" +
  348. " </xs:simpleType>{0}" +
  349. " </xs:list>{0}" +
  350. " </xs:simpleType>{0}" +
  351. " <xs:complexType name=\"ArrayOfString\">{0}" +
  352. " <xs:complexContent mixed=\"false\">{0}" +
  353. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  354. " <xs:attribute d5p1:arrayType=\"xs:string[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  355. " </xs:restriction>{0}" +
  356. " </xs:complexContent>{0}" +
  357. " </xs:complexType>{0}" +
  358. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  359. }
  360. [Test]
  361. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  362. public void ExportClass_MyList ()
  363. {
  364. XmlSchemas schemas = Export (typeof (MyList), "NSMyList");
  365. Assert.AreEqual (1, schemas.Count, "#1");
  366. StringWriter sw = new StringWriter ();
  367. schemas[0].Write (sw);
  368. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  369. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  370. #if NET_2_0
  371. "<xs:schema xmlns:tns=\"NSMyList\" elementFormDefault=\"qualified\" targetNamespace=\"NSMyList\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  372. #else
  373. "<xs:schema xmlns:tns=\"NSMyList\" targetNamespace=\"NSMyList\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  374. #endif
  375. " <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
  376. " <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  377. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  378. " <xs:complexContent mixed=\"false\">{0}" +
  379. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  380. " <xs:attribute d5p1:arrayType=\"xs:anyType[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  381. " </xs:restriction>{0}" +
  382. " </xs:complexContent>{0}" +
  383. " </xs:complexType>{0}" +
  384. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  385. }
  386. [Test]
  387. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  388. public void ExportClass_Container ()
  389. {
  390. XmlSchemas schemas = Export (typeof (Container), "NSContainer");
  391. Assert.AreEqual (1, schemas.Count, "#1");
  392. StringWriter sw = new StringWriter ();
  393. schemas[0].Write (sw);
  394. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  395. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  396. #if NET_2_0
  397. "<xs:schema xmlns:tns=\"NSContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  398. #else
  399. "<xs:schema xmlns:tns=\"NSContainer\" targetNamespace=\"NSContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  400. #endif
  401. " <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
  402. " <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  403. " <xs:complexType name=\"Container\">{0}" +
  404. " <xs:sequence>{0}" +
  405. #if NET_2_0
  406. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
  407. #else
  408. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
  409. #endif
  410. " </xs:sequence>{0}" +
  411. " </xs:complexType>{0}" +
  412. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  413. " <xs:complexContent mixed=\"false\">{0}" +
  414. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  415. " <xs:attribute d5p1:arrayType=\"xs:anyType[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  416. " </xs:restriction>{0}" +
  417. " </xs:complexContent>{0}" +
  418. " </xs:complexType>{0}" +
  419. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  420. }
  421. [Test]
  422. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  423. public void ExportClass_Container2 ()
  424. {
  425. XmlSchemas schemas = Export (typeof (Container2), "NSContainer2");
  426. Assert.AreEqual (1, schemas.Count, "#1");
  427. StringWriter sw = new StringWriter ();
  428. schemas[0].Write (sw);
  429. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  430. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  431. #if NET_2_0
  432. "<xs:schema xmlns:tns=\"NSContainer2\" elementFormDefault=\"qualified\" targetNamespace=\"NSContainer2\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  433. #else
  434. "<xs:schema xmlns:tns=\"NSContainer2\" targetNamespace=\"NSContainer2\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  435. #endif
  436. " <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
  437. " <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  438. " <xs:complexType name=\"Container2\">{0}" +
  439. " <xs:sequence>{0}" +
  440. #if NET_2_0
  441. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
  442. #else
  443. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Items\" type=\"tns:ArrayOfAnyType\" />{0}" +
  444. #endif
  445. " </xs:sequence>{0}" +
  446. " </xs:complexType>{0}" +
  447. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  448. " <xs:complexContent mixed=\"false\">{0}" +
  449. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  450. " <xs:attribute d5p1:arrayType=\"xs:anyType[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  451. " </xs:restriction>{0}" +
  452. " </xs:complexContent>{0}" +
  453. " </xs:complexType>{0}" +
  454. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  455. }
  456. [Test]
  457. [ExpectedException (typeof (NotSupportedException))]
  458. public void ExportClass_MyElem ()
  459. {
  460. Export (typeof (MyElem), "NSMyElem");
  461. }
  462. [Test]
  463. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  464. [ExpectedException (typeof (NotSupportedException))] // The type System.Xml.XmlCDataSection may not be serialized with SOAP-encoded messages.
  465. public void ExportClass_CDataContainer ()
  466. {
  467. Export (typeof (CDataContainer), "NSCDataContainer");
  468. }
  469. [Test]
  470. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  471. [ExpectedException (typeof (NotSupportedException))] // The type System.Xml.XmlCDataSection may not be serialized with SOAP-encoded messages.
  472. public void ExportClass_NodeContainer ()
  473. {
  474. Export (typeof (NodeContainer), "NSNodeContainer");
  475. }
  476. [Test]
  477. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  478. public void ExportClass_Choices ()
  479. {
  480. XmlSchemas schemas = Export (typeof (Choices), "NSChoices");
  481. Assert.AreEqual (1, schemas.Count, "#1");
  482. StringWriter sw = new StringWriter ();
  483. schemas[0].Write (sw);
  484. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  485. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  486. #if NET_2_0
  487. "<xs:schema xmlns:tns=\"NSChoices\" elementFormDefault=\"qualified\" targetNamespace=\"NSChoices\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  488. #else
  489. "<xs:schema xmlns:tns=\"NSChoices\" targetNamespace=\"NSChoices\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  490. #endif
  491. " <xs:complexType name=\"Choices\">{0}" +
  492. " <xs:sequence>{0}" +
  493. #if NET_2_0
  494. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"MyChoice\" type=\"xs:string\" />{0}" +
  495. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"ItemType\" type=\"tns:ItemChoiceType\" />{0}" +
  496. #else
  497. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"MyChoice\" type=\"xs:string\" />{0}" +
  498. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"ItemType\" type=\"tns:ItemChoiceType\" />{0}" +
  499. #endif
  500. " </xs:sequence>{0}" +
  501. " </xs:complexType>{0}" +
  502. " <xs:simpleType name=\"ItemChoiceType\">{0}" +
  503. " <xs:restriction base=\"xs:string\">{0}" +
  504. " <xs:enumeration value=\"ChoiceZero\" />{0}" +
  505. " <xs:enumeration value=\"StrangeOne\" />{0}" +
  506. " <xs:enumeration value=\"ChoiceTwo\" />{0}" +
  507. " </xs:restriction>{0}" +
  508. " </xs:simpleType>{0}" +
  509. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  510. }
  511. [Test]
  512. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  513. public void ExportClass_WrongChoices ()
  514. {
  515. XmlSchemas schemas = Export (typeof (WrongChoices), "NSWrongChoices");
  516. Assert.AreEqual (1, schemas.Count, "#1");
  517. StringWriter sw = new StringWriter ();
  518. schemas[0].Write (sw);
  519. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  520. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  521. #if NET_2_0
  522. "<xs:schema xmlns:tns=\"NSWrongChoices\" elementFormDefault=\"qualified\" targetNamespace=\"NSWrongChoices\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  523. #else
  524. "<xs:schema xmlns:tns=\"NSWrongChoices\" targetNamespace=\"NSWrongChoices\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  525. #endif
  526. " <xs:complexType name=\"WrongChoices\">{0}" +
  527. " <xs:sequence>{0}" +
  528. #if NET_2_0
  529. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"MyChoice\" type=\"xs:string\" />{0}" +
  530. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"ItemType\" type=\"tns:ItemChoiceType\" />{0}" +
  531. #else
  532. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"MyChoice\" type=\"xs:string\" />{0}" +
  533. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"ItemType\" type=\"tns:ItemChoiceType\" />{0}" +
  534. #endif
  535. " </xs:sequence>{0}" +
  536. " </xs:complexType>{0}" +
  537. " <xs:simpleType name=\"ItemChoiceType\">{0}" +
  538. " <xs:restriction base=\"xs:string\">{0}" +
  539. " <xs:enumeration value=\"ChoiceZero\" />{0}" +
  540. " <xs:enumeration value=\"StrangeOne\" />{0}" +
  541. " <xs:enumeration value=\"ChoiceTwo\" />{0}" +
  542. " </xs:restriction>{0}" +
  543. " </xs:simpleType>{0}" +
  544. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  545. }
  546. [Test]
  547. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  548. public void ExportClass_TestSpace ()
  549. {
  550. XmlSchemas schemas = Export (typeof (TestSpace), "NSTestSpace");
  551. Assert.AreEqual (1, schemas.Count, "#1");
  552. StringWriter sw = new StringWriter ();
  553. schemas[0].Write (sw);
  554. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  555. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  556. #if NET_2_0
  557. "<xs:schema xmlns:tns=\"NSTestSpace\" elementFormDefault=\"qualified\" targetNamespace=\"NSTestSpace\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  558. #else
  559. "<xs:schema xmlns:tns=\"NSTestSpace\" targetNamespace=\"NSTestSpace\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  560. #endif
  561. " <xs:complexType name=\"TestSpace\">{0}" +
  562. " <xs:sequence>{0}" +
  563. #if NET_2_0
  564. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"elem\" type=\"xs:int\" />{0}" +
  565. #else
  566. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"elem\" type=\"xs:int\" />{0}" +
  567. #endif
  568. #if NET_2_0
  569. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"attr\" type=\"xs:int\" />{0}" +
  570. #else
  571. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"attr\" type=\"xs:int\" />{0}" +
  572. #endif
  573. " </xs:sequence>{0}" +
  574. " </xs:complexType>{0}" +
  575. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  576. }
  577. [Test]
  578. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  579. public void ExportClass_ReadOnlyProperties ()
  580. {
  581. XmlSchemas schemas = Export (typeof (ReadOnlyProperties), "NSReadOnlyProperties");
  582. Assert.AreEqual (1, schemas.Count, "#1");
  583. StringWriter sw = new StringWriter ();
  584. schemas[0].Write (sw);
  585. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  586. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  587. #if NET_2_0
  588. "<xs:schema xmlns:tns=\"NSReadOnlyProperties\" elementFormDefault=\"qualified\" targetNamespace=\"NSReadOnlyProperties\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  589. #else
  590. "<xs:schema xmlns:tns=\"NSReadOnlyProperties\" targetNamespace=\"NSReadOnlyProperties\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  591. #endif
  592. " <xs:complexType name=\"ReadOnlyProperties\" />{0}" +
  593. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  594. }
  595. [Test]
  596. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  597. public void ExportClass_ListDefaults ()
  598. {
  599. XmlSchemas schemas = Export (typeof (ListDefaults), "NSListDefaults");
  600. Assert.AreEqual (1, schemas.Count, "#1");
  601. StringWriter sw = new StringWriter ();
  602. schemas[0].Write (sw);
  603. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  604. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  605. #if NET_2_0
  606. "<xs:schema xmlns:tns=\"NSListDefaults\" elementFormDefault=\"qualified\" targetNamespace=\"NSListDefaults\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  607. #else
  608. "<xs:schema xmlns:tns=\"NSListDefaults\" targetNamespace=\"NSListDefaults\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  609. #endif
  610. " <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
  611. " <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  612. " <xs:complexType name=\"ListDefaults\">{0}" +
  613. " <xs:sequence>{0}" +
  614. #if NET_2_0
  615. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"list2\" type=\"tns:ArrayOfAnyType\" />{0}" +
  616. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"list3\" type=\"tns:ArrayOfAnyType\" />{0}" +
  617. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"list4\" type=\"tns:ArrayOfString\" />{0}" +
  618. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"list5\" type=\"tns:ArrayOfAnyType\" />{0}" +
  619. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"ed\" type=\"tns:SimpleClass\" />{0}" +
  620. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"str\" type=\"xs:string\" />{0}" +
  621. #else
  622. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"list2\" type=\"tns:ArrayOfAnyType\" />{0}" +
  623. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"list3\" type=\"tns:ArrayOfAnyType\" />{0}" +
  624. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"list4\" type=\"tns:ArrayOfString\" />{0}" +
  625. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"list5\" type=\"tns:ArrayOfAnyType\" />{0}" +
  626. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"ed\" type=\"tns:SimpleClass\" />{0}" +
  627. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"str\" type=\"xs:string\" />{0}" +
  628. #endif
  629. " </xs:sequence>{0}" +
  630. " </xs:complexType>{0}" +
  631. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  632. " <xs:complexContent mixed=\"false\">{0}" +
  633. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  634. " <xs:attribute d5p1:arrayType=\"xs:anyType[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  635. " </xs:restriction>{0}" +
  636. " </xs:complexContent>{0}" +
  637. " </xs:complexType>{0}" +
  638. " <xs:complexType name=\"SimpleClass\">{0}" +
  639. " <xs:sequence>{0}" +
  640. #if NET_2_0
  641. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"something\" type=\"xs:string\" />{0}" +
  642. #else
  643. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"something\" type=\"xs:string\" />{0}" +
  644. #endif
  645. " </xs:sequence>{0}" +
  646. " </xs:complexType>{0}" +
  647. " <xs:complexType name=\"ArrayOfString\">{0}" +
  648. " <xs:complexContent mixed=\"false\">{0}" +
  649. " <xs:restriction xmlns:q2=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q2:Array\">{0}" +
  650. " <xs:attribute d5p1:arrayType=\"xs:string[]\" ref=\"q2:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  651. " </xs:restriction>{0}" +
  652. " </xs:complexContent>{0}" +
  653. " </xs:complexType>{0}" +
  654. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  655. }
  656. [Test]
  657. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  658. public void ExportClass_ClsPerson ()
  659. {
  660. XmlSchemas schemas = Export (typeof (clsPerson), "NSClsPerson");
  661. Assert.AreEqual (1, schemas.Count, "#1");
  662. StringWriter sw = new StringWriter ();
  663. schemas[0].Write (sw);
  664. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  665. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  666. #if NET_2_0
  667. "<xs:schema xmlns:tns=\"NSClsPerson\" elementFormDefault=\"qualified\" targetNamespace=\"NSClsPerson\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  668. #else
  669. "<xs:schema xmlns:tns=\"NSClsPerson\" targetNamespace=\"NSClsPerson\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  670. #endif
  671. " <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
  672. " <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  673. " <xs:complexType name=\"clsPerson\">{0}" +
  674. " <xs:sequence>{0}" +
  675. #if NET_2_0
  676. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"EmailAccounts\" type=\"tns:ArrayOfAnyType\" />{0}" +
  677. #else
  678. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"EmailAccounts\" type=\"tns:ArrayOfAnyType\" />{0}" +
  679. #endif
  680. " </xs:sequence>{0}" +
  681. " </xs:complexType>{0}" +
  682. " <xs:complexType name=\"ArrayOfAnyType\">{0}" +
  683. " <xs:complexContent mixed=\"false\">{0}" +
  684. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  685. " <xs:attribute d5p1:arrayType=\"xs:anyType[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  686. " </xs:restriction>{0}" +
  687. " </xs:complexContent>{0}" +
  688. " </xs:complexType>{0}" +
  689. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  690. }
  691. [Test]
  692. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  693. public void ExportClass_ArrayClass ()
  694. {
  695. XmlSchemas schemas = Export (typeof (ArrayClass), "NSArrayClass");
  696. Assert.AreEqual (1, schemas.Count, "#1");
  697. StringWriter sw = new StringWriter ();
  698. schemas[0].Write (sw);
  699. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  700. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  701. #if NET_2_0
  702. "<xs:schema xmlns:tns=\"NSArrayClass\" elementFormDefault=\"qualified\" targetNamespace=\"NSArrayClass\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  703. #else
  704. "<xs:schema xmlns:tns=\"NSArrayClass\" targetNamespace=\"NSArrayClass\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  705. #endif
  706. " <xs:complexType name=\"ArrayClass\">{0}" +
  707. " <xs:sequence>{0}" +
  708. #if NET_2_0
  709. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"names\" type=\"xs:anyType\" />{0}" +
  710. #else
  711. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"names\" type=\"xs:anyType\" />{0}" +
  712. #endif
  713. " </xs:sequence>{0}" +
  714. " </xs:complexType>{0}" +
  715. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  716. }
  717. [Test]
  718. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  719. public void ExportClass_StructContainer ()
  720. {
  721. XmlSchemas schemas = Export (typeof (StructContainer), "NSStructContainer");
  722. Assert.AreEqual (1, schemas.Count, "#1");
  723. StringWriter sw = new StringWriter ();
  724. schemas[0].Write (sw);
  725. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  726. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  727. #if NET_2_0
  728. "<xs:schema xmlns:tns=\"NSStructContainer\" elementFormDefault=\"qualified\" targetNamespace=\"NSStructContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  729. #else
  730. "<xs:schema xmlns:tns=\"NSStructContainer\" targetNamespace=\"NSStructContainer\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  731. #endif
  732. " <xs:complexType name=\"StructContainer\">{0}" +
  733. " <xs:sequence>{0}" +
  734. #if NET_2_0
  735. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" form=\"unqualified\" name=\"Value\" type=\"tns:EnumDefaultValue\" />{0}" +
  736. #else
  737. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"Value\" type=\"tns:EnumDefaultValue\" />{0}" +
  738. #endif
  739. " </xs:sequence>{0}" +
  740. " </xs:complexType>{0}" +
  741. " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
  742. " <xs:list>{0}" +
  743. " <xs:simpleType>{0}" +
  744. " <xs:restriction base=\"xs:string\">{0}" +
  745. " <xs:enumeration value=\"e1\" />{0}" +
  746. " <xs:enumeration value=\"e2\" />{0}" +
  747. " <xs:enumeration value=\"e3\" />{0}" +
  748. " </xs:restriction>{0}" +
  749. " </xs:simpleType>{0}" +
  750. " </xs:list>{0}" +
  751. " </xs:simpleType>{0}" +
  752. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  753. }
  754. [Test]
  755. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  756. /*
  757. #if NET_2_0
  758. [Category ("NotWorking")] // minOccurs is 1 on Mono
  759. #endif
  760. */
  761. public void ExportClass_SimpleClass_Array ()
  762. {
  763. SoapAttributeOverrides overrides = new SoapAttributeOverrides ();
  764. SoapAttributes attr = new SoapAttributes ();
  765. SoapElementAttribute element = new SoapElementAttribute ();
  766. element.ElementName = "saying";
  767. element.IsNullable = true;
  768. attr.SoapElement = element;
  769. overrides.Add (typeof (SimpleClass), "something", attr);
  770. SoapReflectionImporter ri = new SoapReflectionImporter (overrides, "NSSimpleClassArray");
  771. XmlSchemas schemas = new XmlSchemas ();
  772. SoapSchemaExporter sx = new SoapSchemaExporter (schemas);
  773. XmlTypeMapping tm = ri.ImportTypeMapping (typeof (SimpleClass[]));
  774. sx.ExportTypeMapping (tm);
  775. Assert.AreEqual (1, schemas.Count, "#1");
  776. StringWriter sw = new StringWriter ();
  777. schemas[0].Write (sw);
  778. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  779. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  780. #if NET_2_0
  781. "<xs:schema xmlns:tns=\"NSSimpleClassArray\" elementFormDefault=\"qualified\" targetNamespace=\"NSSimpleClassArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  782. #else
  783. "<xs:schema xmlns:tns=\"NSSimpleClassArray\" targetNamespace=\"NSSimpleClassArray\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  784. #endif
  785. " <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
  786. " <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  787. " <xs:complexType name=\"ArrayOfSimpleClass\">{0}" +
  788. " <xs:complexContent mixed=\"false\">{0}" +
  789. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  790. " <xs:attribute d5p1:arrayType=\"tns:SimpleClass[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  791. " </xs:restriction>{0}" +
  792. " </xs:complexContent>{0}" +
  793. " </xs:complexType>{0}" +
  794. " <xs:complexType name=\"SimpleClass\">{0}" +
  795. " <xs:sequence>{0}" +
  796. #if NET_2_0
  797. " <xs:element minOccurs=\"0\" maxOccurs=\"1\" form=\"unqualified\" name=\"saying\" nillable=\"true\" type=\"xs:string\" />{0}" +
  798. #else
  799. " <xs:element minOccurs=\"1\" maxOccurs=\"1\" name=\"saying\" type=\"xs:string\" />{0}" +
  800. #endif
  801. " </xs:sequence>{0}" +
  802. " </xs:complexType>{0}" +
  803. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  804. }
  805. [Test]
  806. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  807. public void ExportEnum ()
  808. {
  809. XmlSchemas schemas = Export (typeof (EnumDefaultValue), "NSEnumDefaultValue");
  810. Assert.AreEqual (1, schemas.Count, "#1");
  811. StringWriter sw = new StringWriter ();
  812. schemas[0].Write (sw);
  813. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  814. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  815. #if NET_2_0
  816. "<xs:schema xmlns:tns=\"NSEnumDefaultValue\" elementFormDefault=\"qualified\" targetNamespace=\"NSEnumDefaultValue\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  817. #else
  818. "<xs:schema xmlns:tns=\"NSEnumDefaultValue\" targetNamespace=\"NSEnumDefaultValue\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  819. #endif
  820. " <xs:simpleType name=\"EnumDefaultValue\">{0}" +
  821. " <xs:list>{0}" +
  822. " <xs:simpleType>{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:list>{0}" +
  830. " </xs:simpleType>{0}" +
  831. "</xs:schema>", Environment.NewLine), sw.ToString (), "#2");
  832. schemas = Export (typeof (EnumDefaultValueNF), "NSEnumDefaultValueNF");
  833. Assert.AreEqual (1, schemas.Count, "#3");
  834. sw = new StringWriter ();
  835. schemas[0].Write (sw);
  836. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  837. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  838. #if NET_2_0
  839. "<xs:schema xmlns:tns=\"NSEnumDefaultValueNF\" elementFormDefault=\"qualified\" targetNamespace=\"NSEnumDefaultValueNF\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  840. #else
  841. "<xs:schema xmlns:tns=\"NSEnumDefaultValueNF\" targetNamespace=\"NSEnumDefaultValueNF\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  842. #endif
  843. " <xs:simpleType name=\"EnumDefaultValueNF\">{0}" +
  844. " <xs:restriction base=\"xs:string\">{0}" +
  845. " <xs:enumeration value=\"e1\" />{0}" +
  846. " <xs:enumeration value=\"e2\" />{0}" +
  847. " <xs:enumeration value=\"e3\" />{0}" +
  848. " </xs:restriction>{0}" +
  849. " </xs:simpleType>{0}" +
  850. "</xs:schema>", Environment.NewLine), sw.ToString (), "#4");
  851. }
  852. [Test]
  853. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  854. public void ExportXsdPrimitive ()
  855. {
  856. ArrayList types = new ArrayList ();
  857. types.Add (new TypeDescription (typeof (object), true, "anyType", "Object"));
  858. types.Add (new TypeDescription (typeof (byte), true, "unsignedByte", "Byte"));
  859. types.Add (new TypeDescription (typeof (sbyte), true, "byte", "Byte"));
  860. types.Add (new TypeDescription (typeof (bool), true, "boolean", "Boolean"));
  861. types.Add (new TypeDescription (typeof (short), true, "short", "Short"));
  862. types.Add (new TypeDescription (typeof (int), true, "int", "Int"));
  863. types.Add (new TypeDescription (typeof (long), true, "long", "Long"));
  864. types.Add (new TypeDescription (typeof (float), true, "float", "Float"));
  865. types.Add (new TypeDescription (typeof (double), true, "double", "Double"));
  866. types.Add (new TypeDescription (typeof (decimal), true, "decimal", "Decimal"));
  867. types.Add (new TypeDescription (typeof (ushort), true, "unsignedShort", "UnsignedShort"));
  868. types.Add (new TypeDescription (typeof (uint), true, "unsignedInt", "UnsignedInt"));
  869. types.Add (new TypeDescription (typeof (ulong), true, "unsignedLong", "UnsignedLong"));
  870. types.Add (new TypeDescription (typeof (DateTime), true, "dateTime", "DateTime"));
  871. #if NET_2_0
  872. types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName", true));
  873. #else
  874. types.Add (new TypeDescription (typeof (XmlQualifiedName), true, "QName", "QName"));
  875. #endif
  876. types.Add (new TypeDescription (typeof (string), true, "string", "String", true));
  877. foreach (TypeDescription typeDesc in types) {
  878. XmlSchemas schemas = Export (typeDesc.Type, typeDesc.Type.Name);
  879. Assert.AreEqual (0, schemas.Count, typeDesc.Type.FullName + "#1");
  880. }
  881. }
  882. [Test]
  883. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  884. public void ExportXsdPrimitive_ByteArray ()
  885. {
  886. XmlSchemas schemas = Export (typeof (byte[]), "ByteArray");
  887. Assert.AreEqual (0, schemas.Count, "#1");
  888. }
  889. [Test]
  890. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  891. public void ExportXsdPrimitive_Arrays ()
  892. {
  893. ArrayList types = new ArrayList ();
  894. types.Add (new TypeDescription (typeof (object[]), true, "anyType", "AnyType"));
  895. types.Add (new TypeDescription (typeof (sbyte[]), true, "byte", "Byte"));
  896. types.Add (new TypeDescription (typeof (bool[]), true, "boolean", "Boolean"));
  897. types.Add (new TypeDescription (typeof (short[]), true, "short", "Short"));
  898. types.Add (new TypeDescription (typeof (int[]), true, "int", "Int"));
  899. types.Add (new TypeDescription (typeof (long[]), true, "long", "Long"));
  900. types.Add (new TypeDescription (typeof (float[]), true, "float", "Float"));
  901. types.Add (new TypeDescription (typeof (double[]), true, "double", "Double"));
  902. types.Add (new TypeDescription (typeof (decimal[]), true, "decimal", "Decimal"));
  903. types.Add (new TypeDescription (typeof (ushort[]), true, "unsignedShort", "UnsignedShort"));
  904. types.Add (new TypeDescription (typeof (uint[]), true, "unsignedInt", "UnsignedInt"));
  905. types.Add (new TypeDescription (typeof (ulong[]), true, "unsignedLong", "UnsignedLong"));
  906. types.Add (new TypeDescription (typeof (DateTime[]), true, "dateTime", "DateTime"));
  907. #if NET_2_0
  908. types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName", true));
  909. #else
  910. types.Add (new TypeDescription (typeof (XmlQualifiedName[]), true, "QName", "QName"));
  911. #endif
  912. types.Add (new TypeDescription (typeof (string[]), true, "string", "String", true));
  913. foreach (TypeDescription typeDesc in types) {
  914. XmlSchemas schemas = Export (typeDesc.Type, typeDesc.Type.Name);
  915. Assert.AreEqual (1, schemas.Count, typeDesc.Type.FullName + "#1");
  916. StringWriter sw = new StringWriter ();
  917. schemas[0].Write (sw);
  918. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  919. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  920. #if NET_2_0
  921. "<xs:schema xmlns:tns=\"{1}\" elementFormDefault=\"qualified\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  922. #else
  923. "<xs:schema xmlns:tns=\"{1}\" targetNamespace=\"{1}\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  924. #endif
  925. " <xs:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\" />{0}" +
  926. " <xs:import namespace=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  927. " <xs:complexType name=\"ArrayOf{2}\">{0}" +
  928. " <xs:complexContent mixed=\"false\">{0}" +
  929. " <xs:restriction xmlns:q1=\"http://schemas.xmlsoap.org/soap/encoding/\" base=\"q1:Array\">{0}" +
  930. " <xs:attribute d5p1:arrayType=\"xs:{3}[]\" ref=\"q1:arrayType\" xmlns:d5p1=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  931. " </xs:restriction>{0}" +
  932. " </xs:complexContent>{0}" +
  933. " </xs:complexType>{0}" +
  934. "</xs:schema>", Environment.NewLine, typeDesc.Type.Name, typeDesc.ArrayType, typeDesc.XmlType,
  935. typeDesc.XsdType ? "xs" : "tns", typeDesc.IsNillable ? "nillable=\"true\" " : ""),
  936. sw.ToString (), typeDesc.Type.FullName + "#2");
  937. }
  938. }
  939. [Test]
  940. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  941. public void ExportNonXsdPrimitive_Guid ()
  942. {
  943. XmlSchemas schemas = Export (typeof (Guid), "NSPrimGuid");
  944. Assert.AreEqual (1, schemas.Count, "#1");
  945. StringWriter sw = new StringWriter ();
  946. schemas[0].Write (sw);
  947. Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
  948. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  949. #if NET_2_0
  950. "<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}" +
  951. #else
  952. "<xs:schema xmlns:tns=\"http://microsoft.com/wsdl/types/\" targetNamespace=\"http://microsoft.com/wsdl/types/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">{0}" +
  953. #endif
  954. " <xs:simpleType name=\"guid\">{0}" +
  955. " <xs:restriction base=\"xs:string\">{0}" +
  956. " <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}" +
  957. " </xs:restriction>{0}" +
  958. " </xs:simpleTyp