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

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