XmlReflectionImporterTests.cs 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207
  1. //
  2. // System.Xml.Serialization.XmlReflectionImporterTests
  3. //
  4. // Author:
  5. // Erik LeBel ([email protected])
  6. //
  7. // (C) 2003 Erik LeBel
  8. //
  9. // FIXME test some of these with Xml Attributes attached to some members:
  10. // do the names get carried over to Element for XmlAttributeAttribute and XmlElementAttribute?
  11. //
  12. using System;
  13. using System.Collections;
  14. using System.Xml;
  15. using System.Xml.Schema;
  16. using System.Xml.Serialization;
  17. using NUnit.Framework;
  18. #if NET_2_0
  19. using System.Collections.Generic;
  20. #endif
  21. using MonoTests.System.Xml.TestClasses;
  22. namespace MonoTests.System.XmlSerialization
  23. {
  24. // debugging class
  25. internal class Debug
  26. {
  27. public static void Print(XmlTypeMapping tm)
  28. {
  29. Console.WriteLine("/XmlTypeMapping:");
  30. Console.WriteLine("ElementName: {0} ", tm.ElementName);
  31. Console.WriteLine("Namespace: {0} ", tm.Namespace);
  32. Console.WriteLine("TypeName: {0} ", tm.TypeName);
  33. Console.WriteLine("FullTypeName: {0} ", tm.TypeFullName);
  34. }
  35. public static void Print(XmlMemberMapping mm)
  36. {
  37. Console.WriteLine("/XmlMemberMapping:");
  38. Console.WriteLine("Any: {0} ", mm.Any);
  39. Console.WriteLine("ElementName: {0} ", mm.ElementName);
  40. Console.WriteLine("MemberName: {0} ", mm.MemberName);
  41. Console.WriteLine("Namespace: {0} ", mm.Namespace);
  42. Console.WriteLine("TypeFullName: {0} ", mm.TypeFullName);
  43. Console.WriteLine("TypeName: {0} ", mm.TypeName);
  44. Console.WriteLine("TypeNamespace: {0} ", mm.TypeNamespace);
  45. }
  46. }
  47. [TestFixture]
  48. public class XmlReflectionImporterTests
  49. {
  50. private const string SomeNamespace = "some:urn";
  51. private const string AnotherNamespace = "another:urn";
  52. private const string XmlSchemaNamespace = "http://www.w3.org/2001/XMLSchema";
  53. // these Map methods re-create the XmlReflectionImporter at every call.
  54. private XmlTypeMapping Map(Type t)
  55. {
  56. XmlReflectionImporter ri = new XmlReflectionImporter();
  57. XmlTypeMapping tm = ri.ImportTypeMapping(t);
  58. //Debug.Print(tm);
  59. return tm;
  60. }
  61. private XmlTypeMapping Map(Type t, XmlRootAttribute root)
  62. {
  63. XmlReflectionImporter ri = new XmlReflectionImporter();
  64. XmlTypeMapping tm = ri.ImportTypeMapping(t, root);
  65. return tm;
  66. }
  67. private XmlTypeMapping Map(Type t, string ns)
  68. {
  69. XmlReflectionImporter ri = new XmlReflectionImporter(ns);
  70. XmlTypeMapping tm = ri.ImportTypeMapping(t);
  71. //Debug.Print(tm);
  72. return tm;
  73. }
  74. private XmlTypeMapping Map (Type t, string ns, XmlRootAttribute root)
  75. {
  76. XmlReflectionImporter ri = new XmlReflectionImporter (ns);
  77. XmlTypeMapping tm = ri.ImportTypeMapping (t, root);
  78. return tm;
  79. }
  80. private XmlTypeMapping Map(Type t, XmlAttributeOverrides overrides)
  81. {
  82. XmlReflectionImporter ri = new XmlReflectionImporter(overrides);
  83. XmlTypeMapping tm = ri.ImportTypeMapping(t);
  84. //Debug.Print(tm);
  85. return tm;
  86. }
  87. private XmlMembersMapping MembersMap(Type t, XmlAttributeOverrides overrides,
  88. XmlReflectionMember [] members, bool inContainer)
  89. {
  90. XmlReflectionImporter ri = new XmlReflectionImporter(overrides);
  91. XmlMembersMapping mm = ri.ImportMembersMapping(null, null, members, inContainer);
  92. return mm;
  93. }
  94. [Test]
  95. public void TestIntTypeMapping()
  96. {
  97. XmlTypeMapping tm = Map(typeof(int));
  98. Assert.AreEqual ("int", tm.ElementName, "#1");
  99. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  100. Assert.AreEqual ("Int32", tm.TypeName, "#3");
  101. Assert.AreEqual ("System.Int32", tm.TypeFullName, "#4");
  102. }
  103. [Test]
  104. #if NET_2_0
  105. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  106. #endif
  107. public void TestIntTypeMapping_Array ()
  108. {
  109. XmlTypeMapping tm = Map(typeof(int[]));
  110. Assert.AreEqual ("ArrayOfInt", tm.ElementName, "#A1");
  111. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  112. #if NET_2_0
  113. Assert.AreEqual ("ArrayOfInt32", tm.TypeName, "#A3");
  114. #else
  115. Assert.AreEqual ("Int32[]", tm.TypeName, "#A3");
  116. #endif
  117. Assert.AreEqual ("System.Int32[]", tm.TypeFullName, "#A4");
  118. tm = Map (typeof (int[][]));
  119. Assert.AreEqual ("ArrayOfArrayOfInt", tm.ElementName, "#B1");
  120. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  121. #if NET_2_0
  122. Assert.AreEqual ("ArrayOfArrayOfInt32", tm.TypeName, "#B3");
  123. #else
  124. Assert.AreEqual ("Int32[][]", tm.TypeName, "#B3");
  125. #endif
  126. Assert.AreEqual ("System.Int32[][]", tm.TypeFullName, "#B4");
  127. tm = Map (typeof (int[][][]));
  128. Assert.AreEqual ("ArrayOfArrayOfArrayOfInt", tm.ElementName, "#C1");
  129. Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
  130. #if NET_2_0
  131. Assert.AreEqual ("ArrayOfArrayOfArrayOfInt32", tm.TypeName, "#C3");
  132. #else
  133. Assert.AreEqual ("Int32[][][]", tm.TypeName, "#C3");
  134. #endif
  135. Assert.AreEqual ("System.Int32[][][]", tm.TypeFullName, "#C4");
  136. }
  137. [Test]
  138. public void TestStringTypeMapping()
  139. {
  140. XmlTypeMapping tm = Map(typeof(string));
  141. Assert.AreEqual ("string", tm.ElementName, "#1");
  142. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  143. Assert.AreEqual ("String", tm.TypeName, "#3");
  144. Assert.AreEqual ("System.String", tm.TypeFullName, "#4");
  145. }
  146. [Test]
  147. #if NET_2_0
  148. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  149. #endif
  150. public void TestStringTypeMapping_Array ()
  151. {
  152. XmlTypeMapping tm = Map (typeof (string[]));
  153. Assert.AreEqual ("ArrayOfString", tm.ElementName, "#A1");
  154. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  155. #if NET_2_0
  156. Assert.AreEqual ("ArrayOfString", tm.TypeName, "#A3");
  157. #else
  158. Assert.AreEqual ("String[]", tm.TypeName, "#A3");
  159. #endif
  160. Assert.AreEqual ("System.String[]", tm.TypeFullName, "#A4");
  161. tm = Map (typeof (string[][]));
  162. Assert.AreEqual ("ArrayOfArrayOfString", tm.ElementName, "#B1");
  163. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  164. #if NET_2_0
  165. Assert.AreEqual ("ArrayOfArrayOfString", tm.TypeName, "#B3");
  166. #else
  167. Assert.AreEqual ("String[][]", tm.TypeName, "#B3");
  168. #endif
  169. Assert.AreEqual ("System.String[][]", tm.TypeFullName, "#B4");
  170. tm = Map (typeof (string[][][]));
  171. Assert.AreEqual ("ArrayOfArrayOfArrayOfString", tm.ElementName, "#C1");
  172. Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
  173. #if NET_2_0
  174. Assert.AreEqual ("ArrayOfArrayOfArrayOfString", tm.TypeName, "#C3");
  175. #else
  176. Assert.AreEqual ("String[][][]", tm.TypeName, "#C3");
  177. #endif
  178. Assert.AreEqual ("System.String[][][]", tm.TypeFullName, "#C4");
  179. }
  180. [Test]
  181. public void TestObjectTypeMapping()
  182. {
  183. XmlTypeMapping tm = Map(typeof(object));
  184. Assert.AreEqual ("anyType", tm.ElementName, "#1");
  185. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  186. Assert.AreEqual ("Object", tm.TypeName, "#3");
  187. Assert.AreEqual ("System.Object", tm.TypeFullName, "#4");
  188. }
  189. [Test]
  190. #if NET_2_0
  191. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  192. #endif
  193. public void TestObjectTypeMapping_Array ()
  194. {
  195. XmlTypeMapping tm = Map (typeof (object[]));
  196. Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#A1");
  197. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  198. #if NET_2_0
  199. Assert.AreEqual ("ArrayOfObject", tm.TypeName, "#A3");
  200. #else
  201. Assert.AreEqual ("Object[]", tm.TypeName, "#A3");
  202. #endif
  203. Assert.AreEqual ("System.Object[]", tm.TypeFullName, "#A4");
  204. tm = Map (typeof (object[][]));
  205. Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#B1");
  206. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  207. #if NET_2_0
  208. Assert.AreEqual ("ArrayOfArrayOfObject", tm.TypeName, "#B3");
  209. #else
  210. Assert.AreEqual ("Object[][]", tm.TypeName, "#B3");
  211. #endif
  212. Assert.AreEqual ("System.Object[][]", tm.TypeFullName, "#B4");
  213. tm = Map (typeof (object[][][]));
  214. Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
  215. Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
  216. #if NET_2_0
  217. Assert.AreEqual ("ArrayOfArrayOfArrayOfObject", tm.TypeName, "#C3");
  218. #else
  219. Assert.AreEqual ("Object[][][]", tm.TypeName, "#C3");
  220. #endif
  221. Assert.AreEqual ("System.Object[][][]", tm.TypeFullName, "#C4");
  222. }
  223. [Test]
  224. public void TestByteTypeMapping()
  225. {
  226. XmlTypeMapping tm = Map(typeof(byte));
  227. Assert.AreEqual ("unsignedByte", tm.ElementName, "#1");
  228. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  229. Assert.AreEqual ("Byte", tm.TypeName, "#3");
  230. Assert.AreEqual ("System.Byte", tm.TypeFullName, "#4");
  231. }
  232. [Test]
  233. #if NET_2_0
  234. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  235. #endif
  236. public void TestByteTypeMapping_Array ()
  237. {
  238. XmlTypeMapping tm = Map(typeof(byte[]));
  239. Assert.AreEqual ("base64Binary", tm.ElementName, "#A1");
  240. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  241. Assert.AreEqual ("Byte[]", tm.TypeName, "#A3");
  242. Assert.AreEqual ("System.Byte[]", tm.TypeFullName, "#A4");
  243. tm = Map (typeof (byte[][]));
  244. Assert.AreEqual ("ArrayOfBase64Binary", tm.ElementName, "#B1");
  245. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  246. #if NET_2_0
  247. Assert.AreEqual ("ArrayOfArrayOfByte", tm.TypeName, "#B3");
  248. #else
  249. Assert.AreEqual ("Byte[][]", tm.TypeName, "#B3");
  250. #endif
  251. Assert.AreEqual ("System.Byte[][]", tm.TypeFullName, "#B4");
  252. tm = Map (typeof (byte[][][]));
  253. Assert.AreEqual ("ArrayOfArrayOfBase64Binary", tm.ElementName, "#C1");
  254. Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
  255. #if NET_2_0
  256. Assert.AreEqual ("ArrayOfArrayOfArrayOfByte", tm.TypeName, "#C3");
  257. #else
  258. Assert.AreEqual ("Byte[][][]", tm.TypeName, "#C3");
  259. #endif
  260. Assert.AreEqual ("System.Byte[][][]", tm.TypeFullName, "#C4");
  261. }
  262. [Test]
  263. public void TestBoolTypeMapping()
  264. {
  265. XmlTypeMapping tm = Map(typeof(bool));
  266. Assert.AreEqual ("boolean", tm.ElementName, "#1");
  267. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  268. Assert.AreEqual ("Boolean", tm.TypeName, "#3");
  269. Assert.AreEqual ("System.Boolean", tm.TypeFullName, "#4");
  270. }
  271. [Test]
  272. public void TestShortTypeMapping()
  273. {
  274. XmlTypeMapping tm = Map(typeof(short));
  275. Assert.AreEqual ("short", tm.ElementName, "#1");
  276. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  277. Assert.AreEqual ("Int16", tm.TypeName, "#3");
  278. Assert.AreEqual ("System.Int16", tm.TypeFullName, "#4");
  279. }
  280. [Test]
  281. public void TestUnsignedShortTypeMapping()
  282. {
  283. XmlTypeMapping tm = Map(typeof(ushort));
  284. Assert.AreEqual ("unsignedShort", tm.ElementName, "#1");
  285. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  286. Assert.AreEqual ("UInt16", tm.TypeName, "#3");
  287. Assert.AreEqual ("System.UInt16", tm.TypeFullName, "#4");
  288. }
  289. [Test]
  290. public void TestUIntTypeMapping()
  291. {
  292. XmlTypeMapping tm = Map(typeof(uint));
  293. Assert.AreEqual ("unsignedInt", tm.ElementName, "#1");
  294. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  295. Assert.AreEqual ("UInt32", tm.TypeName, "#3");
  296. Assert.AreEqual ("System.UInt32", tm.TypeFullName, "#4");
  297. }
  298. [Test]
  299. public void TestLongTypeMapping()
  300. {
  301. XmlTypeMapping tm = Map(typeof(long));
  302. Assert.AreEqual ("long", tm.ElementName, "#1");
  303. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  304. Assert.AreEqual ("Int64", tm.TypeName, "#3");
  305. Assert.AreEqual ("System.Int64", tm.TypeFullName, "#4");
  306. }
  307. [Test]
  308. public void TestULongTypeMapping()
  309. {
  310. XmlTypeMapping tm = Map(typeof(ulong));
  311. Assert.AreEqual ("unsignedLong", tm.ElementName, "#1");
  312. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  313. Assert.AreEqual ("UInt64", tm.TypeName, "#3");
  314. Assert.AreEqual ("System.UInt64", tm.TypeFullName, "#4");
  315. }
  316. [Test]
  317. public void TestFloatTypeMapping()
  318. {
  319. XmlTypeMapping tm = Map(typeof(float));
  320. Assert.AreEqual ("float", tm.ElementName, "#1");
  321. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  322. Assert.AreEqual ("Single", tm.TypeName, "#3");
  323. Assert.AreEqual ("System.Single", tm.TypeFullName, "#4");
  324. }
  325. [Test]
  326. public void TestDoubleTypeMapping()
  327. {
  328. XmlTypeMapping tm = Map(typeof(double));
  329. Assert.AreEqual ("double", tm.ElementName, "#1");
  330. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  331. Assert.AreEqual ("Double", tm.TypeName, "#3");
  332. Assert.AreEqual ("System.Double", tm.TypeFullName, "#4");
  333. }
  334. [Test]
  335. public void TestDateTimeTypeMapping()
  336. {
  337. XmlTypeMapping tm = Map(typeof(DateTime));
  338. Assert.AreEqual ("dateTime", tm.ElementName, "#1");
  339. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  340. Assert.AreEqual ("DateTime", tm.TypeName, "#3");
  341. Assert.AreEqual ("System.DateTime", tm.TypeFullName, "#4");
  342. }
  343. [Test]
  344. #if NET_2_0
  345. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  346. #endif
  347. public void TestDateTimeTypeMapping_Array ()
  348. {
  349. XmlTypeMapping tm = Map (typeof (DateTime[]));
  350. Assert.AreEqual ("ArrayOfDateTime", tm.ElementName, "#A1");
  351. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  352. #if NET_2_0
  353. Assert.AreEqual ("ArrayOfDateTime", tm.TypeName, "#A3");
  354. #else
  355. Assert.AreEqual ("DateTime[]", tm.TypeName, "#A3");
  356. #endif
  357. Assert.AreEqual ("System.DateTime[]", tm.TypeFullName, "#A4");
  358. tm = Map (typeof (DateTime[][]));
  359. Assert.AreEqual ("ArrayOfArrayOfDateTime", tm.ElementName, "#B1");
  360. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  361. #if NET_2_0
  362. Assert.AreEqual ("ArrayOfArrayOfDateTime", tm.TypeName, "#B3");
  363. #else
  364. Assert.AreEqual ("DateTime[][]", tm.TypeName, "#B3");
  365. #endif
  366. Assert.AreEqual ("System.DateTime[][]", tm.TypeFullName, "#B4");
  367. tm = Map (typeof (DateTime[][][]));
  368. Assert.AreEqual ("ArrayOfArrayOfArrayOfDateTime", tm.ElementName, "#C1");
  369. Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
  370. #if NET_2_0
  371. Assert.AreEqual ("ArrayOfArrayOfArrayOfDateTime", tm.TypeName, "#C3");
  372. #else
  373. Assert.AreEqual ("DateTime[][][]", tm.TypeName, "#C3");
  374. #endif
  375. Assert.AreEqual ("System.DateTime[][][]", tm.TypeFullName, "#C4");
  376. }
  377. [Test]
  378. public void TestGuidTypeMapping()
  379. {
  380. XmlTypeMapping tm = Map(typeof(Guid));
  381. Assert.AreEqual ("guid", tm.ElementName, "#1");
  382. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  383. Assert.AreEqual ("Guid", tm.TypeName, "#3");
  384. Assert.AreEqual ("System.Guid", tm.TypeFullName, "#4");
  385. }
  386. [Test]
  387. #if NET_2_0
  388. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  389. #endif
  390. public void TestGuidTypeMapping_Array ()
  391. {
  392. XmlTypeMapping tm = Map (typeof (Guid[]));
  393. Assert.AreEqual ("ArrayOfGuid", tm.ElementName, "#A1");
  394. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  395. #if NET_2_0
  396. Assert.AreEqual ("ArrayOfGuid", tm.TypeName, "#A3");
  397. #else
  398. Assert.AreEqual ("Guid[]", tm.TypeName, "#A3");
  399. #endif
  400. Assert.AreEqual ("System.Guid[]", tm.TypeFullName, "#A4");
  401. tm = Map (typeof (Guid[][]));
  402. Assert.AreEqual ("ArrayOfArrayOfGuid", tm.ElementName, "#B1");
  403. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  404. #if NET_2_0
  405. Assert.AreEqual ("ArrayOfArrayOfGuid", tm.TypeName, "#B3");
  406. #else
  407. Assert.AreEqual ("Guid[][]", tm.TypeName, "#B3");
  408. #endif
  409. Assert.AreEqual ("System.Guid[][]", tm.TypeFullName, "#B4");
  410. tm = Map (typeof (Guid[][][]));
  411. Assert.AreEqual ("ArrayOfArrayOfArrayOfGuid", tm.ElementName, "#C1");
  412. Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
  413. #if NET_2_0
  414. Assert.AreEqual ("ArrayOfArrayOfArrayOfGuid", tm.TypeName, "#C3");
  415. #else
  416. Assert.AreEqual ("Guid[][][]", tm.TypeName, "#C3");
  417. #endif
  418. Assert.AreEqual ("System.Guid[][][]", tm.TypeFullName, "#C4");
  419. }
  420. [Test]
  421. public void TestDecimalTypeMapping()
  422. {
  423. XmlTypeMapping tm = Map(typeof(decimal));
  424. Assert.AreEqual ("decimal", tm.ElementName, "#1");
  425. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  426. Assert.AreEqual ("Decimal", tm.TypeName, "#3");
  427. Assert.AreEqual ("System.Decimal", tm.TypeFullName, "#4");
  428. }
  429. [Test]
  430. public void TestXmlQualifiedNameTypeMapping()
  431. {
  432. XmlTypeMapping tm = Map(typeof(XmlQualifiedName));
  433. Assert.AreEqual ("QName", tm.ElementName, "#1");
  434. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  435. Assert.AreEqual ("XmlQualifiedName", tm.TypeName, "#3");
  436. Assert.AreEqual ("System.Xml.XmlQualifiedName", tm.TypeFullName, "#4");
  437. }
  438. [Test]
  439. public void TestSByteTypeMapping()
  440. {
  441. XmlTypeMapping tm = Map(typeof(sbyte));
  442. Assert.AreEqual ("byte", tm.ElementName, "#1");
  443. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  444. Assert.AreEqual ("SByte", tm.TypeName, "#3");
  445. Assert.AreEqual ("System.SByte", tm.TypeFullName, "#4");
  446. }
  447. [Test]
  448. public void TestCharTypeMapping()
  449. {
  450. XmlTypeMapping tm = Map(typeof(char));
  451. Assert.AreEqual ("char", tm.ElementName, "#1");
  452. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  453. Assert.AreEqual ("Char", tm.TypeName, "#3");
  454. Assert.AreEqual ("System.Char", tm.TypeFullName, "#4");
  455. }
  456. [Test]
  457. #if NET_2_0
  458. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  459. #endif
  460. public void TestCharTypeMapping_Array ()
  461. {
  462. XmlTypeMapping tm = Map (typeof (char[]));
  463. Assert.AreEqual ("ArrayOfChar", tm.ElementName, "#A1");
  464. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  465. #if NET_2_0
  466. Assert.AreEqual ("ArrayOfChar", tm.TypeName, "#A3");
  467. #else
  468. Assert.AreEqual ("Char[]", tm.TypeName, "#A3");
  469. #endif
  470. Assert.AreEqual ("System.Char[]", tm.TypeFullName, "#A4");
  471. tm = Map (typeof (char[][]));
  472. Assert.AreEqual ("ArrayOfArrayOfChar", tm.ElementName, "#B1");
  473. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  474. #if NET_2_0
  475. Assert.AreEqual ("ArrayOfArrayOfChar", tm.TypeName, "#B3");
  476. #else
  477. Assert.AreEqual ("Char[][]", tm.TypeName, "#B3");
  478. #endif
  479. Assert.AreEqual ("System.Char[][]", tm.TypeFullName, "#B4");
  480. tm = Map (typeof (char[][][]));
  481. Assert.AreEqual ("ArrayOfArrayOfArrayOfChar", tm.ElementName, "#C1");
  482. Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
  483. #if NET_2_0
  484. Assert.AreEqual ("ArrayOfArrayOfArrayOfChar", tm.TypeName, "#C3");
  485. #else
  486. Assert.AreEqual ("Char[][][]", tm.TypeName, "#C3");
  487. #endif
  488. Assert.AreEqual ("System.Char[][][]", tm.TypeFullName, "#C4");
  489. }
  490. [Test]
  491. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  492. public void TestXmlNodeTypeMapping ()
  493. {
  494. Type type = typeof (XmlNode);
  495. XmlTypeMapping tm = Map (type);
  496. Assert.AreEqual (string.Empty, tm.ElementName, "#A1");
  497. Assert.IsNull (tm.Namespace, "#A2");
  498. Assert.AreEqual ("XmlNode", tm.TypeName, "#A3");
  499. Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#A4");
  500. tm = Map (type, AnotherNamespace);
  501. Assert.AreEqual (string.Empty, tm.ElementName, "#B1");
  502. Assert.IsNull (tm.Namespace, "#B2");
  503. Assert.AreEqual ("XmlNode", tm.TypeName, "#B3");
  504. Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#B4");
  505. XmlRootAttribute root = new XmlRootAttribute ("somename");
  506. root.Namespace = SomeNamespace;
  507. tm = Map (type, root);
  508. Assert.AreEqual ("somename", tm.ElementName, "#C1");
  509. Assert.IsNull (tm.Namespace, "#C2");
  510. Assert.AreEqual ("XmlNode", tm.TypeName, "#C3");
  511. Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#C4");
  512. tm = Map (type, AnotherNamespace, root);
  513. Assert.AreEqual ("somename", tm.ElementName, "#D1");
  514. Assert.IsNull (tm.Namespace, "#D2");
  515. Assert.AreEqual ("XmlNode", tm.TypeName, "#D3");
  516. Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#D4");
  517. root.Namespace = null;
  518. tm = Map (type, root);
  519. Assert.AreEqual ("somename", tm.ElementName, "#E1");
  520. Assert.IsNull (tm.Namespace, "#E2");
  521. Assert.AreEqual ("XmlNode", tm.TypeName, "#E3");
  522. Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#E4");
  523. tm = Map (type, AnotherNamespace, root);
  524. Assert.AreEqual ("somename", tm.ElementName, "#F1");
  525. Assert.IsNull (tm.Namespace, "#F2");
  526. Assert.AreEqual ("XmlNode", tm.TypeName, "#F3");
  527. Assert.AreEqual ("System.Xml.XmlNode", tm.TypeFullName, "#F4");
  528. }
  529. [Test]
  530. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  531. public void TestXmlElementTypeMapping ()
  532. {
  533. Type type = typeof (XmlElement);
  534. XmlTypeMapping tm = Map (type);
  535. Assert.AreEqual (string.Empty, tm.ElementName, "#1");
  536. Assert.IsNull (tm.Namespace, "#2");
  537. Assert.AreEqual ("XmlElement", tm.TypeName, "#3");
  538. Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#4");
  539. tm = Map (type, AnotherNamespace);
  540. Assert.AreEqual (string.Empty, tm.ElementName, "#B1");
  541. Assert.IsNull (tm.Namespace, "#B2");
  542. Assert.AreEqual ("XmlElement", tm.TypeName, "#B3");
  543. Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#B4");
  544. XmlRootAttribute root = new XmlRootAttribute ("somename");
  545. root.Namespace = SomeNamespace;
  546. tm = Map (type, root);
  547. Assert.AreEqual ("somename", tm.ElementName, "#C1");
  548. Assert.IsNull (tm.Namespace, "#C2");
  549. Assert.AreEqual ("XmlElement", tm.TypeName, "#C3");
  550. Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#C4");
  551. tm = Map (type, AnotherNamespace, root);
  552. Assert.AreEqual ("somename", tm.ElementName, "#D1");
  553. Assert.IsNull (tm.Namespace, "#D2");
  554. Assert.AreEqual ("XmlElement", tm.TypeName, "#D3");
  555. Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#D4");
  556. root.Namespace = null;
  557. tm = Map (type, root);
  558. Assert.AreEqual ("somename", tm.ElementName, "#E1");
  559. Assert.IsNull (tm.Namespace, "#E2");
  560. Assert.AreEqual ("XmlElement", tm.TypeName, "#E3");
  561. Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#E4");
  562. tm = Map (type, AnotherNamespace, root);
  563. Assert.AreEqual ("somename", tm.ElementName, "#F1");
  564. Assert.IsNull (tm.Namespace, "#F2");
  565. Assert.AreEqual ("XmlElement", tm.TypeName, "#F3");
  566. Assert.AreEqual ("System.Xml.XmlElement", tm.TypeFullName, "#F4");
  567. }
  568. [Test]
  569. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  570. public void TestXmlNotationTypeMapping ()
  571. {
  572. Type type = typeof (XmlNotation);
  573. XmlTypeMapping tm = Map (type);
  574. Assert.AreEqual (string.Empty, tm.ElementName, "#1");
  575. Assert.IsNull (tm.Namespace, "#2");
  576. Assert.AreEqual ("XmlNotation", tm.TypeName, "#3");
  577. Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#4");
  578. tm = Map (type, AnotherNamespace);
  579. Assert.AreEqual (string.Empty, tm.ElementName, "#B1");
  580. Assert.IsNull (tm.Namespace, "#B2");
  581. Assert.AreEqual ("XmlNotation", tm.TypeName, "#B3");
  582. Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#B4");
  583. XmlRootAttribute root = new XmlRootAttribute ("somename");
  584. root.Namespace = SomeNamespace;
  585. tm = Map (type, root);
  586. Assert.AreEqual ("somename", tm.ElementName, "#C1");
  587. Assert.IsNull (tm.Namespace, "#C2");
  588. Assert.AreEqual ("XmlNotation", tm.TypeName, "#C3");
  589. Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#C4");
  590. tm = Map (type, AnotherNamespace, root);
  591. Assert.AreEqual ("somename", tm.ElementName, "#D1");
  592. Assert.IsNull (tm.Namespace, "#D2");
  593. Assert.AreEqual ("XmlNotation", tm.TypeName, "#D3");
  594. Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#D4");
  595. root.Namespace = null;
  596. tm = Map (type, root);
  597. Assert.AreEqual ("somename", tm.ElementName, "#E1");
  598. Assert.IsNull (tm.Namespace, "#E2");
  599. Assert.AreEqual ("XmlNotation", tm.TypeName, "#E3");
  600. Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#E4");
  601. tm = Map (type, AnotherNamespace, root);
  602. Assert.AreEqual ("somename", tm.ElementName, "#F1");
  603. Assert.IsNull (tm.Namespace, "#F2");
  604. Assert.AreEqual ("XmlNotation", tm.TypeName, "#F3");
  605. Assert.AreEqual ("System.Xml.XmlNotation", tm.TypeFullName, "#F4");
  606. }
  607. [Test]
  608. public void TestXmlSerializableTypeMapping ()
  609. {
  610. XmlTypeMapping tm = Map (typeof (Employee));
  611. Assert.AreEqual ("Employee", tm.ElementName, "#1");
  612. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  613. Assert.AreEqual ("Employee", tm.TypeName, "#3");
  614. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.Employee", tm.TypeFullName, "#4");
  615. }
  616. [Test]
  617. #if NET_2_0
  618. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  619. #endif
  620. public void TestXmlSerializableTypeMapping_Array ()
  621. {
  622. XmlTypeMapping tm = Map (typeof (Employee[]));
  623. Assert.AreEqual ("ArrayOfEmployee", tm.ElementName, "#A1");
  624. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  625. #if NET_2_0
  626. Assert.AreEqual ("ArrayOfEmployee", tm.TypeName, "#A3");
  627. #else
  628. Assert.AreEqual ("Employee[]", tm.TypeName, "#A3");
  629. #endif
  630. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.Employee[]", tm.TypeFullName, "#A4");
  631. tm = Map (typeof (Employee[][]));
  632. Assert.AreEqual ("ArrayOfArrayOfEmployee", tm.ElementName, "#B1");
  633. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  634. #if NET_2_0
  635. Assert.AreEqual ("ArrayOfArrayOfEmployee", tm.TypeName, "#B3");
  636. #else
  637. Assert.AreEqual ("Employee[][]", tm.TypeName, "#B3");
  638. #endif
  639. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.Employee[][]", tm.TypeFullName, "#B4");
  640. tm = Map (typeof (Employee[][][]));
  641. Assert.AreEqual ("ArrayOfArrayOfArrayOfEmployee", tm.ElementName, "#C1");
  642. Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
  643. #if NET_2_0
  644. Assert.AreEqual ("ArrayOfArrayOfArrayOfEmployee", tm.TypeName, "#C3");
  645. #else
  646. Assert.AreEqual ("Employee[][][]", tm.TypeName, "#C3");
  647. #endif
  648. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.Employee[][][]", tm.TypeFullName, "#C4");
  649. }
  650. [Test]
  651. public void TestClassTypeMapping_NestedStruct ()
  652. {
  653. XmlTypeMapping tm = Map (typeof (NestedStruct));
  654. Assert.AreEqual ("NestedStruct", tm.ElementName, "#1");
  655. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  656. Assert.AreEqual ("NestedStruct", tm.TypeName, "#3");
  657. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.NestedStruct", tm.TypeFullName, "#4");
  658. }
  659. [Test]
  660. [ExpectedException (typeof (ArgumentNullException))]
  661. public void TestNullTypeMapping()
  662. {
  663. Map(null);
  664. }
  665. [Test]
  666. public void TestIntTypeMappingWithDefaultNamespaces()
  667. {
  668. XmlTypeMapping tm = Map(typeof(int), SomeNamespace);
  669. Assert.AreEqual ("int", tm.ElementName, "#1");
  670. Assert.AreEqual (SomeNamespace, tm.Namespace, "#2");
  671. Assert.AreEqual ("Int32", tm.TypeName, "#3");
  672. Assert.AreEqual ("System.Int32", tm.TypeFullName, "#4");
  673. }
  674. [Test]
  675. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  676. public void TestStructTypeMapping ()
  677. {
  678. XmlTypeMapping tm = Map (typeof (TimeSpan));
  679. Assert.AreEqual ("TimeSpan", tm.ElementName, "#1");
  680. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  681. Assert.AreEqual ("TimeSpan", tm.TypeName, "#3");
  682. Assert.AreEqual ("System.TimeSpan", tm.TypeFullName, "#4");
  683. }
  684. [Test]
  685. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  686. public void TestStructTypeMapping_Array ()
  687. {
  688. XmlTypeMapping tm = Map (typeof (TimeSpan[]));
  689. Assert.AreEqual ("ArrayOfTimeSpan", tm.ElementName, "#A1");
  690. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  691. #if NET_2_0
  692. Assert.AreEqual ("ArrayOfTimeSpan", tm.TypeName, "#A3");
  693. #else
  694. Assert.AreEqual ("TimeSpan[]", tm.TypeName, "#A3");
  695. #endif
  696. Assert.AreEqual ("System.TimeSpan[]", tm.TypeFullName, "#A4");
  697. tm = Map (typeof (TimeSpan[][]));
  698. Assert.AreEqual ("ArrayOfArrayOfTimeSpan", tm.ElementName, "#B1");
  699. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  700. #if NET_2_0
  701. Assert.AreEqual ("ArrayOfArrayOfTimeSpan", tm.TypeName, "#B3");
  702. #else
  703. Assert.AreEqual ("TimeSpan[][]", tm.TypeName, "#B3");
  704. #endif
  705. Assert.AreEqual ("System.TimeSpan[][]", tm.TypeFullName, "#B4");
  706. tm = Map (typeof (TimeSpan[][][]));
  707. Assert.AreEqual ("ArrayOfArrayOfArrayOfTimeSpan", tm.ElementName, "#C1");
  708. Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
  709. #if NET_2_0
  710. Assert.AreEqual ("ArrayOfArrayOfArrayOfTimeSpan", tm.TypeName, "#C3");
  711. #else
  712. Assert.AreEqual ("TimeSpan[][][]", tm.TypeName, "#C3");
  713. #endif
  714. Assert.AreEqual ("System.TimeSpan[][][]", tm.TypeFullName, "#C4");
  715. }
  716. [Test]
  717. public void TestEnumTypeMapping ()
  718. {
  719. XmlTypeMapping tm = Map (typeof (AttributeTargets));
  720. Assert.AreEqual ("AttributeTargets", tm.ElementName, "#1");
  721. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  722. Assert.AreEqual ("AttributeTargets", tm.TypeName, "#3");
  723. Assert.AreEqual ("System.AttributeTargets", tm.TypeFullName, "#4");
  724. }
  725. [Test]
  726. #if NET_2_0
  727. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  728. #endif
  729. public void TestEnumTypeMapping_Array ()
  730. {
  731. XmlTypeMapping tm = Map (typeof (AttributeTargets[]));
  732. Assert.AreEqual ("ArrayOfAttributeTargets", tm.ElementName, "#A1");
  733. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  734. #if NET_2_0
  735. Assert.AreEqual ("ArrayOfAttributeTargets", tm.TypeName, "#A3");
  736. #else
  737. Assert.AreEqual ("AttributeTargets[]", tm.TypeName, "#A3");
  738. #endif
  739. Assert.AreEqual ("System.AttributeTargets[]", tm.TypeFullName, "#A4");
  740. tm = Map (typeof (AttributeTargets[][]));
  741. Assert.AreEqual ("ArrayOfArrayOfAttributeTargets", tm.ElementName, "#B1");
  742. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  743. #if NET_2_0
  744. Assert.AreEqual ("ArrayOfArrayOfAttributeTargets", tm.TypeName, "#B3");
  745. #else
  746. Assert.AreEqual ("AttributeTargets[][]", tm.TypeName, "#B3");
  747. #endif
  748. Assert.AreEqual ("System.AttributeTargets[][]", tm.TypeFullName, "#B4");
  749. tm = Map (typeof (AttributeTargets[][][]));
  750. Assert.AreEqual ("ArrayOfArrayOfArrayOfAttributeTargets", tm.ElementName, "#C1");
  751. Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
  752. #if NET_2_0
  753. Assert.AreEqual ("ArrayOfArrayOfArrayOfAttributeTargets", tm.TypeName, "#C3");
  754. #else
  755. Assert.AreEqual ("AttributeTargets[][][]", tm.TypeName, "#C3");
  756. #endif
  757. Assert.AreEqual ("System.AttributeTargets[][][]", tm.TypeFullName, "#C4");
  758. }
  759. [Test]
  760. public void TestClassTypeMapping()
  761. {
  762. XmlTypeMapping tm = Map (typeof (SimpleClass));
  763. Assert.AreEqual ("SimpleClass", tm.ElementName, "#1");
  764. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  765. Assert.AreEqual ("SimpleClass", tm.TypeName, "#3");
  766. Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass", tm.TypeFullName, "#4");
  767. }
  768. [Test]
  769. #if NET_2_0
  770. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  771. #endif
  772. public void TestClassTypeMapping_Array ()
  773. {
  774. XmlTypeMapping tm = Map (typeof (SimpleClass[]));
  775. Assert.AreEqual ("ArrayOfSimpleClass", tm.ElementName, "#A1");
  776. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  777. #if NET_2_0
  778. Assert.AreEqual ("ArrayOfSimpleClass", tm.TypeName, "#A3");
  779. #else
  780. Assert.AreEqual ("SimpleClass[]", tm.TypeName, "#A3");
  781. #endif
  782. Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass[]", tm.TypeFullName, "#A4");
  783. tm = Map (typeof (SimpleClass[][]));
  784. Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.ElementName, "#B1");
  785. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  786. #if NET_2_0
  787. Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.TypeName, "#B3");
  788. #else
  789. Assert.AreEqual ("SimpleClass[][]", tm.TypeName, "#B3");
  790. #endif
  791. Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass[][]", tm.TypeFullName, "#B4");
  792. tm = Map (typeof (SimpleClass[][][]));
  793. Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#C1");
  794. Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
  795. #if NET_2_0
  796. Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.TypeName, "#C3");
  797. #else
  798. Assert.AreEqual ("SimpleClass[][][]", tm.TypeName, "#C3");
  799. #endif
  800. Assert.AreEqual ("MonoTests.System.Xml.TestClasses.SimpleClass[][][]", tm.TypeFullName, "#C4");
  801. }
  802. [Test]
  803. [ExpectedException (typeof (NotSupportedException))]
  804. public void TypeMapping_IDictionary ()
  805. {
  806. // The type MonoTests.System.Xml.TestClasses.DictionaryWithIndexer
  807. // is not supported because it implements IDictionary.
  808. Map (typeof (DictionaryWithIndexer));
  809. }
  810. [Test]
  811. #if NET_2_0
  812. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  813. #endif
  814. public void TypeMapping_IEnumerable_SimpleClass ()
  815. {
  816. XmlTypeMapping tm = Map (typeof (SimpleClassEnumerable));
  817. Assert.AreEqual ("ArrayOfSimpleClass", tm.ElementName, "#1");
  818. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  819. Assert.AreEqual ("SimpleClassEnumerable", tm.TypeName, "#3");
  820. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerable", tm.TypeFullName, "#4");
  821. tm = Map (typeof (SimpleClassEnumerable[]));
  822. Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.ElementName, "#A1");
  823. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  824. #if NET_2_0
  825. Assert.AreEqual ("ArrayOfSimpleClassEnumerable", tm.TypeName, "#A3");
  826. #else
  827. Assert.AreEqual ("SimpleClassEnumerable[]", tm.TypeName, "#A3");
  828. #endif
  829. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerable[]", tm.TypeFullName, "#A4");
  830. tm = Map (typeof (SimpleClassEnumerable[][]));
  831. Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#B1");
  832. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  833. #if NET_2_0
  834. Assert.AreEqual ("ArrayOfArrayOfSimpleClassEnumerable", tm.TypeName, "#B3");
  835. #else
  836. Assert.AreEqual ("SimpleClassEnumerable[][]", tm.TypeName, "#B3");
  837. #endif
  838. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerable[][]", tm.TypeFullName, "#B4");
  839. tm = Map (typeof (SimpleClassEnumerable[][][]));
  840. Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#C1");
  841. Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
  842. #if NET_2_0
  843. Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassEnumerable", tm.TypeName, "#C3");
  844. #else
  845. Assert.AreEqual ("SimpleClassEnumerable[][][]", tm.TypeName, "#C3");
  846. #endif
  847. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerable[][][]", tm.TypeFullName, "#C4");
  848. }
  849. [Test]
  850. #if NET_2_0
  851. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  852. #endif
  853. public void TypeMapping_IEnumerable_Object ()
  854. {
  855. XmlTypeMapping tm = Map (typeof (ObjectEnumerable));
  856. Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
  857. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  858. Assert.AreEqual ("ObjectEnumerable", tm.TypeName, "#3");
  859. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectEnumerable", tm.TypeFullName, "#4");
  860. tm = Map (typeof (ObjectEnumerable[]));
  861. Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
  862. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  863. #if NET_2_0
  864. Assert.AreEqual ("ArrayOfObjectEnumerable", tm.TypeName, "#A3");
  865. #else
  866. Assert.AreEqual ("ObjectEnumerable[]", tm.TypeName, "#A3");
  867. #endif
  868. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectEnumerable[]", tm.TypeFullName, "#A4");
  869. tm = Map (typeof (ObjectEnumerable[][]));
  870. Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
  871. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  872. #if NET_2_0
  873. Assert.AreEqual ("ArrayOfArrayOfObjectEnumerable", tm.TypeName, "#B3");
  874. #else
  875. Assert.AreEqual ("ObjectEnumerable[][]", tm.TypeName, "#B3");
  876. #endif
  877. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectEnumerable[][]", tm.TypeFullName, "#B4");
  878. tm = Map (typeof (ObjectEnumerable[][][]));
  879. Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
  880. Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
  881. #if NET_2_0
  882. Assert.AreEqual ("ArrayOfArrayOfArrayOfObjectEnumerable", tm.TypeName, "#C3");
  883. #else
  884. Assert.AreEqual ("ObjectEnumerable[][][]", tm.TypeName, "#C3");
  885. #endif
  886. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectEnumerable[][][]", tm.TypeFullName, "#C4");
  887. }
  888. [Test]
  889. [ExpectedException (typeof (InvalidOperationException))]
  890. public void TypeMapping_IEnumerable_Object_NoMatchingAddMethod ()
  891. {
  892. Map (typeof (ObjectEnumerableNoMatchingAddMethod));
  893. }
  894. [Test]
  895. [ExpectedException (typeof (InvalidOperationException))]
  896. public void TypeMapping_IEnumerable_Object_NoMatchingAddMethod_Array ()
  897. {
  898. Map (typeof (ObjectEnumerableNoMatchingAddMethod[]));
  899. }
  900. [Test]
  901. #if NET_2_0
  902. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  903. #endif
  904. public void TypeMapping_IEnumerable_SimpleClass_PrivateCurrent ()
  905. {
  906. XmlTypeMapping tm = Map (typeof (SimpleClassEnumerablePrivateCurrent));
  907. Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
  908. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  909. Assert.AreEqual ("SimpleClassEnumerablePrivateCurrent", tm.TypeName, "#3");
  910. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateCurrent", tm.TypeFullName, "#4");
  911. tm = Map (typeof (SimpleClassEnumerablePrivateCurrent[]));
  912. Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
  913. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  914. #if NET_2_0
  915. Assert.AreEqual ("ArrayOfSimpleClassEnumerablePrivateCurrent", tm.TypeName, "#A3");
  916. #else
  917. Assert.AreEqual ("SimpleClassEnumerablePrivateCurrent[]", tm.TypeName, "#A3");
  918. #endif
  919. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateCurrent[]", tm.TypeFullName, "#A4");
  920. tm = Map (typeof (SimpleClassEnumerablePrivateCurrent[][]));
  921. Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
  922. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  923. #if NET_2_0
  924. Assert.AreEqual ("ArrayOfArrayOfSimpleClassEnumerablePrivateCurrent", tm.TypeName, "#B3");
  925. #else
  926. Assert.AreEqual ("SimpleClassEnumerablePrivateCurrent[][]", tm.TypeName, "#B3");
  927. #endif
  928. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateCurrent[][]", tm.TypeFullName, "#B4");
  929. tm = Map (typeof (SimpleClassEnumerablePrivateCurrent[][][]));
  930. Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
  931. Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
  932. #if NET_2_0
  933. Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassEnumerablePrivateCurrent", tm.TypeName, "#C3");
  934. #else
  935. Assert.AreEqual ("SimpleClassEnumerablePrivateCurrent[][][]", tm.TypeName, "#C3");
  936. #endif
  937. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateCurrent[][][]", tm.TypeFullName, "#C4");
  938. }
  939. [Test]
  940. #if NET_2_0
  941. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  942. #endif
  943. #if ONLY_1_1
  944. [Category ("NotDotNet")] // results in NullReferenceException in .NET 1.1 (SP1)
  945. #endif
  946. public void TypeMapping_IEnumerable_SimpleClass_PrivateGetEnumerator ()
  947. {
  948. XmlTypeMapping tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator));
  949. Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
  950. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  951. Assert.AreEqual ("SimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#3");
  952. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator", tm.TypeFullName, "#4");
  953. tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator[]));
  954. Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
  955. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  956. #if NET_2_0
  957. Assert.AreEqual ("ArrayOfSimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#A3");
  958. #else
  959. Assert.AreEqual ("SimpleClassEnumerablePrivateGetEnumerator[]", tm.TypeName, "#A3");
  960. #endif
  961. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator[]", tm.TypeFullName, "#A4");
  962. tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator[][]));
  963. Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
  964. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  965. #if NET_2_0
  966. Assert.AreEqual ("ArrayOfArrayOfSimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#B3");
  967. #else
  968. Assert.AreEqual ("SimpleClassEnumerablePrivateGetEnumerator[][]", tm.TypeName, "#B3");
  969. #endif
  970. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator[][]", tm.TypeFullName, "#B4");
  971. tm = Map (typeof (SimpleClassEnumerablePrivateGetEnumerator[][][]));
  972. Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
  973. Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
  974. #if NET_2_0
  975. Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassEnumerablePrivateGetEnumerator", tm.TypeName, "#C3");
  976. #else
  977. Assert.AreEqual ("SimpleClassEnumerablePrivateGetEnumerator[][][]", tm.TypeName, "#C3");
  978. #endif
  979. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassEnumerablePrivateGetEnumerator[][][]", tm.TypeFullName, "#C4");
  980. }
  981. [Test]
  982. [ExpectedException (typeof (InvalidOperationException))]
  983. public void TypeMapping_ICollection_Object_NoMatchingAddMethod ()
  984. {
  985. Map (typeof (ObjectCollectionNoMatchingAddMethod));
  986. }
  987. [Test]
  988. [ExpectedException (typeof (InvalidOperationException))]
  989. public void TypeMapping_ICollection_Object_NoMatchingAddMethod_Array ()
  990. {
  991. Map (typeof (ObjectCollectionNoMatchingAddMethod[]));
  992. }
  993. [Test]
  994. [ExpectedException (typeof (InvalidOperationException))]
  995. public void TypeMapping_ICollection_SimpleClass_NoMatchingAddMethod ()
  996. {
  997. Map (typeof (SimpleClassCollectionNoMatchingAddMethod));
  998. }
  999. [Test]
  1000. [ExpectedException (typeof (InvalidOperationException))]
  1001. public void TypeMapping_ICollection_SimpleClass_NoMatchingAddMethod_Array ()
  1002. {
  1003. Map (typeof (SimpleClassCollectionNoMatchingAddMethod[]));
  1004. }
  1005. [Test]
  1006. #if NET_2_0
  1007. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1008. #endif
  1009. public void TypeMapping_ICollection_SimpleClass ()
  1010. {
  1011. XmlTypeMapping tm = Map (typeof (SimpleClassCollection));
  1012. Assert.AreEqual ("ArrayOfSimpleClass", tm.ElementName, "#1");
  1013. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  1014. Assert.AreEqual ("SimpleClassCollection", tm.TypeName, "#3");
  1015. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassCollection", tm.TypeFullName, "#4");
  1016. tm = Map (typeof (SimpleClassCollection[]));
  1017. Assert.AreEqual ("ArrayOfArrayOfSimpleClass", tm.ElementName, "#A1");
  1018. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  1019. #if NET_2_0
  1020. Assert.AreEqual ("ArrayOfSimpleClassCollection", tm.TypeName, "#A3");
  1021. #else
  1022. Assert.AreEqual ("SimpleClassCollection[]", tm.TypeName, "#A3");
  1023. #endif
  1024. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassCollection[]", tm.TypeFullName, "#A4");
  1025. tm = Map (typeof (SimpleClassCollection[][]));
  1026. Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#B1");
  1027. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  1028. #if NET_2_0
  1029. Assert.AreEqual ("ArrayOfArrayOfSimpleClassCollection", tm.TypeName, "#B3");
  1030. #else
  1031. Assert.AreEqual ("SimpleClassCollection[][]", tm.TypeName, "#B3");
  1032. #endif
  1033. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassCollection[][]", tm.TypeFullName, "#B4");
  1034. tm = Map (typeof (SimpleClassCollection[][][]));
  1035. Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfSimpleClass", tm.ElementName, "#C1");
  1036. Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
  1037. #if NET_2_0
  1038. Assert.AreEqual ("ArrayOfArrayOfArrayOfSimpleClassCollection", tm.TypeName, "#C3");
  1039. #else
  1040. Assert.AreEqual ("SimpleClassCollection[][][]", tm.TypeName, "#C3");
  1041. #endif
  1042. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.SimpleClassCollection[][][]", tm.TypeFullName, "#C4");
  1043. }
  1044. [Test]
  1045. #if NET_2_0
  1046. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1047. #endif
  1048. public void TypeMapping_ICollection_Object ()
  1049. {
  1050. XmlTypeMapping tm = Map (typeof (ObjectCollection));
  1051. Assert.AreEqual ("ArrayOfAnyType", tm.ElementName, "#1");
  1052. Assert.AreEqual (string.Empty, tm.Namespace, "#2");
  1053. Assert.AreEqual ("ObjectCollection", tm.TypeName, "#3");
  1054. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectCollection", tm.TypeFullName, "#4");
  1055. tm = Map (typeof (ObjectCollection[]));
  1056. Assert.AreEqual ("ArrayOfArrayOfAnyType", tm.ElementName, "#A1");
  1057. Assert.AreEqual (string.Empty, tm.Namespace, "#A2");
  1058. #if NET_2_0
  1059. Assert.AreEqual ("ArrayOfObjectCollection", tm.TypeName, "#A3");
  1060. #else
  1061. Assert.AreEqual ("ObjectCollection[]", tm.TypeName, "#A3");
  1062. #endif
  1063. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectCollection[]", tm.TypeFullName, "#A4");
  1064. tm = Map (typeof (ObjectCollection[][]));
  1065. Assert.AreEqual ("ArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#B1");
  1066. Assert.AreEqual (string.Empty, tm.Namespace, "#B2");
  1067. #if NET_2_0
  1068. Assert.AreEqual ("ArrayOfArrayOfObjectCollection", tm.TypeName, "#B3");
  1069. #else
  1070. Assert.AreEqual ("ObjectCollection[][]", tm.TypeName, "#B3");
  1071. #endif
  1072. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectCollection[][]", tm.TypeFullName, "#B4");
  1073. tm = Map (typeof (ObjectCollection[][][]));
  1074. Assert.AreEqual ("ArrayOfArrayOfArrayOfArrayOfAnyType", tm.ElementName, "#C1");
  1075. Assert.AreEqual (string.Empty, tm.Namespace, "#C2");
  1076. #if NET_2_0
  1077. Assert.AreEqual ("ArrayOfArrayOfArrayOfObjectCollection", tm.TypeName, "#C3");
  1078. #else
  1079. Assert.AreEqual ("ObjectCollection[][][]", tm.TypeName, "#C3");
  1080. #endif
  1081. Assert.AreEqual ("MonoTests.System.XmlSerialization.XmlReflectionImporterTests.ObjectCollection[][][]", tm.TypeFullName, "#C4");
  1082. }
  1083. [Test]
  1084. [ExpectedException (typeof (InvalidOperationException))]
  1085. public void TypeMapping_ICollection_Object_NoIntIndexer ()
  1086. {
  1087. Map (typeof (ObjectCollectionNoIntIndexer));
  1088. }
  1089. [Test]
  1090. [ExpectedException (typeof (InvalidOperationException))]
  1091. public void TypeMapping_ICollection_Object_NoIntIndexer_Array ()
  1092. {
  1093. Map (typeof (ObjectCollectionNoIntIndexer[]));
  1094. }
  1095. [Test]
  1096. [ExpectedException (typeof (InvalidOperationException))]
  1097. public void TypeMapping_ICollection_SimpleClass_NoIntIndexer ()
  1098. {
  1099. Map (typeof (SimpleClassCollectionNoIntIndexer));
  1100. }
  1101. [Test]
  1102. [ExpectedException (typeof (InvalidOperationException))]
  1103. public void TypeMapping_ICollection_SimpleClass_NoIntIndexer_Array ()
  1104. {
  1105. Map (typeof (SimpleClassCollectionNoIntIndexer[]));
  1106. }
  1107. [Test]
  1108. public void TypeMapping_InvalidDefault ()
  1109. {
  1110. XmlAttributes attrs = new XmlAttributes (typeof (Field).GetMember ("Modifiers") [0]);
  1111. attrs.XmlDefaultValue = 2; // not a defined enum value
  1112. XmlAttributeOverrides overrides = new XmlAttributeOverrides ();
  1113. overrides.Add (typeof (Field), "Modifiers", attrs);
  1114. try {
  1115. Map (typeof (Field), overrides);
  1116. Assert.Fail ("#A1");
  1117. } catch (InvalidOperationException ex) {
  1118. // There was an error reflecting type MonoTests.System.Xml.TestClasses.Field
  1119. Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
  1120. Assert.IsNotNull (ex.Message, "#A3");
  1121. Assert.IsTrue (ex.Message.IndexOf (typeof (Field).FullName) != -1, "#A4");
  1122. Assert.IsNotNull (ex.InnerException, "#A5");
  1123. // There was an error reflecting field 'Modifiers'
  1124. Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.GetType (), "#A6");
  1125. Assert.IsNotNull (ex.InnerException.Message, "#A7");
  1126. Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#A8");
  1127. Assert.IsNotNull (ex.InnerException.InnerException, "#A9");
  1128. // Value '2' cannot be converted to System.Int32
  1129. Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.InnerException.GetType (), "#A10");
  1130. Assert.IsNotNull (ex.InnerException.InnerException.Message, "#A11");
  1131. Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("'2'") != -1, "#A12");
  1132. Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (int).FullName) != -1, "#A13");
  1133. Assert.IsNull (ex.InnerException.InnerException.InnerException, "#A14");
  1134. }
  1135. attrs.XmlDefaultValue = "2"; // not of the same type as the underlying enum type (System.Int32)
  1136. try {
  1137. Map (typeof (Field), overrides);
  1138. Assert.Fail ("#B1");
  1139. } catch (InvalidOperationException ex) {
  1140. // There was an error reflecting type MonoTests.System.Xml.TestClasses.Field
  1141. Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
  1142. Assert.IsNotNull (ex.Message, "#B3");
  1143. Assert.IsTrue (ex.Message.IndexOf (typeof (Field).FullName) != -1, "#B4");
  1144. Assert.IsNotNull (ex.InnerException, "#B5");
  1145. // There was an error reflecting field 'Modifiers'
  1146. Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.GetType (), "#B6");
  1147. Assert.IsNotNull (ex.InnerException.Message, "#B7");
  1148. Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#B8");
  1149. Assert.IsNotNull (ex.InnerException.InnerException, "#B9");
  1150. // Enum underlying type and the object must be same type or object.
  1151. // Type passed in was 'System.String'; the enum underlying type was
  1152. // 'System.Int32'.
  1153. Assert.AreEqual (typeof (ArgumentException), ex.InnerException.InnerException.GetType (), "#B10");
  1154. Assert.IsNotNull (ex.InnerException.InnerException.Message, "#B11");
  1155. Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (string).FullName) != -1, "#B12");
  1156. Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (int).FullName) != -1, "#B13");
  1157. Assert.IsNull (ex.InnerException.InnerException.InnerException, "#B14");
  1158. }
  1159. attrs.XmlDefaultValue = EnumDefaultValueNF.e2; // other enum type
  1160. try {
  1161. Map (typeof (Field), overrides);
  1162. Assert.Fail ("#C1");
  1163. } catch (InvalidOperationException ex) {
  1164. // There was an error reflecting type MonoTests.System.Xml.TestClasses.Field
  1165. Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
  1166. Assert.IsNotNull (ex.Message, "#C3");
  1167. Assert.IsTrue (ex.Message.IndexOf (typeof (Field).FullName) != -1, "#C4");
  1168. Assert.IsNotNull (ex.InnerException, "#C5");
  1169. // There was an error reflecting field 'Modifiers'
  1170. Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.GetType (), "#C6");
  1171. Assert.IsNotNull (ex.InnerException.Message, "#C7");
  1172. Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#C8");
  1173. Assert.IsNotNull (ex.InnerException.InnerException, "#C9");
  1174. // Object must be the same type as the enum. The type passed in
  1175. // was MonoTests.System.Xml.TestClasses.EnumDefaultValueNF; the
  1176. // enum type was MonoTests.System.Xml.TestClasses.MapModifiers
  1177. Assert.AreEqual (typeof (ArgumentException), ex.InnerException.InnerException.GetType (), "#C10");
  1178. Assert.IsNotNull (ex.InnerException.InnerException.Message, "#C11");
  1179. Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (EnumDefaultValueNF).FullName) != -1, "#C12");
  1180. Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (MapModifiers).FullName) != -1, "#C13");
  1181. Assert.IsNull (ex.InnerException.InnerException.InnerException, "#C14");
  1182. }
  1183. attrs.XmlDefaultValue = (MapModifiers) 20; // non-existing enum value
  1184. try {
  1185. Map (typeof (Field), overrides);
  1186. Assert.Fail ("#D1");
  1187. } catch (InvalidOperationException ex) {
  1188. // There was an error reflecting type MonoTests.System.Xml.TestClasses.Field
  1189. Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
  1190. Assert.IsNotNull (ex.Message, "#D3");
  1191. Assert.IsTrue (ex.Message.IndexOf (typeof (Field).FullName) != -1, "#D4");
  1192. Assert.IsNotNull (ex.InnerException, "#D5");
  1193. // There was an error reflecting field 'Modifiers'
  1194. Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.GetType (), "#D6");
  1195. Assert.IsNotNull (ex.InnerException.Message, "#D7");
  1196. Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#D8");
  1197. Assert.IsNotNull (ex.InnerException.InnerException, "#D9");
  1198. // Value '20' cannot be converted to MonoTests.System.Xml.TestClasses.MapModifiers
  1199. Assert.AreEqual (typeof (InvalidOperationException), ex.InnerException.InnerException.GetType (), "#D10");
  1200. Assert.IsNotNull (ex.InnerException.InnerException.Message, "#D11");
  1201. Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("'20'") != -1, "#D12");
  1202. Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (MapModifiers).FullName) != -1, "#D13");
  1203. Assert.IsNull (ex.InnerException.InnerException.InnerException, "#D14");
  1204. }
  1205. }
  1206. [Test]
  1207. [ExpectedException (typeof (ArgumentNullException))]
  1208. public void TypeMapping_Null ()
  1209. {
  1210. Map ((Type) null);
  1211. }
  1212. [Test]
  1213. [ExpectedException (typeof (NotSupportedException))]
  1214. public void TypeMapping_Void ()
  1215. {
  1216. Map (typeof (void));
  1217. }
  1218. [Test]
  1219. public void TypeMapping_WrongChoices ()
  1220. {
  1221. try {
  1222. Map (typeof (WrongChoices));
  1223. Assert.Fail ("#1");
  1224. } catch (InvalidOperationException ex) {
  1225. // There was an error reflecting type 'MonoTests.System.Xml.TestClasses.WrongChoices'
  1226. Assert.IsNotNull (ex.Message, "#2");
  1227. Assert.IsTrue (ex.Message.IndexOf ("'" + typeof (WrongChoices).FullName + "'") != -1, "#3");
  1228. Assert.IsNotNull (ex.InnerException, "#4");
  1229. // There was an error reflecting field 'MyChoice'
  1230. Assert.IsNotNull (ex.InnerException.Message, "#5");
  1231. Assert.IsTrue (ex.InnerException.Message.IndexOf ("'MyChoice'") != -1, "#6");
  1232. Assert.IsNotNull (ex.InnerException.InnerException, "#7");
  1233. // Type MonoTests.System.Xml.TestClasses.ItemChoiceType is missing
  1234. // enumeration value 'StrangeOne' for element 'StrangeOne' from
  1235. // namespace ''.
  1236. Assert.IsNotNull (ex.InnerException.InnerException.Message, "#8");
  1237. Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (ItemChoiceType).FullName) != -1, "#9");
  1238. Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("'StrangeOne'") != -1, "#10");
  1239. Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("''") != -1, "#11");
  1240. }
  1241. }
  1242. [Test] // bug #77591
  1243. public void TypeMapping_XmlText_PrimitiveTypes ()
  1244. {
  1245. XmlAttributeOverrides overrides = null;
  1246. XmlAttributes attrs = null;
  1247. overrides = new XmlAttributeOverrides ();
  1248. attrs = new XmlAttributes ();
  1249. attrs.XmlText = new XmlTextAttribute (typeof (int));
  1250. overrides.Add (typeof (Field), "Modifiers", attrs);
  1251. try {
  1252. Map (typeof (Field), overrides);
  1253. Assert.Fail ("#A1");
  1254. } catch (InvalidOperationException ex) {
  1255. // There was an error reflecting type 'MonoTests.System.Xml.TestClasses.Field'
  1256. Assert.IsNotNull (ex.Message, "#A2");
  1257. Assert.IsTrue (ex.Message.IndexOf ("'" + typeof (Field).FullName + "'") != -1, "#A3");
  1258. Assert.IsNotNull (ex.InnerException, "#A4");
  1259. // There was an error reflecting field 'Modifiers'
  1260. Assert.IsNotNull (ex.InnerException.Message, "#A5");
  1261. Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#A6");
  1262. Assert.IsNotNull (ex.InnerException.InnerException, "#A7");
  1263. // The type for XmlText may not be specified for primitive types
  1264. Assert.IsNotNull (ex.InnerException.InnerException.Message, "#A8");
  1265. Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("XmlText") != -1, "#A9");
  1266. }
  1267. overrides = new XmlAttributeOverrides ();
  1268. attrs = new XmlAttributes ();
  1269. attrs.XmlText = new XmlTextAttribute (typeof (int));
  1270. overrides.Add (typeof (Field), "Street", attrs);
  1271. try {
  1272. Map (typeof (Field), overrides);
  1273. Assert.Fail ("#B1");
  1274. } catch (InvalidOperationException ex) {
  1275. // There was an error reflecting type 'MonoTests.System.Xml.TestClasses.Field'
  1276. Assert.IsNotNull (ex.Message, "#B2");
  1277. Assert.IsTrue (ex.Message.IndexOf ("'" + typeof (Field).FullName + "'") != -1, "#B3");
  1278. Assert.IsNotNull (ex.InnerException, "#B4");
  1279. // There was an error reflecting field 'Street'
  1280. Assert.IsNotNull (ex.InnerException.Message, "#B5");
  1281. Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Street'") != -1, "#B6");
  1282. Assert.IsNotNull (ex.InnerException.InnerException, "#B7");
  1283. // The type for XmlText may not be specified for primitive types
  1284. Assert.IsNotNull (ex.InnerException.InnerException.Message, "#B8");
  1285. Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("XmlText") != -1, "#B9");
  1286. }
  1287. overrides = new XmlAttributeOverrides ();
  1288. attrs = new XmlAttributes ();
  1289. attrs.XmlText = new XmlTextAttribute (typeof (MapModifiers));
  1290. overrides.Add (typeof (Field), "Modifiers", attrs);
  1291. Map (typeof (Field), overrides);
  1292. overrides = new XmlAttributeOverrides ();
  1293. attrs = new XmlAttributes ();
  1294. attrs.XmlText = new XmlTextAttribute (typeof (string));
  1295. overrides.Add (typeof (Field), "Street", attrs);
  1296. Map (typeof (Field), overrides);
  1297. }
  1298. [Test]
  1299. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1300. public void TestImportMembersMapping()
  1301. {
  1302. Type type = typeof(SimpleClass);
  1303. XmlAttributes attrs = new XmlAttributes();
  1304. XmlAttributeOverrides overrides = new XmlAttributeOverrides();
  1305. overrides.Add(typeof(SimpleClass), attrs);
  1306. XmlReflectionMember[] members = new XmlReflectionMember[0];
  1307. XmlMembersMapping mm;
  1308. try
  1309. {
  1310. mm = MembersMap(type, overrides, members, true);
  1311. Assert.Fail("Should not be able to fetch an empty XmlMembersMapping");
  1312. }
  1313. catch (Exception)
  1314. {
  1315. }
  1316. XmlReflectionMember rm = new XmlReflectionMember();
  1317. rm.IsReturnValue = false;
  1318. rm.MemberName = "something";
  1319. rm.MemberType = typeof(string);
  1320. members = new XmlReflectionMember[1];
  1321. members[0] = rm;
  1322. mm = MembersMap(type, overrides, members, false);
  1323. Equals(mm.Count, 1);
  1324. XmlMemberMapping smm = mm[0];
  1325. Assert.IsFalse (smm.Any, "#1");
  1326. Assert.AreEqual ("something", smm.ElementName, "#2");
  1327. Assert.AreEqual ("something", smm.MemberName, "#3");
  1328. Assert.IsNull (smm.Namespace, "#4");
  1329. Assert.AreEqual ("System.String", smm.TypeFullName, "#5");
  1330. Assert.AreEqual ("string", smm.TypeName, "#6");
  1331. #if NET_2_0
  1332. Assert.AreEqual (XmlSchemaNamespace, smm.TypeNamespace, "#7");
  1333. #else
  1334. Assert.IsNull (smm.TypeNamespace, "#7");
  1335. #endif
  1336. rm = new XmlReflectionMember();
  1337. rm.IsReturnValue = false;
  1338. rm.MemberName = "nothing";
  1339. rm.MemberType = typeof(string);
  1340. members = new XmlReflectionMember[1];
  1341. members[0] = rm;
  1342. mm = MembersMap(type, overrides, members, false);
  1343. Assert.AreEqual (1, mm.Count, "#8");
  1344. }
  1345. [Test]
  1346. public void TestIntTypeMappingWithXmlRootAttribute()
  1347. {
  1348. const string TheNamespace = "another:urn";
  1349. XmlRootAttribute root = new XmlRootAttribute("price");
  1350. root.Namespace = TheNamespace;
  1351. XmlTypeMapping tm = Map(typeof(int), root);
  1352. Assert.AreEqual ("price", tm.ElementName, "#1");
  1353. Assert.AreEqual (TheNamespace, tm.Namespace, "#2");
  1354. Assert.AreEqual ("Int32", tm.TypeName, "#3");
  1355. Assert.AreEqual ("System.Int32", tm.TypeFullName, "#4");
  1356. }
  1357. [Test]
  1358. [ExpectedException (typeof (InvalidOperationException))]
  1359. public void TestSerializeWrongChoice ()
  1360. {
  1361. new XmlSerializer (typeof(WrongChoices));
  1362. }
  1363. [Test]
  1364. public void XmlArrayOnByteArray ()
  1365. {
  1366. new XmlSerializer (typeof (XmlArrayOnByteArrayType));
  1367. }
  1368. #if NET_2_0
  1369. [Test]
  1370. public void ImportNullableInt ()
  1371. {
  1372. XmlReflectionImporter imp = new XmlReflectionImporter ();
  1373. XmlTypeMapping map = imp.ImportTypeMapping (typeof (int?));
  1374. XmlSchemas schemas = new XmlSchemas ();
  1375. XmlSchemaExporter exp = new XmlSchemaExporter (schemas);
  1376. exp.ExportTypeMapping (map);
  1377. XmlSchema schema = schemas [0];
  1378. XmlSchemaElement el = schema.Items [0] as XmlSchemaElement;
  1379. Assert.AreEqual ("int", el.Name, "#1");
  1380. Assert.AreEqual (new XmlQualifiedName ("int", XmlSchema.Namespace), el.SchemaTypeName, "#2");
  1381. Assert.AreEqual (true, el.IsNillable, "#3");
  1382. }
  1383. [Test]
  1384. public void ImportNullableContainer ()
  1385. {
  1386. new XmlSerializer (typeof (NullableContainer));
  1387. }
  1388. [Test]
  1389. public void ImportNullableContainer2 ()
  1390. {
  1391. XmlReflectionImporter imp = new XmlReflectionImporter ();
  1392. XmlTypeMapping map = imp.ImportTypeMapping (typeof (NullableContainer2));
  1393. XmlSchemas schemas = new XmlSchemas ();
  1394. XmlSchemaExporter exp = new XmlSchemaExporter (schemas);
  1395. exp.ExportTypeMapping (map);
  1396. XmlSchema schema = schemas [0];
  1397. XmlSchemaComplexType el = schema.Items [1] as XmlSchemaComplexType;
  1398. XmlSchemaSequence s = el.Particle as XmlSchemaSequence;
  1399. XmlSchemaElement el2 = s.Items [0] as XmlSchemaElement;
  1400. Assert.IsTrue (el2.IsNillable);
  1401. }
  1402. [Test]
  1403. [ExpectedException (typeof (InvalidOperationException))]
  1404. public void ImportGenericTypeDefinition ()
  1405. {
  1406. new XmlSerializer (typeof (List<int>).GetGenericTypeDefinition ());
  1407. }
  1408. [Test]
  1409. [ExpectedException (typeof (InvalidOperationException))]
  1410. public void XmlSchemaProviderMissingMethod ()
  1411. {
  1412. new XmlSerializer (typeof (XmlSchemaProviderMissingMethodType));
  1413. }
  1414. [Test]
  1415. [ExpectedException (typeof (InvalidOperationException))]
  1416. public void XmlSchemaProviderMethodNonStatic ()
  1417. {
  1418. new XmlSerializer (typeof (XmlSchemaProviderNonStaticType));
  1419. }
  1420. [Test]
  1421. [ExpectedException (typeof (InvalidOperationException))]
  1422. public void XmlSchemaProviderMethodIncorrectReturn ()
  1423. {
  1424. new XmlSerializer (typeof (XmlSchemaProviderIncorrectReturnType));
  1425. }
  1426. [Test]
  1427. public void XmlSchemaProviderAndDefaultNamespace ()
  1428. {
  1429. XmlTypeMapping tm = new XmlReflectionImporter ("urn:bar").ImportTypeMapping (typeof (XmlSchemaProviderAndDefaultNamespaceType));
  1430. Assert.AreEqual ("foo", tm.ElementName, "#1");
  1431. Assert.AreEqual ("foo", tm.XsdTypeName, "#2");
  1432. Assert.AreEqual ("urn:bar", tm.Namespace, "#3");
  1433. Assert.AreEqual ("urn:foo", tm.XsdTypeNamespace);
  1434. }
  1435. #endif
  1436. public class Employee : IXmlSerializable
  1437. {
  1438. private string _firstName;
  1439. private string _lastName;
  1440. private string _address;
  1441. public XmlSchema GetSchema ()
  1442. {
  1443. return null;
  1444. }
  1445. public void WriteXml (XmlWriter writer)
  1446. {
  1447. writer.WriteStartElement ("employee", "urn:devx-com");
  1448. writer.WriteAttributeString ("firstName", _firstName);
  1449. writer.WriteAttributeString ("lastName", _lastName);
  1450. writer.WriteAttributeString ("address", _address);
  1451. writer.WriteEndElement ();
  1452. }
  1453. public void ReadXml (XmlReader reader)
  1454. {
  1455. XmlNodeType type = reader.MoveToContent ();
  1456. if (type == XmlNodeType.Element && reader.LocalName == "employee") {
  1457. _firstName = reader["firstName"];
  1458. _lastName = reader["lastName"];
  1459. _address = reader["address"];
  1460. }
  1461. }
  1462. }
  1463. public class NestedStruct
  1464. {
  1465. public TimeSpan Period = TimeSpan.MaxValue;
  1466. }
  1467. public class ObjectEnumerable : IEnumerable
  1468. {
  1469. public void Add (int value)
  1470. {
  1471. }
  1472. public void Add (object value)
  1473. {
  1474. }
  1475. public IEnumerator GetEnumerator ()
  1476. {
  1477. return new ArrayList ().GetEnumerator ();
  1478. }
  1479. }
  1480. public class SimpleClassEnumerable : IEnumerable
  1481. {
  1482. public void Add (int value)
  1483. {
  1484. }
  1485. public void Add (object value)
  1486. {
  1487. }
  1488. IEnumerator IEnumerable.GetEnumerator ()
  1489. {
  1490. return GetEnumerator ();
  1491. }
  1492. public SimpleClassEnumerator GetEnumerator ()
  1493. {
  1494. return new SimpleClassEnumerator (new ArrayList ());
  1495. }
  1496. }
  1497. public class SimpleClassEnumerablePrivateGetEnumerator : IEnumerable
  1498. {
  1499. public void Add (object value)
  1500. {
  1501. }
  1502. IEnumerator IEnumerable.GetEnumerator ()
  1503. {
  1504. return new ArrayList ().GetEnumerator ();
  1505. }
  1506. }
  1507. public class SimpleClassEnumerablePrivateCurrent : IEnumerable
  1508. {
  1509. public void Add (object value)
  1510. {
  1511. }
  1512. IEnumerator IEnumerable.GetEnumerator ()
  1513. {
  1514. return GetEnumerator ();
  1515. }
  1516. public NoCurrentEnumerator GetEnumerator ()
  1517. {
  1518. return new NoCurrentEnumerator (new ArrayList ());
  1519. }
  1520. }
  1521. // GetEnumerator().Current returns object, but there's no corresponding
  1522. // Add (System.Object) method
  1523. public class ObjectEnumerableNoMatchingAddMethod : IEnumerable
  1524. {
  1525. public void Add (int value)
  1526. {
  1527. }
  1528. public IEnumerator GetEnumerator ()
  1529. {
  1530. return new ArrayList ().GetEnumerator ();
  1531. }
  1532. }
  1533. // GetEnumerator().Current returns SimpleClass, but there's no
  1534. // corresponding Add (SimpleClass) method
  1535. public class SimpleClassCollectionNoMatchingAddMethod : ICollection
  1536. {
  1537. public SimpleClass this[int index]
  1538. {
  1539. get
  1540. {
  1541. return (SimpleClass) _list[index];
  1542. }
  1543. }
  1544. public int Count
  1545. {
  1546. get { return _list.Count; }
  1547. }
  1548. public bool IsSynchronized
  1549. {
  1550. get { return _list.IsSynchronized; }
  1551. }
  1552. public object SyncRoot
  1553. {
  1554. get { return _list.SyncRoot; }
  1555. }
  1556. public void CopyTo (Array array, int index)
  1557. {
  1558. _list.CopyTo (array, index);
  1559. }
  1560. IEnumerator IEnumerable.GetEnumerator ()
  1561. {
  1562. return GetEnumerator ();
  1563. }
  1564. public SimpleClassEnumerator GetEnumerator ()
  1565. {
  1566. return new SimpleClassEnumerator (_list);
  1567. }
  1568. private ArrayList _list = new ArrayList ();
  1569. }
  1570. // GetEnumerator().Current returns object, but there's no corresponding
  1571. // Add (System.Object) method
  1572. public class ObjectCollectionNoMatchingAddMethod : ICollection
  1573. {
  1574. public object this[int index]
  1575. {
  1576. get
  1577. {
  1578. return _list[index];
  1579. }
  1580. }
  1581. public int Count
  1582. {
  1583. get { return _list.Count; }
  1584. }
  1585. public bool IsSynchronized
  1586. {
  1587. get { return _list.IsSynchronized; }
  1588. }
  1589. public object SyncRoot
  1590. {
  1591. get { return _list.SyncRoot; }
  1592. }
  1593. public void CopyTo (Array array, int index)
  1594. {
  1595. _list.CopyTo (array, index);
  1596. }
  1597. IEnumerator IEnumerable.GetEnumerator ()
  1598. {
  1599. return GetEnumerator ();
  1600. }
  1601. public IEnumerator GetEnumerator ()
  1602. {
  1603. return _list.GetEnumerator ();
  1604. }
  1605. private ArrayList _list = new ArrayList ();
  1606. }
  1607. // Does not have int indexer.
  1608. public class SimpleClassCollectionNoIntIndexer : ICollection
  1609. {
  1610. public SimpleClass this[string name]
  1611. {
  1612. get
  1613. {
  1614. return new SimpleClass ();
  1615. }
  1616. }
  1617. public int Count
  1618. {
  1619. get { return _list.Count; }
  1620. }
  1621. public bool IsSynchronized
  1622. {
  1623. get { return _list.IsSynchronized; }
  1624. }
  1625. public object SyncRoot
  1626. {
  1627. get { return _list.SyncRoot; }
  1628. }
  1629. public void CopyTo (Array array, int index)
  1630. {
  1631. _list.CopyTo (array, index);
  1632. }
  1633. IEnumerator IEnumerable.GetEnumerator ()
  1634. {
  1635. return GetEnumerator ();
  1636. }
  1637. public SimpleClassEnumerator GetEnumerator ()
  1638. {
  1639. return new SimpleClassEnumerator (_list);
  1640. }
  1641. public void Add (SimpleClass value)
  1642. {
  1643. _list.Add (value);
  1644. }
  1645. private ArrayList _list = new ArrayList ();
  1646. }
  1647. // Does not have int indexer.
  1648. public class ObjectCollectionNoIntIndexer : ICollection
  1649. {
  1650. public object this[string name]
  1651. {
  1652. get
  1653. {
  1654. return new SimpleClass ();
  1655. }
  1656. }
  1657. public int Count
  1658. {
  1659. get { return _list.Count; }
  1660. }
  1661. public bool IsSynchronized
  1662. {
  1663. get { return _list.IsSynchronized; }
  1664. }
  1665. public object SyncRoot
  1666. {
  1667. get { return _list.SyncRoot; }
  1668. }
  1669. public void CopyTo (Array array, int index)
  1670. {
  1671. _list.CopyTo (array, index);
  1672. }
  1673. public IEnumerator GetEnumerator ()
  1674. {
  1675. return _list.GetEnumerator ();
  1676. }
  1677. public void Add (object value)
  1678. {
  1679. _list.Add (value);
  1680. }
  1681. private ArrayList _list = new ArrayList ();
  1682. }
  1683. public class SimpleClassCollection : ICollection
  1684. {
  1685. public SimpleClass this[int index]
  1686. {
  1687. get
  1688. {
  1689. return (SimpleClass) _list[index];
  1690. }
  1691. }
  1692. public int Count
  1693. {
  1694. get { return _list.Count; }
  1695. }
  1696. public bool IsSynchronized
  1697. {
  1698. get { return _list.IsSynchronized; }
  1699. }
  1700. public object SyncRoot
  1701. {
  1702. get { return _list.SyncRoot; }
  1703. }
  1704. public void CopyTo (Array array, int index)
  1705. {
  1706. _list.CopyTo (array, index);
  1707. }
  1708. IEnumerator IEnumerable.GetEnumerator ()
  1709. {
  1710. return GetEnumerator ();
  1711. }
  1712. public SimpleClassEnumerator GetEnumerator ()
  1713. {
  1714. return new SimpleClassEnumerator (_list);
  1715. }
  1716. public void Add (SimpleClass value)
  1717. {
  1718. _list.Add (value);
  1719. }
  1720. private ArrayList _list = new ArrayList ();
  1721. }
  1722. public class ObjectCollection : ICollection
  1723. {
  1724. public object this[int name]
  1725. {
  1726. get
  1727. {
  1728. return new SimpleClass ();
  1729. }
  1730. }
  1731. public int Count
  1732. {
  1733. get { return _list.Count; }
  1734. }
  1735. public bool IsSynchronized
  1736. {
  1737. get { return _list.IsSynchronized; }
  1738. }
  1739. public object SyncRoot
  1740. {
  1741. get { return _list.SyncRoot; }
  1742. }
  1743. public void CopyTo (Array array, int index)
  1744. {
  1745. _list.CopyTo (array, index);
  1746. }
  1747. public IEnumerator GetEnumerator ()
  1748. {
  1749. return _list.GetEnumerator ();
  1750. }
  1751. public void Add (object value)
  1752. {
  1753. _list.Add (value);
  1754. }
  1755. private ArrayList _list = new ArrayList ();
  1756. }
  1757. public class SimpleClassEnumerator : IEnumerator
  1758. {
  1759. internal SimpleClassEnumerator (ArrayList arguments)
  1760. {
  1761. IEnumerable temp = (IEnumerable) (arguments);
  1762. _baseEnumerator = temp.GetEnumerator ();
  1763. }
  1764. public SimpleClass Current
  1765. {
  1766. get { return (SimpleClass) _baseEnumerator.Current; }
  1767. }
  1768. object IEnumerator.Current
  1769. {
  1770. get { return _baseEnumerator.Current; }
  1771. }
  1772. public bool MoveNext ()
  1773. {
  1774. return _baseEnumerator.MoveNext ();
  1775. }
  1776. bool IEnumerator.MoveNext ()
  1777. {
  1778. return _baseEnumerator.MoveNext ();
  1779. }
  1780. public void Reset ()
  1781. {
  1782. _baseEnumerator.Reset ();
  1783. }
  1784. void IEnumerator.Reset ()
  1785. {
  1786. _baseEnumerator.Reset ();
  1787. }
  1788. private IEnumerator _baseEnumerator;
  1789. }
  1790. public class NoCurrentEnumerator : IEnumerator
  1791. {
  1792. internal NoCurrentEnumerator (ArrayList arguments)
  1793. {
  1794. IEnumerable temp = (IEnumerable) (arguments);
  1795. _baseEnumerator = temp.GetEnumerator ();
  1796. }
  1797. object IEnumerator.Current
  1798. {
  1799. get { return _baseEnumerator.Current; }
  1800. }
  1801. public bool MoveNext ()
  1802. {
  1803. return _baseEnumerator.MoveNext ();
  1804. }
  1805. bool IEnumerator.MoveNext ()
  1806. {
  1807. return _baseEnumerator.MoveNext ();
  1808. }
  1809. public void Reset ()
  1810. {
  1811. _baseEnumerator.Reset ();
  1812. }
  1813. void IEnumerator.Reset ()
  1814. {
  1815. _baseEnumerator.Reset ();
  1816. }
  1817. private IEnumerator _baseEnumerator;
  1818. }
  1819. public class XmlArrayOnByteArrayType
  1820. {
  1821. [XmlArray]
  1822. [XmlArrayItem ("Byte", IsNullable =false)]
  1823. public byte [] Args;
  1824. }
  1825. #if NET_2_0
  1826. public class NullableContainer
  1827. {
  1828. [XmlElement (IsNullable = true)]
  1829. public int? NilInt;
  1830. }
  1831. public class NullableContainer2
  1832. {
  1833. int? value;
  1834. public int? NullableInt {
  1835. get { return value; }
  1836. set { this.value = value; }
  1837. }
  1838. }
  1839. [XmlSchemaProvider ("GetXsdType")]
  1840. public class XmlSchemaProviderMissingMethodType : IXmlSerializable
  1841. {
  1842. public void ReadXml (XmlReader reader)
  1843. {
  1844. }
  1845. public void WriteXml (XmlWriter writer)
  1846. {
  1847. }
  1848. public XmlSchema GetSchema ()
  1849. {
  1850. return null;
  1851. }
  1852. }
  1853. [XmlSchemaProvider ("GetXsdType")]
  1854. public class XmlSchemaProviderNonStaticType : IXmlSerializable
  1855. {
  1856. public void ReadXml (XmlReader reader)
  1857. {
  1858. }
  1859. public void WriteXml (XmlWriter writer)
  1860. {
  1861. }
  1862. public XmlSchema GetSchema ()
  1863. {
  1864. return null;
  1865. }
  1866. public object GetXsdType ()
  1867. {
  1868. return null;
  1869. }
  1870. }
  1871. [XmlSchemaProvider ("GetXsdType")]
  1872. public class XmlSchemaProviderIncorrectReturnType : IXmlSerializable
  1873. {
  1874. public void ReadXml (XmlReader reader)
  1875. {
  1876. }
  1877. public void WriteXml (XmlWriter writer)
  1878. {
  1879. }
  1880. public XmlSchema GetSchema ()
  1881. {
  1882. return null;
  1883. }
  1884. public static object GetXsdType ()
  1885. {
  1886. return null;
  1887. }
  1888. }
  1889. [XmlSchemaProvider ("GetXsd")]
  1890. public class XmlSchemaProviderAndDefaultNamespaceType : IXmlSerializable
  1891. {
  1892. public static XmlQualifiedName GetXsd (XmlSchemaSet xss)
  1893. {
  1894. XmlSchema xs = new XmlSchema ();
  1895. xs.TargetNamespace = "urn:foo";
  1896. XmlSchemaComplexType ct = new XmlSchemaComplexType ();
  1897. ct.Name = "foo";
  1898. xs.Items.Add (ct);
  1899. xss.Add (xs);
  1900. return new XmlQualifiedName ("foo", "urn:foo");
  1901. }
  1902. public void WriteXml (XmlWriter write)
  1903. {
  1904. }
  1905. public void ReadXml (XmlReader reader)
  1906. {
  1907. }
  1908. public XmlSchema GetSchema ()
  1909. {
  1910. return null;
  1911. }
  1912. }
  1913. #endif
  1914. }
  1915. }