SoapReflectionImporterTests.cs 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938
  1. //
  2. // System.Xml.Serialization.SoapReflectionImporterTests
  3. //
  4. // Author:
  5. // Gert Driesen ([email protected])
  6. //
  7. // (C) 2005 Novell
  8. //
  9. using System;
  10. using System.Collections;
  11. using DefaultValueAttribute = System.ComponentModel.DefaultValueAttribute;
  12. using System.Xml;
  13. using System.Xml.Schema;
  14. using System.Xml.Serialization;
  15. using NUnit.Framework;
  16. using MonoTests.System.Xml.TestClasses;
  17. namespace MonoTests.System.XmlSerialization
  18. {
  19. [TestFixture]
  20. public class SoapReflectionImporterTests
  21. {
  22. private const string SomeNamespace = "some:urn";
  23. private const string AnotherNamespace = "another:urn";
  24. private const string XmlSchemaNamespace = "http://www.w3.org/2001/XMLSchema";
  25. private const string WsdlTypesNamespace = "http://microsoft.com/wsdl/types/";
  26. // these Map methods re-create the SoapReflectionImporter at every call.
  27. private XmlTypeMapping Map (Type t)
  28. {
  29. SoapReflectionImporter ri = new SoapReflectionImporter ();
  30. XmlTypeMapping tm = ri.ImportTypeMapping (t);
  31. return tm;
  32. }
  33. private XmlTypeMapping Map (Type t, string ns)
  34. {
  35. SoapReflectionImporter ri = new SoapReflectionImporter (ns);
  36. XmlTypeMapping tm = ri.ImportTypeMapping (t);
  37. return tm;
  38. }
  39. private XmlTypeMapping Map (Type t, SoapAttributeOverrides overrides)
  40. {
  41. SoapReflectionImporter ri = new SoapReflectionImporter(overrides);
  42. XmlTypeMapping tm = ri.ImportTypeMapping(t);
  43. return tm;
  44. }
  45. private XmlMembersMapping MembersMap (Type t, SoapAttributeOverrides overrides,
  46. XmlReflectionMember [] members, bool inContainer, bool writeAccessors)
  47. {
  48. SoapReflectionImporter ri = new SoapReflectionImporter (overrides);
  49. XmlMembersMapping mm = ri.ImportMembersMapping (null, null, members,
  50. inContainer, writeAccessors);
  51. return mm;
  52. }
  53. [Test]
  54. public void TestIntTypeMapping ()
  55. {
  56. XmlTypeMapping tm = Map (typeof (int));
  57. Assert.AreEqual ("int", tm.ElementName, "#1");
  58. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#2");
  59. Assert.AreEqual ("Int32", tm.TypeName, "#3");
  60. Assert.AreEqual ("System.Int32", tm.TypeFullName, "#4");
  61. }
  62. [Test]
  63. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  64. public void TestIntTypeMapping_DefaultNamespace ()
  65. {
  66. XmlTypeMapping tm = Map (typeof (int), SomeNamespace);
  67. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#1");
  68. tm = Map (typeof (int[]), SomeNamespace);
  69. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  70. tm = Map (typeof (int[][]), SomeNamespace);
  71. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  72. }
  73. [Test]
  74. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  75. public void TestIntTypeMapping_Array ()
  76. {
  77. XmlTypeMapping tm = Map (typeof (int[]));
  78. Assert.AreEqual ("ArrayOfInt", tm.ElementName, "#A1");
  79. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  80. #if NET_2_0
  81. Assert.AreEqual ("ArrayOfInt32", tm.TypeName, "#A3");
  82. #else
  83. Assert.AreEqual ("Int32[]", tm.TypeName, "#A3");
  84. #endif
  85. Assert.AreEqual ("System.Int32[]", tm.TypeFullName, "#A4");
  86. tm = Map (typeof (int[][]));
  87. Assert.AreEqual ("ArrayOfArrayOfInt", tm.ElementName, "#B1");
  88. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  89. #if NET_2_0
  90. Assert.AreEqual ("ArrayOfArrayOfInt32", tm.TypeName, "#B3");
  91. #else
  92. Assert.AreEqual ("Int32[][]", tm.TypeName, "#B3");
  93. #endif
  94. Assert.AreEqual ("System.Int32[][]", tm.TypeFullName, "#B4");
  95. }
  96. [Test]
  97. public void TestStringTypeMapping ()
  98. {
  99. XmlTypeMapping tm = Map (typeof (string));
  100. Assert.AreEqual ("string", tm.ElementName, "#1");
  101. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#2");
  102. Assert.AreEqual ("String", tm.TypeName, "#3");
  103. Assert.AreEqual ("System.String", tm.TypeFullName, "#4");
  104. }
  105. [Test]
  106. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  107. public void TestStringTypeMapping_DefaultNamespace ()
  108. {
  109. XmlTypeMapping tm = Map (typeof (string), SomeNamespace);
  110. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#1");
  111. tm = Map (typeof (string[]), SomeNamespace);
  112. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  113. tm = Map (typeof (string[][]), SomeNamespace);
  114. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  115. }
  116. [Test]
  117. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  118. public void TestStringTypeMapping_Array ()
  119. {
  120. XmlTypeMapping tm = Map (typeof (string[]));
  121. Assert.AreEqual ("ArrayOfString", tm.ElementName, "#A1");
  122. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  123. #if NET_2_0
  124. Assert.AreEqual ("ArrayOfString", tm.TypeName, "#A3");
  125. #else
  126. Assert.AreEqual ("String[]", tm.TypeName, "#A3");
  127. #endif
  128. Assert.AreEqual ("System.String[]", tm.TypeFullName, "#A4");
  129. tm = Map (typeof (string[][]));
  130. Assert.AreEqual ("ArrayOfArrayOfString", tm.ElementName, "#B1");
  131. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  132. #if NET_2_0
  133. Assert.AreEqual ("ArrayOfArrayOfString", tm.TypeName, "#B3");
  134. #else
  135. Assert.AreEqual ("String[][]", tm.TypeName, "#B3");
  136. #endif
  137. Assert.AreEqual ("System.String[][]", tm.TypeFullName, "#B4");
  138. }
  139. [Test]
  140. public void TestObjectTypeMapping ()
  141. {
  142. XmlTypeMapping tm = Map (typeof (object));
  143. Assert.AreEqual ("anyType", tm.ElementName, "#1");
  144. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#2");
  145. Assert.AreEqual ("Object", tm.TypeName, "#3");
  146. Assert.AreEqual ("System.Object", tm.TypeFullName, "#4");
  147. }
  148. [Test]
  149. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  150. public void TestObjectTypeMapping_DefaultNamespace ()
  151. {
  152. XmlTypeMapping tm = Map (typeof (object), SomeNamespace);
  153. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#1");
  154. tm = Map (typeof (object[]), SomeNamespace);
  155. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  156. tm = Map (typeof (object[][]), SomeNamespace);
  157. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  158. }
  159. [Test]
  160. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  161. public void TestObjectTypeMapping_Array ()
  162. {
  163. XmlTypeMapping tm = Map (typeof (object[]));
  164. Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#A1");
  165. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  166. #if NET_2_0
  167. Assert.AreEqual ("ArrayOfObject", tm.TypeName, "#A3");
  168. #else
  169. Assert.AreEqual ("Object[]", tm.TypeName, "#A3");
  170. #endif
  171. Assert.AreEqual ("System.Object[]", tm.TypeFullName, "#A4");
  172. tm = Map (typeof (object[][]));
  173. Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#B1");
  174. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  175. #if NET_2_0
  176. Assert.AreEqual ("ArrayOfArrayOfObject", tm.TypeName, "#B3");
  177. #else
  178. Assert.AreEqual ("Object[][]", tm.TypeName, "#B3");
  179. #endif
  180. Assert.AreEqual ("System.Object[][]", tm.TypeFullName, "#B4");
  181. }
  182. [Test]
  183. public void TestByteTypeMapping ()
  184. {
  185. XmlTypeMapping tm = Map (typeof (byte));
  186. Assert.AreEqual ("unsignedByte", tm.ElementName, "#1");
  187. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#2");
  188. Assert.AreEqual ("Byte", tm.TypeName, "#3");
  189. Assert.AreEqual ("System.Byte", tm.TypeFullName, "#4");
  190. }
  191. [Test]
  192. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  193. public void TestByteTypeMapping_DefaultNamespace ()
  194. {
  195. XmlTypeMapping tm = Map (typeof (byte), SomeNamespace);
  196. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#1");
  197. tm = Map (typeof (byte[]), SomeNamespace);
  198. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#2");
  199. tm = Map (typeof (byte[][]), SomeNamespace);
  200. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  201. }
  202. [Test]
  203. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  204. public void TestByteTypeMapping_Array ()
  205. {
  206. XmlTypeMapping tm = Map (typeof (byte[]));
  207. Assert.AreEqual ("base64Binary", tm.ElementName, "#A1");
  208. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#A2");
  209. Assert.AreEqual ("Byte[]", tm.TypeName, "#A3");
  210. Assert.AreEqual ("System.Byte[]", tm.TypeFullName, "#A4");
  211. tm = Map (typeof (byte[][]));
  212. Assert.AreEqual ("ArrayOfBase64Binary", tm.ElementName, "#B1");
  213. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  214. #if NET_2_0
  215. Assert.AreEqual ("ArrayOfArrayOfByte", tm.TypeName, "#B3");
  216. #else
  217. Assert.AreEqual ("Byte[][]", tm.TypeName, "#B3");
  218. #endif
  219. Assert.AreEqual ("System.Byte[][]", tm.TypeFullName, "#B4");
  220. }
  221. [Test]
  222. public void TestBoolTypeMapping ()
  223. {
  224. XmlTypeMapping tm = Map (typeof (bool));
  225. Assert.AreEqual ("boolean", tm.ElementName, "#1");
  226. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#2");
  227. Assert.AreEqual ("Boolean", tm.TypeName, "#3");
  228. Assert.AreEqual ("System.Boolean", tm.TypeFullName, "#4");
  229. }
  230. [Test]
  231. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  232. public void TestBoolTypeMapping_DefaultNamespace ()
  233. {
  234. XmlTypeMapping tm = Map (typeof (bool), "http://somenamespace");
  235. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#1");
  236. tm = Map (typeof (bool[]), SomeNamespace);
  237. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  238. tm = Map (typeof (bool[][]), SomeNamespace);
  239. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  240. }
  241. [Test]
  242. public void TestShortTypeMapping ()
  243. {
  244. XmlTypeMapping tm = Map (typeof (short));
  245. Assert.AreEqual ("short", tm.ElementName, "#1");
  246. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#2");
  247. Assert.AreEqual ("Int16", tm.TypeName, "#3");
  248. Assert.AreEqual ("System.Int16", tm.TypeFullName, "#4");
  249. }
  250. [Test]
  251. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  252. public void TestShortTypeMapping_DefaultNamespace ()
  253. {
  254. XmlTypeMapping tm = Map (typeof (short), SomeNamespace);
  255. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#1");
  256. tm = Map (typeof (short[]), SomeNamespace);
  257. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  258. tm = Map (typeof (short[][]), SomeNamespace);
  259. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  260. }
  261. [Test]
  262. public void TestUnsignedShortTypeMapping ()
  263. {
  264. XmlTypeMapping tm = Map (typeof (ushort));
  265. Assert.AreEqual ("unsignedShort", tm.ElementName, "#1");
  266. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#2");
  267. Assert.AreEqual ("UInt16", tm.TypeName, "#3");
  268. Assert.AreEqual ("System.UInt16", tm.TypeFullName, "#4");
  269. }
  270. [Test]
  271. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  272. public void TestUnsignedShortTypeMapping_DefaultNamespace ()
  273. {
  274. XmlTypeMapping tm = Map (typeof (ushort), SomeNamespace);
  275. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#1");
  276. tm = Map (typeof (ushort[]), SomeNamespace);
  277. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  278. tm = Map (typeof (ushort[][]), SomeNamespace);
  279. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  280. }
  281. [Test]
  282. public void TestUIntTypeMapping ()
  283. {
  284. XmlTypeMapping tm = Map (typeof (uint));
  285. Assert.AreEqual ("unsignedInt", tm.ElementName, "#1");
  286. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#2");
  287. Assert.AreEqual ("UInt32", tm.TypeName, "#3");
  288. Assert.AreEqual ("System.UInt32", tm.TypeFullName, "#4");
  289. }
  290. [Test]
  291. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  292. public void TestUIntTypeMapping_DefaultNamespace ()
  293. {
  294. XmlTypeMapping tm = Map (typeof (uint), SomeNamespace);
  295. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#1");
  296. tm = Map (typeof (uint[]), SomeNamespace);
  297. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  298. tm = Map (typeof (uint[][]), SomeNamespace);
  299. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  300. }
  301. [Test]
  302. public void TestLongTypeMapping ()
  303. {
  304. XmlTypeMapping tm = Map (typeof (long));
  305. Assert.AreEqual ("long", tm.ElementName, "#1");
  306. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#2");
  307. Assert.AreEqual ("Int64", tm.TypeName, "#3");
  308. Assert.AreEqual ("System.Int64", tm.TypeFullName, "#4");
  309. }
  310. [Test]
  311. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  312. public void TestLongTypeMapping_DefaultNamespace ()
  313. {
  314. XmlTypeMapping tm = Map (typeof (long), SomeNamespace);
  315. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#1");
  316. tm = Map (typeof (long[]), SomeNamespace);
  317. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  318. tm = Map (typeof (long[][]), SomeNamespace);
  319. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  320. }
  321. [Test]
  322. public void TestULongTypeMapping ()
  323. {
  324. XmlTypeMapping tm = Map (typeof (ulong));
  325. Assert.AreEqual ("unsignedLong", tm.ElementName, "#1");
  326. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#2");
  327. Assert.AreEqual ("UInt64", tm.TypeName, "#3");
  328. Assert.AreEqual ("System.UInt64", tm.TypeFullName, "#4");
  329. }
  330. [Test]
  331. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  332. public void TestULongTypeMapping_DefaultNamespace ()
  333. {
  334. XmlTypeMapping tm = Map (typeof (ulong), SomeNamespace);
  335. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#1");
  336. tm = Map (typeof (ulong[]), SomeNamespace);
  337. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  338. tm = Map (typeof (ulong[][]), SomeNamespace);
  339. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  340. }
  341. [Test]
  342. public void TestFloatTypeMapping ()
  343. {
  344. XmlTypeMapping tm = Map (typeof (float));
  345. Assert.AreEqual ("float", tm.ElementName, "#1");
  346. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#2");
  347. Assert.AreEqual ("Single", tm.TypeName, "#3");
  348. Assert.AreEqual ("System.Single", tm.TypeFullName, "#4");
  349. }
  350. [Test]
  351. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  352. public void TestFloatTypeMapping_DefaultNamespace ()
  353. {
  354. XmlTypeMapping tm = Map (typeof (float), SomeNamespace);
  355. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#1");
  356. tm = Map (typeof (float[]), SomeNamespace);
  357. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  358. tm = Map (typeof (float[][]), SomeNamespace);
  359. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  360. }
  361. [Test]
  362. public void TestDoubleTypeMapping ()
  363. {
  364. XmlTypeMapping tm = Map (typeof (double));
  365. Assert.AreEqual ("double", tm.ElementName, "#1");
  366. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#2");
  367. Assert.AreEqual ("Double", tm.TypeName, "#3");
  368. Assert.AreEqual ("System.Double", tm.TypeFullName, "#4");
  369. }
  370. [Test]
  371. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  372. public void TestDoubleTypeMapping_DefaultNamespace ()
  373. {
  374. XmlTypeMapping tm = Map (typeof (double), SomeNamespace);
  375. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#1");
  376. tm = Map (typeof (double[]), SomeNamespace);
  377. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  378. tm = Map (typeof (double[][]), SomeNamespace);
  379. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  380. }
  381. [Test]
  382. public void TestDateTimeTypeMapping ()
  383. {
  384. XmlTypeMapping tm = Map (typeof (DateTime));
  385. Assert.AreEqual ("dateTime", tm.ElementName, "#1");
  386. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#2");
  387. Assert.AreEqual ("DateTime", tm.TypeName, "#3");
  388. Assert.AreEqual ("System.DateTime", tm.TypeFullName, "#4");
  389. }
  390. [Test]
  391. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  392. public void TestDateTimeTypeMapping_DefaultNamespace ()
  393. {
  394. XmlTypeMapping tm = Map (typeof (DateTime), SomeNamespace);
  395. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#1");
  396. tm = Map (typeof (DateTime[]), SomeNamespace);
  397. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  398. tm = Map (typeof (DateTime[][]), SomeNamespace);
  399. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  400. }
  401. [Test]
  402. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  403. public void TestDateTimeTypeMapping_Array ()
  404. {
  405. XmlTypeMapping tm = Map (typeof (DateTime[]));
  406. Assert.AreEqual ("ArrayOfDateTime", tm.ElementName, "#A1");
  407. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  408. #if NET_2_0
  409. Assert.AreEqual ("ArrayOfDateTime", tm.TypeName, "#A3");
  410. #else
  411. Assert.AreEqual ("DateTime[]", tm.TypeName, "#A3");
  412. #endif
  413. Assert.AreEqual ("System.DateTime[]", tm.TypeFullName, "#A4");
  414. tm = Map (typeof (DateTime[][]));
  415. Assert.AreEqual ("ArrayOfArrayOfDateTime", tm.ElementName, "#B1");
  416. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  417. #if NET_2_0
  418. Assert.AreEqual ("ArrayOfArrayOfDateTime", tm.TypeName, "#B3");
  419. #else
  420. Assert.AreEqual ("DateTime[][]", tm.TypeName, "#B3");
  421. #endif
  422. Assert.AreEqual ("System.DateTime[][]", tm.TypeFullName, "#B4");
  423. }
  424. [Test]
  425. public void TestGuidTypeMapping ()
  426. {
  427. XmlTypeMapping tm = Map (typeof (Guid));
  428. Assert.AreEqual ("guid", tm.ElementName, "#1");
  429. Assert.AreEqual (WsdlTypesNamespace, tm.Namespace, "#2");
  430. Assert.AreEqual ("Guid", tm.TypeName, "#3");
  431. Assert.AreEqual ("System.Guid", tm.TypeFullName, "#4");
  432. }
  433. [Test]
  434. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  435. public void TestGuidTypeMapping_DefaultNamespace ()
  436. {
  437. XmlTypeMapping tm = Map (typeof (Guid), SomeNamespace);
  438. Assert.AreEqual (WsdlTypesNamespace, tm.Namespace, "#1");
  439. tm = Map (typeof (Guid[]), SomeNamespace);
  440. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  441. tm = Map (typeof (Guid[][]), SomeNamespace);
  442. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  443. }
  444. [Test]
  445. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  446. public void TestGuidTypeMapping_Array ()
  447. {
  448. XmlTypeMapping tm = Map (typeof (Guid[]));
  449. Assert.AreEqual ("ArrayOfGuid", tm.ElementName, "#A1");
  450. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  451. #if NET_2_0
  452. Assert.AreEqual ("ArrayOfGuid", tm.TypeName, "#A3");
  453. #else
  454. Assert.AreEqual ("Guid[]", tm.TypeName, "#A3");
  455. #endif
  456. Assert.AreEqual ("System.Guid[]", tm.TypeFullName, "#A4");
  457. tm = Map (typeof (Guid[][]));
  458. Assert.AreEqual ("ArrayOfArrayOfGuid", tm.ElementName, "#B1");
  459. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  460. #if NET_2_0
  461. Assert.AreEqual ("ArrayOfArrayOfGuid", tm.TypeName, "#B3");
  462. #else
  463. Assert.AreEqual ("Guid[][]", tm.TypeName, "#B3");
  464. #endif
  465. Assert.AreEqual ("System.Guid[][]", tm.TypeFullName, "#B4");
  466. }
  467. [Test]
  468. public void TestDecimalTypeMapping ()
  469. {
  470. XmlTypeMapping tm = Map (typeof (decimal));
  471. Assert.AreEqual ("decimal", tm.ElementName, "#1");
  472. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#2");
  473. Assert.AreEqual ("Decimal", tm.TypeName, "#3");
  474. Assert.AreEqual ("System.Decimal", tm.TypeFullName, "#4");
  475. }
  476. [Test]
  477. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  478. public void TestDecimalTypeMapping_DefaultNamespace ()
  479. {
  480. XmlTypeMapping tm = Map (typeof (decimal), SomeNamespace);
  481. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#1");
  482. tm = Map (typeof (decimal[]), SomeNamespace);
  483. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  484. tm = Map (typeof (decimal[][]), SomeNamespace);
  485. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  486. }
  487. [Test]
  488. public void TestXmlQualifiedNameTypeMapping ()
  489. {
  490. XmlTypeMapping tm = Map (typeof (XmlQualifiedName));
  491. Assert.AreEqual ("QName", tm.ElementName, "#1");
  492. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#2");
  493. Assert.AreEqual ("XmlQualifiedName", tm.TypeName, "#3");
  494. Assert.AreEqual ("System.Xml.XmlQualifiedName", tm.TypeFullName, "#4");
  495. }
  496. [Test]
  497. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  498. public void TestXmlQualifiedNameTypeMapping_DefaultNamespace ()
  499. {
  500. XmlTypeMapping tm = Map (typeof (XmlQualifiedName), SomeNamespace);
  501. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#1");
  502. tm = Map (typeof (XmlQualifiedName[]), SomeNamespace);
  503. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  504. tm = Map (typeof (XmlQualifiedName[][]), SomeNamespace);
  505. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  506. }
  507. [Test]
  508. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  509. public void TestXmlQualifiedNameTypeMapping_Array ()
  510. {
  511. XmlTypeMapping tm = Map (typeof (XmlQualifiedName[]));
  512. Assert.AreEqual ("ArrayOfQName", tm.ElementName, "#A1");
  513. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  514. #if NET_2_0
  515. Assert.AreEqual ("ArrayOfXmlQualifiedName", tm.TypeName, "#A3");
  516. #else
  517. Assert.AreEqual ("XmlQualifiedName[]", tm.TypeName, "#A3");
  518. #endif
  519. Assert.AreEqual ("System.Xml.XmlQualifiedName[]", tm.TypeFullName, "#A4");
  520. tm = Map (typeof (XmlQualifiedName[][]));
  521. Assert.AreEqual ("ArrayOfArrayOfQName", tm.ElementName, "#B1");
  522. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  523. #if NET_2_0
  524. Assert.AreEqual ("ArrayOfArrayOfXmlQualifiedName", tm.TypeName, "#B3");
  525. #else
  526. Assert.AreEqual ("XmlQualifiedName[][]", tm.TypeName, "#B3");
  527. #endif
  528. Assert.AreEqual ("System.Xml.XmlQualifiedName[][]", tm.TypeFullName, "#B4");
  529. }
  530. [Test]
  531. public void TestSByteTypeMapping ()
  532. {
  533. XmlTypeMapping tm = Map (typeof (sbyte));
  534. Assert.AreEqual ("byte", tm.ElementName, "#1");
  535. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#2");
  536. Assert.AreEqual ("SByte", tm.TypeName, "#3");
  537. Assert.AreEqual ("System.SByte", tm.TypeFullName, "#4");
  538. }
  539. [Test]
  540. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  541. public void TestSByteTypeMapping_DefaultNamespace ()
  542. {
  543. XmlTypeMapping tm = Map (typeof (sbyte), SomeNamespace);
  544. Assert.AreEqual (XmlSchemaNamespace, tm.Namespace, "#1");
  545. tm = Map (typeof (sbyte[]), SomeNamespace);
  546. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  547. tm = Map (typeof (sbyte[][]), SomeNamespace);
  548. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  549. }
  550. [Test]
  551. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  552. public void TestSByteTypeMapping_Array ()
  553. {
  554. XmlTypeMapping tm = Map (typeof (sbyte[]));
  555. Assert.AreEqual ("ArrayOfByte", tm.ElementName, "#A1");
  556. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  557. #if NET_2_0
  558. Assert.AreEqual ("ArrayOfSByte", tm.TypeName, "#A3");
  559. #else
  560. Assert.AreEqual ("SByte[]", tm.TypeName, "#A3");
  561. #endif
  562. Assert.AreEqual ("System.SByte[]", tm.TypeFullName, "#A4");
  563. tm = Map (typeof (sbyte[][]));
  564. Assert.AreEqual ("ArrayOfArrayOfByte", tm.ElementName, "#B1");
  565. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  566. #if NET_2_0
  567. Assert.AreEqual ("ArrayOfArrayOfSByte", tm.TypeName, "#B3");
  568. #else
  569. Assert.AreEqual ("SByte[][]", tm.TypeName, "#B3");
  570. #endif
  571. Assert.AreEqual ("System.SByte[][]", tm.TypeFullName, "#B4");
  572. }
  573. [Test]
  574. public void TestCharTypeMapping()
  575. {
  576. XmlTypeMapping tm = Map (typeof (char));
  577. Assert.AreEqual ("char", tm.ElementName, "#1");
  578. Assert.AreEqual (WsdlTypesNamespace, tm.Namespace, "#2");
  579. Assert.AreEqual ("Char", tm.TypeName, "#3");
  580. Assert.AreEqual ("System.Char", tm.TypeFullName, "#4");
  581. }
  582. [Test]
  583. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  584. public void TestCharTypeMapping_DefaultNamespace ()
  585. {
  586. XmlTypeMapping tm = Map (typeof (char), SomeNamespace);
  587. Assert.AreEqual (WsdlTypesNamespace, tm.Namespace, "#1");
  588. tm = Map (typeof (char[]), SomeNamespace);
  589. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  590. tm = Map (typeof (char[][]), SomeNamespace);
  591. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  592. }
  593. [Test]
  594. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  595. public void TestCharTypeMapping_Array ()
  596. {
  597. XmlTypeMapping tm = Map (typeof (char[]));
  598. Assert.AreEqual ("ArrayOfChar", tm.ElementName, "#A1");
  599. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  600. #if NET_2_0
  601. Assert.AreEqual ("ArrayOfChar", tm.TypeName, "#A3");
  602. #else
  603. Assert.AreEqual ("Char[]", tm.TypeName, "#A3");
  604. #endif
  605. Assert.AreEqual ("System.Char[]", tm.TypeFullName, "#A4");
  606. tm = Map (typeof (char[][]));
  607. Assert.AreEqual ("ArrayOfArrayOfChar", tm.ElementName, "#B1");
  608. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  609. #if NET_2_0
  610. Assert.AreEqual ("ArrayOfArrayOfChar", tm.TypeName, "#B3");
  611. #else
  612. Assert.AreEqual ("Char[][]", tm.TypeName, "#B3");
  613. #endif
  614. Assert.AreEqual ("System.Char[][]", tm.TypeFullName, "#B4");
  615. }
  616. [Test]
  617. public void TestXmlNodeTypeMapping ()
  618. {
  619. try {
  620. Map (typeof (XmlNode));
  621. Assert.Fail ("#1");
  622. } catch (NotSupportedException) {
  623. // The type System.Xml.XmlNode may not be serialized with SOAP-encoded messages.
  624. }
  625. try {
  626. Map (typeof (XmlNode[]));
  627. Assert.Fail ("#2");
  628. } catch (NotSupportedException) {
  629. // The type System.Xml.XmlNode may not be serialized with SOAP-encoded messages.
  630. }
  631. try {
  632. Map (typeof (XmlNode[][]));
  633. Assert.Fail ("#3");
  634. } catch (NotSupportedException) {
  635. // The type System.Xml.XmlNode may not be serialized with SOAP-encoded messages.
  636. }
  637. }
  638. [Test]
  639. public void TestXmlNodeTypeMapping_DefaultNamespace ()
  640. {
  641. try {
  642. Map (typeof (XmlNode), SomeNamespace);
  643. Assert.Fail ("#1");
  644. } catch (NotSupportedException) {
  645. // The type System.Xml.XmlNode may not be serialized with SOAP-encoded messages.
  646. }
  647. try {
  648. Map (typeof (XmlNode[]), SomeNamespace);
  649. Assert.Fail ("#2");
  650. } catch (NotSupportedException) {
  651. // The type System.Xml.XmlNode may not be serialized with SOAP-encoded messages.
  652. }
  653. try {
  654. Map (typeof (XmlNode[][]), SomeNamespace);
  655. Assert.Fail ("#3");
  656. } catch (NotSupportedException) {
  657. // The type System.Xml.XmlNode may not be serialized with SOAP-encoded messages.
  658. }
  659. }
  660. [Test]
  661. public void TestXmlElementTypeMapping ()
  662. {
  663. try {
  664. Map (typeof (XmlElement));
  665. Assert.Fail ("#1");
  666. } catch (NotSupportedException) {
  667. // The type System.Xml.XmlElement may not be serialized with SOAP-encoded messages.
  668. }
  669. try {
  670. Map (typeof (XmlElement[]));
  671. Assert.Fail ("#2");
  672. } catch (NotSupportedException) {
  673. // The type System.Xml.XmlElement may not be serialized with SOAP-encoded messages.
  674. }
  675. try {
  676. Map (typeof (XmlElement[][]));
  677. Assert.Fail ("#3");
  678. } catch (NotSupportedException) {
  679. // The type System.Xml.XmlElement may not be serialized with SOAP-encoded messages.
  680. }
  681. }
  682. [Test]
  683. public void TestXmlElementTypeMapping_DefaultNamespace ()
  684. {
  685. try {
  686. Map (typeof (XmlElement), SomeNamespace);
  687. Assert.Fail ("#1");
  688. } catch (NotSupportedException) {
  689. // The type System.Xml.XmlElement may not be serialized with SOAP-encoded messages.
  690. }
  691. try {
  692. Map (typeof (XmlElement[]), SomeNamespace);
  693. Assert.Fail ("#2");
  694. } catch (NotSupportedException) {
  695. // The type System.Xml.XmlElement may not be serialized with SOAP-encoded messages.
  696. }
  697. try {
  698. Map (typeof (XmlElement[][]), SomeNamespace);
  699. Assert.Fail ("#3");
  700. } catch (NotSupportedException) {
  701. // The type System.Xml.XmlElement may not be serialized with SOAP-encoded messages.
  702. }
  703. }
  704. [Test]
  705. public void TestXmlNotationTypeMapping ()
  706. {
  707. try {
  708. Map (typeof (XmlNotation));
  709. Assert.Fail ("#1");
  710. } catch (NotSupportedException) {
  711. // The type System.Xml.XmlNotation may not be serialized with SOAP-encoded messages.
  712. }
  713. try {
  714. Map (typeof (XmlNotation[]));
  715. Assert.Fail ("#2");
  716. } catch (NotSupportedException) {
  717. // The type System.Xml.XmlNotation may not be serialized with SOAP-encoded messages.
  718. }
  719. try {
  720. Map (typeof (XmlNotation[][]));
  721. Assert.Fail ("#3");
  722. } catch (NotSupportedException) {
  723. // The type System.Xml.XmlNotation may not be serialized with SOAP-encoded messages.
  724. }
  725. }
  726. [Test]
  727. public void TestXmlNotationTypeMapping_DefaultNamespace ()
  728. {
  729. try {
  730. Map (typeof (XmlNotation), SomeNamespace);
  731. Assert.Fail ("#1");
  732. } catch (NotSupportedException) {
  733. // The type System.Xml.XmlNotation may not be serialized with SOAP-encoded messages.
  734. }
  735. try {
  736. Map (typeof (XmlNotation[]), SomeNamespace);
  737. Assert.Fail ("#2");
  738. } catch (NotSupportedException) {
  739. // The type System.Xml.XmlNotation may not be serialized with SOAP-encoded messages.
  740. }
  741. try {
  742. Map (typeof (XmlNotation[][]), SomeNamespace);
  743. Assert.Fail ("#3");
  744. } catch (NotSupportedException) {
  745. // The type System.Xml.XmlNotation may not be serialized with SOAP-encoded messages.
  746. }
  747. }
  748. [Test]
  749. [ExpectedException (typeof (NotSupportedException))]
  750. public void TestXmlSerializableTypeMapping ()
  751. {
  752. Map (typeof (Employee));
  753. }
  754. [Test]
  755. [Category ("NotWorking")]
  756. [ExpectedException (typeof (NotSupportedException))]
  757. public void TestClassTypeMapping_NestedStruct ()
  758. {
  759. Map (typeof (NestedStruct));
  760. }
  761. [Test]
  762. [ExpectedException (typeof (ArgumentNullException))]
  763. public void TestNullTypeMapping()
  764. {
  765. Map(null);
  766. }
  767. [Test]
  768. [ExpectedException (typeof (ArgumentNullException))]
  769. public void TestNullTypeMapping_DefaultNamespace ()
  770. {
  771. Map (null, SomeNamespace);
  772. }
  773. [Test]
  774. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  775. public void TestStructTypeMapping ()
  776. {
  777. XmlTypeMapping tm = Map (typeof (TimeSpan));
  778. Assert.AreEqual ("TimeSpan", tm.ElementName, "#1");
  779. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  780. Assert.AreEqual ("TimeSpan", tm.TypeName, "#3");
  781. Assert.AreEqual ("System.TimeSpan", tm.TypeFullName, "#4");
  782. }
  783. [Test]
  784. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  785. public void TestStructTypeMapping_DefaultNamespace ()
  786. {
  787. XmlTypeMapping tm = Map (typeof (TimeSpan), SomeNamespace);
  788. Assert.AreEqual (SomeNamespace, tm.Namespace, "#1");
  789. try {
  790. tm = Map (typeof (TimeSpan[]), SomeNamespace);
  791. Assert.Fail ("#2");
  792. } catch (NotSupportedException) {
  793. }
  794. try {
  795. tm = Map (typeof (TimeSpan[][]), SomeNamespace);
  796. Assert.Fail ("#3");
  797. } catch (NotSupportedException) {
  798. }
  799. }
  800. [Test]
  801. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  802. [ExpectedException (typeof (NotSupportedException))] // Arrays of structs are not supported with encoded SOAP.
  803. public void TestStructTypeMapping_Array ()
  804. {
  805. Map (typeof (TimeSpan[]));
  806. }
  807. [Test]
  808. public void TestEnumTypeMapping ()
  809. {
  810. XmlTypeMapping tm = Map (typeof (AttributeTargets));
  811. Assert.AreEqual ("AttributeTargets", tm.ElementName, "#1");
  812. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  813. Assert.AreEqual ("AttributeTargets", tm.TypeName, "#3");
  814. Assert.AreEqual ("System.AttributeTargets", tm.TypeFullName, "#4");
  815. }
  816. [Test]
  817. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  818. public void TestEnumTypeMapping_DefaultNamespace ()
  819. {
  820. XmlTypeMapping tm = Map (typeof (AttributeTargets), SomeNamespace);
  821. Assert.AreEqual (SomeNamespace, tm.Namespace, "#1");
  822. tm = Map (typeof (AttributeTargets[]), SomeNamespace);
  823. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  824. tm = Map (typeof (AttributeTargets[][]), SomeNamespace);
  825. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  826. }
  827. [Test]
  828. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  829. public void TestEnumTypeMapping_Array ()
  830. {
  831. XmlTypeMapping tm = Map (typeof (AttributeTargets[]));
  832. Assert.AreEqual ("ArrayOfAttributeTargets", tm.ElementName, "#A1");
  833. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  834. #if NET_2_0
  835. Assert.AreEqual ("ArrayOfAttributeTargets", tm.TypeName, "#A3");
  836. #else
  837. Assert.AreEqual ("AttributeTargets[]", tm.TypeName, "#A3");
  838. #endif
  839. Assert.AreEqual ("System.AttributeTargets[]", tm.TypeFullName, "#A4");
  840. tm = Map (typeof (AttributeTargets[][]));
  841. Assert.AreEqual ("ArrayOfArrayOfAttributeTargets", tm.ElementName, "#B1");
  842. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  843. #if NET_2_0
  844. Assert.AreEqual ("ArrayOfArrayOfAttributeTargets", tm.TypeName, "#B3");
  845. #else
  846. Assert.AreEqual ("AttributeTargets[][]", tm.TypeName, "#B3");
  847. #endif
  848. Assert.AreEqual ("System.AttributeTargets[][]", tm.TypeFullName, "#B4");
  849. }
  850. [Test]
  851. public void TestClassTypeMapping()
  852. {
  853. XmlTypeMapping tm = Map (typeof (SimpleClass));
  854. Assert.AreEqual ("SimpleClass", tm.ElementName, "#1");
  855. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  856. Assert.AreEqual ("SimpleClass", tm.TypeName, "#3");
  857. Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass", tm.TypeFullName, "#4");
  858. }
  859. [Test]
  860. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  861. public void TestClassTypeMapping_DefaultNamespace ()
  862. {
  863. XmlTypeMapping tm = Map (typeof (SimpleClass), SomeNamespace);
  864. Assert.AreEqual (SomeNamespace, tm.Namespace, "#1");
  865. tm = Map (typeof (SimpleClass[]), SomeNamespace);
  866. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  867. tm = Map (typeof (SimpleClass[][]), SomeNamespace);
  868. Assert.AreEqual (SomeNamespace, tm.Namespace, "#3");
  869. }
  870. [Test]
  871. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  872. public void TestClassTypeMapping_Array ()
  873. {
  874. XmlTypeMapping tm = Map (typeof (SimpleClass[]));
  875. Assert.AreEqual ("ArrayOfSimpleClass", tm.ElementName, "#A1");
  876. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  877. #if NET_2_0
  878. Assert.AreEqual ("ArrayOfSimpleClass", tm.TypeName, "#A3");
  879. #else
  880. Assert.AreEqual ("SimpleClass[]", tm.TypeName, "#A3");
  881. #endif
  882. Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass[]", tm.TypeFullName, "#A4");
  883. tm = Map (typeof (SimpleClass[][]));
  884. Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.ElementName, "#B1");
  885. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  886. #if NET_2_0
  887. Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.TypeName, "#B3");
  888. #else
  889. Assert.AreEqual ("SimpleClass[][]", tm.TypeName, "#B3");
  890. #endif
  891. Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass[][]", tm.TypeFullName, "#B4");
  892. }
  893. [Test]
  894. #if ONLY_1_1
  895. [Category ("NotDotNet")] // wrong error message is reported in .NET 1.1
  896. #endif
  897. public void TypeMapping_Attribute_ComplexType ()
  898. {
  899. SoapAttributes attrs = new SoapAttributes (typeof (Field_Encoded).GetMember ("Names")[0]);
  900. attrs.SoapAttribute = new SoapAttributeAttribute (); // SoapAttribute cannot be used to encode complex types
  901. SoapAttributeOverrides overrides = new SoapAttributeOverrides ();
  902. overrides.Add (typeof (Field_Encoded), "Names", attrs);
  903. try {
  904. Map (typeof (Field_Encoded), overrides);
  905. Assert.Fail ("#A1");
  906. } catch (InvalidOperationException ex) {
  907. // Cannot serialize member 'Names' of type System.String[].
  908. // SoapAttribute cannot be used to encode complex types.
  909. Assert.IsNotNull (ex.Message, "#A2");
  910. Assert.IsTrue (ex.Message.IndexOf (typeof (string[]).FullName) != -1, "#A3");
  911. Assert.IsTrue (ex.Message.IndexOf ("SoapAttribute") != -1, "#A4");
  912. Assert.IsNull (ex.InnerException, "#A5");
  913. }
  914. }
  915. [Test]
  916. public void TypeMapping_Field ()
  917. {
  918. XmlTypeMapping tm = Map (typeof (Field));
  919. Assert.AreEqual ("Field", tm.ElementName, "#1");
  920. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  921. Assert.AreEqual ("Field", tm.TypeName, "#3");
  922. Assert.AreEqual ("MonoTests.System.Xml.TestClasses.Field", tm.TypeFullName, "#4");
  923. }
  924. [Test]
  925. public void TypeMapping_Field_DefaultNamespace ()
  926. {
  927. XmlTypeMapping tm = Map (typeof (Field), SomeNamespace);
  928. Assert.AreEqual ("Field", tm.ElementName, "#1");
  929. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  930. Assert.AreEqual ("Field", tm.TypeName, "#3");
  931. Assert.AreEqual ("MonoTests.System.Xml.TestClasses.Field", tm.TypeFullName, "#4");
  932. }
  933. [Test]
  934. public void TypeMapping_Field_Encoded ()
  935. {
  936. XmlTypeMapping tm = Map (typeof (Field_Encoded));
  937. Assert.AreEqual ("field", tm.ElementName, "#1");
  938. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  939. Assert.AreEqual ("Field_Encoded", tm.TypeName, "#3");
  940. Assert.AreEqual ("MonoTests.System.Xml.TestClasses.Field_Encoded", tm.TypeFullName, "#4");
  941. }
  942. [Test]
  943. public void TypeMapping_Field_Encoded_DefaultNamespace ()
  944. {
  945. XmlTypeMapping tm = Map (typeof (Field_Encoded), AnotherNamespace);
  946. Assert.AreEqual ("field", tm.ElementName, "#1");
  947. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  948. Assert.AreEqual ("Field_Encoded", tm.TypeName, "#3");
  949. Assert.AreEqual ("MonoTests.System.Xml.TestClasses.Field_Encoded", tm.TypeFullName, "#4");
  950. }
  951. [Test]
  952. public void TypeMapping_FlagEnum ()
  953. {
  954. XmlTypeMapping tm = Map (typeof (FlagEnum));
  955. Assert.AreEqual ("FlagEnum", tm.ElementName, "#1");
  956. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  957. Assert.AreEqual ("FlagEnum", tm.TypeName, "#3");
  958. Assert.AreEqual ("MonoTests.System.Xml.TestClasses.FlagEnum", tm.TypeFullName, "#4");
  959. }
  960. [Test]
  961. public void TypeMapping_FlagEnum_DefaultNamespace ()
  962. {
  963. XmlTypeMapping tm = Map (typeof (FlagEnum), SomeNamespace);
  964. Assert.AreEqual ("FlagEnum", tm.ElementName, "#1");
  965. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  966. Assert.AreEqual ("FlagEnum", tm.TypeName, "#3");
  967. Assert.AreEqual ("MonoTests.System.Xml.TestClasses.FlagEnum", tm.TypeFullName, "#4");
  968. }
  969. [Test]
  970. [ExpectedException (typeof (NotSupportedException))]
  971. public void TypeMapping_IDictionary ()
  972. {
  973. // The type MonoTests.System.Xml.TestClasses.DictionaryWithIndexer
  974. // is not supported because it implements IDictionary.
  975. Map (typeof (DictionaryWithIndexer));
  976. }
  977. [Test]
  978. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  979. public void TypeMapping_IEnumerable_SimpleClass ()
  980. {
  981. XmlTypeMapping tm = Map (typeof (SimpleClassEnumerable));
  982. Assert.AreEqual ("ArrayOfSimpleClass", tm.ElementName, "#1");
  983. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  984. Assert.AreEqual ("SimpleClassEnumerable", tm.TypeName, "#3");
  985. Assert.AreEqual ("MonoTests.System.XmlSerialization.SoapReflectionImporterTests.SimpleClassEnumerable", tm.TypeFullName, "#4");
  986. tm = Map (typeof (SimpleClassEnumerable[]));
  987. Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.ElementName, "#A1");
  988. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  989. #if NET_2_0
  990. Assert.AreEqual ("ArrayOfSimpleClassEnumerable", tm.TypeName, "#A3");
  991. #else
  992. Assert.AreEqual ("SimpleClassEnumerable[]", tm.TypeName, "#A3");
  993. #endif
  994. Assert.AreEqual ("MonoTests.System.XmlSerialization.SoapReflectionImporterTests.SimpleClassEnumerable[]", tm.TypeFullName, "#A4");
  995. tm = Map (typeof (SimpleClassEnumerable[][]));
  996. Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#B1");
  997. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  998. #if NET_2_0
  999. Assert.AreEqual ("ArrayOfArrayOfSimpleClassEnumerable", tm.TypeName, "#B3");
  1000. #else
  1001. Assert.AreEqual ("SimpleClassEnumerable[][]", tm.TypeName, "#B3");
  1002. #endif
  1003. Assert.AreEqual ("MonoTests.System.XmlSerialization.SoapReflectionImporterTests.SimpleClassEnumerable[][]", tm.TypeFullName, "#B4");
  1004. }
  1005. [Test]
  1006. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1007. public void TypeMapping_IEnumerable_Object ()
  1008. {
  1009. XmlTypeMapping tm = Map (typeof (ObjectEnumerable));
  1010. Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
  1011. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  1012. Assert.AreEqual ("ObjectEnumerable", tm.TypeName, "#3");
  1013. Assert.AreEqual ("MonoTests.System.XmlSerialization.SoapReflectionImporterTests.ObjectEnumerable", tm.TypeFullName, "#4");
  1014. tm = Map (typeof (ObjectEnumerable[]));
  1015. Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
  1016. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  1017. #if NET_2_0
  1018. Assert.AreEqual ("ArrayOfObjectEnumerable", tm.TypeName, "#A3");
  1019. #else
  1020. Assert.AreEqual ("ObjectEnumerable[]", tm.TypeName, "#A3");
  1021. #endif
  1022. Assert.AreEqual ("MonoTests.System.XmlSerialization.SoapReflectionImporterTests.ObjectEnumerable[]", tm.TypeFullName, "#A4");
  1023. tm = Map (typeof (ObjectEnumerable[][]));
  1024. Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
  1025. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  1026. #if NET_2_0
  1027. Assert.AreEqual ("ArrayOfArrayOfObjectEnumerable", tm.TypeName, "#B3");
  1028. #else
  1029. Assert.AreEqual ("ObjectEnumerable[][]", tm.TypeName, "#B3");
  1030. #endif
  1031. Assert.AreEqual ("MonoTests.System.XmlSerialization.SoapReflectionImporterTests.ObjectEnumerable[][]", tm.TypeFullName, "#B4");
  1032. }
  1033. [Test]
  1034. [ExpectedException (typeof (InvalidOperationException))]
  1035. public void TypeMapping_IEnumerable_Object_NoMatchingAddMethod ()
  1036. {
  1037. Map (typeof (ObjectEnumerableNoMatchingAddMethod));
  1038. }
  1039. [Test]
  1040. [ExpectedException (typeof (InvalidOperationException))]
  1041. public void TypeMapping_IEnumerable_Object_NoMatchingAddMethod_Array ()
  1042. {
  1043. Map (typeof (ObjectEnumerableNoMatchingAddMethod[]));
  1044. }
  1045. [Test]
  1046. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1047. public void TypeMapping_IEnumerable_SimpleClass_PrivateCurrent ()
  1048. {
  1049. XmlTypeMapping tm = Map (typeof (SimpleClassEnumerablePrivateCurrent));
  1050. Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
  1051. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  1052. Assert.AreEqual ("SimpleClassEnumerablePrivateCurrent", tm.TypeName, "#3");
  1053. Assert.AreEqual ("MonoTests.System.XmlSerialization.SoapReflectionImporterTests.SimpleClassEnumerablePrivateCurrent", tm.TypeFullName, "#4");
  1054. tm = Map (typeof (SimpleClassEnumerablePrivateCurrent[]));
  1055. Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
  1056. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  1057. #if NET_2_0
  1058. Assert.AreEqual ("ArrayOfSimpleClassEnumerablePrivateCurrent", tm.TypeName, "#A3");
  1059. #else
  1060. Assert.AreEqual ("SimpleClassEnumerablePrivateCurrent[]", tm.TypeName, "#A3");
  1061. #endif
  1062. Assert.AreEqual ("MonoTests.System.XmlSerialization.SoapReflectionImporterTests.SimpleClassEnumerablePrivateCurrent[]", tm.TypeFullName, "#A4");
  1063. tm = Map (typeof (SimpleClassEnumerablePrivateCurrent[][]));
  1064. Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
  1065. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  1066. #if NET_2_0
  1067. Assert.AreEqual ("ArrayOfArrayOfSimpleClassEnumerablePrivateCurrent", tm.TypeName, "#B3");
  1068. #else
  1069. Assert.AreEqual ("SimpleClassEnumerablePrivateCurrent[][]", tm.TypeName, "#B3");
  1070. #endif
  1071. Assert.AreEqual ("MonoTests.System.XmlSerialization.SoapReflectionImporterTests.SimpleClassEnumerablePrivateCurrent[][]", tm.TypeFullName, "#B4");
  1072. }
  1073. [Test]
  1074. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1075. #if ONLY_1_1
  1076. [Category ("NotDotNet")] // results in NullReferenceException in .NET 1.1 (SP1)
  1077. #endif
  1078. public void TypeMapping_IEnumerable_SimpleClass_PrivateGetEnumerator ()
  1079. {
  1080. XmlTypeMapping tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator));
  1081. Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
  1082. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  1083. Assert.AreEqual ("SimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#3");
  1084. Assert.AreEqual ("MonoTests.System.XmlSerialization.SoapReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator", tm.TypeFullName, "#4");
  1085. tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator[]));
  1086. Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
  1087. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  1088. #if NET_2_0
  1089. Assert.AreEqual ("ArrayOfSimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#A3");
  1090. #else
  1091. Assert.AreEqual ("SimpleClassEnumerablePrivateGetEnumerator[]", tm.TypeName, "#A3");
  1092. #endif
  1093. Assert.AreEqual ("MonoTests.System.XmlSerialization.SoapReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator[]", tm.TypeFullName, "#A4");
  1094. tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator[][]));
  1095. Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
  1096. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  1097. #if NET_2_0
  1098. Assert.AreEqual ("ArrayOfArrayOfSimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#B3");
  1099. #else
  1100. Assert.AreEqual ("SimpleClassEnumerablePrivateGetEnumerator[][]", tm.TypeName, "#B3");
  1101. #endif
  1102. Assert.AreEqual ("MonoTests.System.XmlSerialization.SoapReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator[][]", tm.TypeFullName, "#B4");
  1103. }
  1104. [Test]
  1105. [ExpectedException (typeof (InvalidOperationException))]
  1106. public void TypeMapping_ICollection_Object_NoMatchingAddMethod ()
  1107. {
  1108. Map (typeof (ObjectCollectionNoMatchingAddMethod));
  1109. }
  1110. [Test]
  1111. [ExpectedException (typeof (InvalidOperationException))]
  1112. public void TypeMapping_ICollection_Object_NoMatchingAddMethod_Array ()
  1113. {
  1114. Map (typeof (ObjectCollectionNoMatchingAddMethod[]));
  1115. }
  1116. [Test]
  1117. [ExpectedException (typeof (InvalidOperationException))]
  1118. public void TypeMapping_ICollection_SimpleClass_NoMatchingAddMethod ()
  1119. {
  1120. Map (typeof (SimpleClassCollectionNoMatchingAddMethod));
  1121. }
  1122. [Test]
  1123. [ExpectedException (typeof (InvalidOperationException))]
  1124. public void TypeMapping_ICollection_SimpleClass_NoMatchingAddMethod_Array ()
  1125. {
  1126. Map (typeof (SimpleClassCollectionNoMatchingAddMethod[]));
  1127. }
  1128. [Test]
  1129. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1130. public void TypeMapping_ICollection_SimpleClass ()
  1131. {
  1132. XmlTypeMapping tm = Map (typeof (SimpleClassCollection));
  1133. Assert.AreEqual ("ArrayOfSimpleClass", tm.ElementName, "#1");
  1134. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  1135. Assert.AreEqual ("SimpleClassCollection", tm.TypeName, "#3");
  1136. Assert.AreEqual ("MonoTests.System.XmlSerialization.SoapReflectionImporterTests.SimpleClassCollection", tm.TypeFullName, "#4");
  1137. tm = Map (typeof (SimpleClassCollection[]));
  1138. Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.ElementName, "#A1");
  1139. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  1140. #if NET_2_0
  1141. Assert.AreEqual ("ArrayOfSimpleClassCollection", tm.TypeName, "#A3");
  1142. #else
  1143. Assert.AreEqual ("SimpleClassCollection[]", tm.TypeName, "#A3");
  1144. #endif
  1145. Assert.AreEqual ("MonoTests.System.XmlSerialization.SoapReflectionImporterTests.SimpleClassCollection[]", tm.TypeFullName, "#A4");
  1146. tm = Map (typeof (SimpleClassCollection[][]));
  1147. Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#B1");
  1148. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  1149. #if NET_2_0
  1150. Assert.AreEqual ("ArrayOfArrayOfSimpleClassCollection", tm.TypeName, "#B3");
  1151. #else
  1152. Assert.AreEqual ("SimpleClassCollection[][]", tm.TypeName, "#B3");
  1153. #endif
  1154. Assert.AreEqual ("MonoTests.System.XmlSerialization.SoapReflectionImporterTests.SimpleClassCollection[][]", tm.TypeFullName, "#B4");
  1155. }
  1156. [Test]
  1157. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1158. public void TypeMapping_ICollection_Object ()
  1159. {
  1160. XmlTypeMapping tm = Map (typeof (ObjectCollection));
  1161. Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
  1162. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  1163. Assert.AreEqual ("ObjectCollection", tm.TypeName, "#3");
  1164. Assert.AreEqual ("MonoTests.System.XmlSerialization.SoapReflectionImporterTests.ObjectCollection", tm.TypeFullName, "#4");
  1165. tm = Map (typeof (ObjectCollection[]));
  1166. Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
  1167. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  1168. #if NET_2_0
  1169. Assert.AreEqual ("ArrayOfObjectCollection", tm.TypeName, "#A3");
  1170. #else
  1171. Assert.AreEqual ("ObjectCollection[]", tm.TypeName, "#A3");
  1172. #endif
  1173. Assert.AreEqual ("MonoTests.System.XmlSerialization.SoapReflectionImporterTests.ObjectCollection[]", tm.TypeFullName, "#A4");
  1174. tm = Map (typeof (ObjectCollection[][]));
  1175. Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
  1176. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  1177. #if NET_2_0
  1178. Assert.AreEqual ("ArrayOfArrayOfObjectCollection", tm.TypeName, "#B3");
  1179. #else
  1180. Assert.AreEqual ("ObjectCollection[][]", tm.TypeName, "#B3");
  1181. #endif
  1182. Assert.AreEqual ("MonoTests.System.XmlSerialization.SoapReflectionImporterTests.ObjectCollection[][]", tm.TypeFullName, "#B4");
  1183. }
  1184. [Test]
  1185. [ExpectedException (typeof (InvalidOperationException))]
  1186. public void TypeMapping_ICollection_Object_NoIntIndexer ()
  1187. {
  1188. Map (typeof (ObjectCollectionNoIntIndexer));
  1189. }
  1190. [Test]
  1191. [ExpectedException (typeof (InvalidOperationException))]
  1192. public void TypeMapping_ICollection_Object_NoIntIndexer_Array ()
  1193. {
  1194. Map (typeof (ObjectCollectionNoIntIndexer[]));
  1195. }
  1196. [Test]
  1197. [ExpectedException (typeof (InvalidOperationException))]
  1198. public void TypeMapping_ICollection_SimpleClass_NoIntIndexer ()
  1199. {
  1200. Map (typeof (SimpleClassCollectionNoIntIndexer));
  1201. }
  1202. [Test]
  1203. [ExpectedException (typeof (InvalidOperationException))]
  1204. public void TypeMapping_ICollection_SimpleClass_NoIntIndexer_Array ()
  1205. {
  1206. Map (typeof (SimpleClassCollectionNoIntIndexer[]));
  1207. }
  1208. [Test]
  1209. public void TypeMapping_InvalidDefault ()
  1210. {
  1211. SoapAttributes attrs = new SoapAttributes (typeof (Field_Encoded).GetMember ("Modifiers")[0]);
  1212. attrs.SoapDefaultValue = 2; // not a defined enum value
  1213. SoapAttributeOverrides overrides = new SoapAttributeOverrides ();
  1214. overrides.Add (typeof (Field_Encoded), "Modifiers", attrs);
  1215. try {
  1216. Map (typeof (Field_Encoded), overrides);
  1217. Assert.Fail ("#A1");
  1218. } catch (InvalidOperationException ex) {
  1219. // Enum System.Int32 cannot be converted to MonoTests.System.Xml.TestClasses.MapModifiers
  1220. Assert.IsNotNull (ex.Message, "#A2");
  1221. Assert.IsTrue (ex.Message.IndexOf (typeof (int).FullName) != -1, "#A3");
  1222. Assert.IsTrue (ex.Message.IndexOf (typeof (MapModifiers).FullName) != -1, "#A4");
  1223. Assert.IsNull (ex.InnerException, "#A5");
  1224. }
  1225. attrs.SoapDefaultValue = "2"; // not of the same type as the underlying enum type (System.Int32)
  1226. try {
  1227. Map (typeof (Field_Encoded), overrides);
  1228. Assert.Fail ("#B1");
  1229. } catch (InvalidOperationException ex) {
  1230. // Enum System.String cannot be converted to MonoTests.System.Xml.TestClasses.MapModifiers
  1231. Assert.IsNotNull (ex.Message, "#B2");
  1232. Assert.IsTrue (ex.Message.IndexOf (typeof (string).FullName) != -1, "#B3");
  1233. Assert.IsTrue (ex.Message.IndexOf (typeof (MapModifiers).FullName) != -1, "#B4");
  1234. Assert.IsNull (ex.InnerException, "#B5");
  1235. }
  1236. attrs.SoapDefaultValue = EnumDefaultValueNF.e2; // other enum type
  1237. try {
  1238. Map (typeof (Field_Encoded), overrides);
  1239. Assert.Fail ("#C1");
  1240. } catch (InvalidOperationException ex) {
  1241. // Enum MonoTests.System.Xml.TestClasses.EnumDefaultValueNF cannot be converted to MonoTests.System.Xml.TestClasses.MapModifiers
  1242. Assert.IsNotNull (ex.Message, "#C2");
  1243. Assert.IsTrue (ex.Message.IndexOf (typeof (EnumDefaultValueNF).FullName) != -1, "#C3");
  1244. Assert.IsTrue (ex.Message.IndexOf (typeof (MapModifiers).FullName) != -1, "#C4");
  1245. Assert.IsNull (ex.InnerException, "#C5");
  1246. }
  1247. attrs.SoapDefaultValue = (MapModifiers) 20; // non-existing enum value
  1248. try {
  1249. Map (typeof (Field_Encoded), overrides);
  1250. Assert.Fail ("#D1");
  1251. } catch (InvalidOperationException ex) {
  1252. // Value '20' cannot be converted to MonoTests.System.Xml.TestClasses.MapModifiers
  1253. Assert.IsNotNull (ex.Message, "#D2");
  1254. Assert.IsTrue (ex.Message.IndexOf ("'20'") != -1, "#D3");
  1255. Assert.IsTrue (ex.Message.IndexOf (typeof (MapModifiers).FullName) != -1, "#D4");
  1256. Assert.IsNull (ex.InnerException, "#D5");
  1257. }
  1258. }
  1259. [Test]
  1260. [Category ("NotWorking")]
  1261. public void TestImportMembersMapping()
  1262. {
  1263. Type type = typeof (SimpleClass);
  1264. SoapAttributes attrs = new SoapAttributes ();
  1265. SoapAttributeOverrides overrides = new SoapAttributeOverrides ();
  1266. overrides.Add (typeof (SimpleClass), attrs);
  1267. XmlReflectionMember[] members = new XmlReflectionMember[0];
  1268. XmlMembersMapping mm;
  1269. try
  1270. {
  1271. mm = MembersMap(type, overrides, members, true, true);
  1272. Assert.Fail("Should not be able to fetch an empty XmlMembersMapping");
  1273. }
  1274. catch (Exception)
  1275. {
  1276. }
  1277. XmlReflectionMember rm = new XmlReflectionMember();
  1278. rm.IsReturnValue = false;
  1279. rm.MemberName = "something";
  1280. rm.MemberType = typeof(string);
  1281. members = new XmlReflectionMember[1];
  1282. members[0] = rm;
  1283. mm = MembersMap(type, overrides, members, false, false);
  1284. Equals(mm.Count, 1);
  1285. XmlMemberMapping smm = mm[0];
  1286. Assert.IsFalse (smm.Any, "#1");
  1287. Assert.AreEqual ("something", smm.ElementName, "#2");
  1288. Assert.AreEqual ("something", smm.MemberName, "#3");
  1289. Assert.IsNull (smm.Namespace, "#4");
  1290. Assert.AreEqual ("System.String", smm.TypeFullName, "#5");
  1291. Assert.AreEqual ("string", smm.TypeName, "#6");
  1292. Assert.AreEqual (XmlSchemaNamespace, smm.TypeNamespace, "#7");
  1293. rm = new XmlReflectionMember();
  1294. rm.IsReturnValue = false;
  1295. rm.MemberName = "nothing";
  1296. rm.MemberType = typeof(string);
  1297. members = new XmlReflectionMember[1];
  1298. members[0] = rm;
  1299. mm = MembersMap(type, overrides, members, false, false);
  1300. Assert.AreEqual (1 , mm.Count, "#8");
  1301. }
  1302. public class Employee : IXmlSerializable
  1303. {
  1304. private string _firstName;
  1305. private string _lastName;
  1306. private string _address;
  1307. public XmlSchema GetSchema ()
  1308. {
  1309. return null;
  1310. }
  1311. public void WriteXml (XmlWriter writer)
  1312. {
  1313. writer.WriteStartElement ("employee", "urn:devx-com");
  1314. writer.WriteAttributeString ("firstName", _firstName);
  1315. writer.WriteAttributeString ("lastName", _lastName);
  1316. writer.WriteAttributeString ("address", _address);
  1317. writer.WriteEndElement ();
  1318. }
  1319. public void ReadXml (XmlReader reader)
  1320. {
  1321. XmlNodeType type = reader.MoveToContent ();
  1322. if (type == XmlNodeType.Element && reader.LocalName == "employee") {
  1323. _firstName = reader["firstName"];
  1324. _lastName = reader["lastName"];
  1325. _address = reader["address"];
  1326. }
  1327. }
  1328. }
  1329. public class NestedStruct
  1330. {
  1331. public TimeSpan Period = TimeSpan.MaxValue;
  1332. }
  1333. public class ObjectEnumerable : IEnumerable
  1334. {
  1335. public void Add (int value)
  1336. {
  1337. }
  1338. public void Add (object value)
  1339. {
  1340. }
  1341. public IEnumerator GetEnumerator ()
  1342. {
  1343. return new ArrayList ().GetEnumerator ();
  1344. }
  1345. }
  1346. public class SimpleClassEnumerable : IEnumerable
  1347. {
  1348. public void Add (int value)
  1349. {
  1350. }
  1351. public void Add (object value)
  1352. {
  1353. }
  1354. IEnumerator IEnumerable.GetEnumerator ()
  1355. {
  1356. return GetEnumerator ();
  1357. }
  1358. public SimpleClassEnumerator GetEnumerator ()
  1359. {
  1360. return new SimpleClassEnumerator (new ArrayList ());
  1361. }
  1362. }
  1363. public class SimpleClassEnumerablePrivateGetEnumerator : IEnumerable
  1364. {
  1365. public void Add (object value)
  1366. {
  1367. }
  1368. IEnumerator IEnumerable.GetEnumerator ()
  1369. {
  1370. return new ArrayList ().GetEnumerator ();
  1371. }
  1372. }
  1373. public class SimpleClassEnumerablePrivateCurrent : IEnumerable
  1374. {
  1375. public void Add (object value)
  1376. {
  1377. }
  1378. IEnumerator IEnumerable.GetEnumerator ()
  1379. {
  1380. return GetEnumerator ();
  1381. }
  1382. public NoCurrentEnumerator GetEnumerator ()
  1383. {
  1384. return new NoCurrentEnumerator (new ArrayList ());
  1385. }
  1386. }
  1387. // GetEnumerator().Current returns object, but there's no corresponding
  1388. // Add (System.Object) method
  1389. public class ObjectEnumerableNoMatchingAddMethod : IEnumerable
  1390. {
  1391. public void Add (int value)
  1392. {
  1393. }
  1394. public IEnumerator GetEnumerator ()
  1395. {
  1396. return new ArrayList ().GetEnumerator ();
  1397. }
  1398. }
  1399. // GetEnumerator().Current returns SimpleClass, but there's no
  1400. // corresponding Add (SimpleClass) method
  1401. public class SimpleClassCollectionNoMatchingAddMethod : ICollection
  1402. {
  1403. public SimpleClass this[int index] {
  1404. get {
  1405. return (SimpleClass) _list[index];
  1406. }
  1407. }
  1408. public int Count {
  1409. get { return _list.Count; }
  1410. }
  1411. public bool IsSynchronized {
  1412. get { return _list.IsSynchronized; }
  1413. }
  1414. public object SyncRoot {
  1415. get { return _list.SyncRoot; }
  1416. }
  1417. public void CopyTo (Array array, int index)
  1418. {
  1419. _list.CopyTo (array, index);
  1420. }
  1421. IEnumerator IEnumerable.GetEnumerator()
  1422. {
  1423. return GetEnumerator ();
  1424. }
  1425. public SimpleClassEnumerator GetEnumerator ()
  1426. {
  1427. return new SimpleClassEnumerator (_list);
  1428. }
  1429. private ArrayList _list = new ArrayList ();
  1430. }
  1431. // GetEnumerator().Current returns object, but there's no corresponding
  1432. // Add (System.Object) method
  1433. public class ObjectCollectionNoMatchingAddMethod : ICollection
  1434. {
  1435. public object this[int index] {
  1436. get {
  1437. return _list[index];
  1438. }
  1439. }
  1440. public int Count {
  1441. get { return _list.Count; }
  1442. }
  1443. public bool IsSynchronized {
  1444. get { return _list.IsSynchronized; }
  1445. }
  1446. public object SyncRoot {
  1447. get { return _list.SyncRoot; }
  1448. }
  1449. public void CopyTo (Array array, int index)
  1450. {
  1451. _list.CopyTo (array, index);
  1452. }
  1453. IEnumerator IEnumerable.GetEnumerator ()
  1454. {
  1455. return GetEnumerator ();
  1456. }
  1457. public IEnumerator GetEnumerator ()
  1458. {
  1459. return _list.GetEnumerator ();
  1460. }
  1461. private ArrayList _list = new ArrayList ();
  1462. }
  1463. // Does not have int indexer.
  1464. public class SimpleClassCollectionNoIntIndexer : ICollection
  1465. {
  1466. public SimpleClass this[string name] {
  1467. get {
  1468. return new SimpleClass ();
  1469. }
  1470. }
  1471. public int Count {
  1472. get { return _list.Count; }
  1473. }
  1474. public bool IsSynchronized {
  1475. get { return _list.IsSynchronized; }
  1476. }
  1477. public object SyncRoot {
  1478. get { return _list.SyncRoot; }
  1479. }
  1480. public void CopyTo (Array array, int index)
  1481. {
  1482. _list.CopyTo (array, index);
  1483. }
  1484. IEnumerator IEnumerable.GetEnumerator ()
  1485. {
  1486. return GetEnumerator ();
  1487. }
  1488. public SimpleClassEnumerator GetEnumerator ()
  1489. {
  1490. return new SimpleClassEnumerator (_list);
  1491. }
  1492. public void Add (SimpleClass value)
  1493. {
  1494. _list.Add (value);
  1495. }
  1496. private ArrayList _list = new ArrayList ();
  1497. }
  1498. // Does not have int indexer.
  1499. public class ObjectCollectionNoIntIndexer : ICollection
  1500. {
  1501. public object this[string name] {
  1502. get {
  1503. return new SimpleClass ();
  1504. }
  1505. }
  1506. public int Count {
  1507. get { return _list.Count; }
  1508. }
  1509. public bool IsSynchronized {
  1510. get { return _list.IsSynchronized; }
  1511. }
  1512. public object SyncRoot {
  1513. get { return _list.SyncRoot; }
  1514. }
  1515. public void CopyTo (Array array, int index)
  1516. {
  1517. _list.CopyTo (array, index);
  1518. }
  1519. public IEnumerator GetEnumerator ()
  1520. {
  1521. return _list.GetEnumerator ();
  1522. }
  1523. public void Add (object value)
  1524. {
  1525. _list.Add (value);
  1526. }
  1527. private ArrayList _list = new ArrayList ();
  1528. }
  1529. public class SimpleClassCollection : ICollection
  1530. {
  1531. public SimpleClass this[int index] {
  1532. get {
  1533. return (SimpleClass) _list[index];
  1534. }
  1535. }
  1536. public int Count {
  1537. get { return _list.Count; }
  1538. }
  1539. public bool IsSynchronized {
  1540. get { return _list.IsSynchronized; }
  1541. }
  1542. public object SyncRoot {
  1543. get { return _list.SyncRoot; }
  1544. }
  1545. public void CopyTo (Array array, int index)
  1546. {
  1547. _list.CopyTo (array, index);
  1548. }
  1549. IEnumerator IEnumerable.GetEnumerator ()
  1550. {
  1551. return GetEnumerator ();
  1552. }
  1553. public SimpleClassEnumerator GetEnumerator ()
  1554. {
  1555. return new SimpleClassEnumerator (_list);
  1556. }
  1557. public void Add (SimpleClass value)
  1558. {
  1559. _list.Add (value);
  1560. }
  1561. private ArrayList _list = new ArrayList ();
  1562. }
  1563. public class ObjectCollection : ICollection
  1564. {
  1565. public object this[int name] {
  1566. get {
  1567. return new SimpleClass ();
  1568. }
  1569. }
  1570. public int Count
  1571. {
  1572. get { return _list.Count; }
  1573. }
  1574. public bool IsSynchronized
  1575. {
  1576. get { return _list.IsSynchronized; }
  1577. }
  1578. public object SyncRoot
  1579. {
  1580. get { return _list.SyncRoot; }
  1581. }
  1582. public void CopyTo (Array array, int index)
  1583. {
  1584. _list.CopyTo (array, index);
  1585. }
  1586. public IEnumerator GetEnumerator ()
  1587. {
  1588. return _list.GetEnumerator ();
  1589. }
  1590. public void Add (object value)
  1591. {
  1592. _list.Add (value);
  1593. }
  1594. private ArrayList _list = new ArrayList ();
  1595. }
  1596. public class SimpleClassEnumerator : IEnumerator
  1597. {
  1598. internal SimpleClassEnumerator (ArrayList arguments)
  1599. {
  1600. IEnumerable temp = (IEnumerable) (arguments);
  1601. _baseEnumerator = temp.GetEnumerator ();
  1602. }
  1603. public SimpleClass Current
  1604. {
  1605. get { return (SimpleClass) _baseEnumerator.Current; }
  1606. }
  1607. object IEnumerator.Current
  1608. {
  1609. get { return _baseEnumerator.Current; }
  1610. }
  1611. public bool MoveNext ()
  1612. {
  1613. return _baseEnumerator.MoveNext ();
  1614. }
  1615. bool IEnumerator.MoveNext ()
  1616. {
  1617. return _baseEnumerator.MoveNext ();
  1618. }
  1619. public void Reset ()
  1620. {
  1621. _baseEnumerator.Reset ();
  1622. }
  1623. void IEnumerator.Reset ()
  1624. {
  1625. _baseEnumerator.Reset ();
  1626. }
  1627. private IEnumerator _baseEnumerator;
  1628. }
  1629. public class NoCurrentEnumerator : IEnumerator
  1630. {
  1631. internal NoCurrentEnumerator (ArrayList arguments)
  1632. {
  1633. IEnumerable temp = (IEnumerable) (arguments);
  1634. _baseEnumerator = temp.GetEnumerator ();
  1635. }
  1636. object IEnumerator.Current
  1637. {
  1638. get { return _baseEnumerator.Current; }
  1639. }
  1640. public bool MoveNext ()
  1641. {
  1642. return _baseEnumerator.MoveNext ();
  1643. }
  1644. bool IEnumerator.MoveNext ()
  1645. {
  1646. return _baseEnumerator.MoveNext ();
  1647. }
  1648. public void Reset ()
  1649. {
  1650. _baseEnumerator.Reset ();
  1651. }
  1652. void IEnumerator.Reset ()
  1653. {
  1654. _baseEnumerator.Reset ();
  1655. }
  1656. private IEnumerator _baseEnumerator;
  1657. }
  1658. }
  1659. }