XmlReflectionImporterTests.cs 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074
  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. #if NET_2_0
  1364. [Test]
  1365. public void ImportNullableInt ()
  1366. {
  1367. XmlReflectionImporter imp = new XmlReflectionImporter ();
  1368. XmlTypeMapping map = imp.ImportTypeMapping (typeof (int?));
  1369. XmlSchemas schemas = new XmlSchemas ();
  1370. XmlSchemaExporter exp = new XmlSchemaExporter (schemas);
  1371. exp.ExportTypeMapping (map);
  1372. XmlSchema schema = schemas [0];
  1373. XmlSchemaElement el = schema.Items [0] as XmlSchemaElement;
  1374. Assert.AreEqual ("int", el.Name, "#1");
  1375. Assert.AreEqual (new XmlQualifiedName ("int", XmlSchema.Namespace), el.SchemaTypeName, "#2");
  1376. Assert.AreEqual (true, el.IsNillable, "#3");
  1377. }
  1378. [Test]
  1379. public void ImportNullableContainer ()
  1380. {
  1381. new XmlSerializer (typeof (NullableContainer));
  1382. }
  1383. [Test]
  1384. public void ImportNullableContainer2 ()
  1385. {
  1386. XmlReflectionImporter imp = new XmlReflectionImporter ();
  1387. XmlTypeMapping map = imp.ImportTypeMapping (typeof (NullableContainer2));
  1388. XmlSchemas schemas = new XmlSchemas ();
  1389. XmlSchemaExporter exp = new XmlSchemaExporter (schemas);
  1390. exp.ExportTypeMapping (map);
  1391. XmlSchema schema = schemas [0];
  1392. XmlSchemaComplexType el = schema.Items [1] as XmlSchemaComplexType;
  1393. XmlSchemaSequence s = el.Particle as XmlSchemaSequence;
  1394. XmlSchemaElement el2 = s.Items [0] as XmlSchemaElement;
  1395. Assert.IsTrue (el2.IsNillable);
  1396. }
  1397. [Test]
  1398. [ExpectedException (typeof (InvalidOperationException))]
  1399. public void ImportGenericTypeDefinition ()
  1400. {
  1401. new XmlSerializer (typeof (List<int>).GetGenericTypeDefinition ());
  1402. }
  1403. #endif
  1404. public class Employee : IXmlSerializable
  1405. {
  1406. private string _firstName;
  1407. private string _lastName;
  1408. private string _address;
  1409. public XmlSchema GetSchema ()
  1410. {
  1411. return null;
  1412. }
  1413. public void WriteXml (XmlWriter writer)
  1414. {
  1415. writer.WriteStartElement ("employee", "urn:devx-com");
  1416. writer.WriteAttributeString ("firstName", _firstName);
  1417. writer.WriteAttributeString ("lastName", _lastName);
  1418. writer.WriteAttributeString ("address", _address);
  1419. writer.WriteEndElement ();
  1420. }
  1421. public void ReadXml (XmlReader reader)
  1422. {
  1423. XmlNodeType type = reader.MoveToContent ();
  1424. if (type == XmlNodeType.Element && reader.LocalName == "employee") {
  1425. _firstName = reader["firstName"];
  1426. _lastName = reader["lastName"];
  1427. _address = reader["address"];
  1428. }
  1429. }
  1430. }
  1431. public class NestedStruct
  1432. {
  1433. public TimeSpan Period = TimeSpan.MaxValue;
  1434. }
  1435. public class ObjectEnumerable : IEnumerable
  1436. {
  1437. public void Add (int value)
  1438. {
  1439. }
  1440. public void Add (object value)
  1441. {
  1442. }
  1443. public IEnumerator GetEnumerator ()
  1444. {
  1445. return new ArrayList ().GetEnumerator ();
  1446. }
  1447. }
  1448. public class SimpleClassEnumerable : IEnumerable
  1449. {
  1450. public void Add (int value)
  1451. {
  1452. }
  1453. public void Add (object value)
  1454. {
  1455. }
  1456. IEnumerator IEnumerable.GetEnumerator ()
  1457. {
  1458. return GetEnumerator ();
  1459. }
  1460. public SimpleClassEnumerator GetEnumerator ()
  1461. {
  1462. return new SimpleClassEnumerator (new ArrayList ());
  1463. }
  1464. }
  1465. public class SimpleClassEnumerablePrivateGetEnumerator : IEnumerable
  1466. {
  1467. public void Add (object value)
  1468. {
  1469. }
  1470. IEnumerator IEnumerable.GetEnumerator ()
  1471. {
  1472. return new ArrayList ().GetEnumerator ();
  1473. }
  1474. }
  1475. public class SimpleClassEnumerablePrivateCurrent : IEnumerable
  1476. {
  1477. public void Add (object value)
  1478. {
  1479. }
  1480. IEnumerator IEnumerable.GetEnumerator ()
  1481. {
  1482. return GetEnumerator ();
  1483. }
  1484. public NoCurrentEnumerator GetEnumerator ()
  1485. {
  1486. return new NoCurrentEnumerator (new ArrayList ());
  1487. }
  1488. }
  1489. // GetEnumerator().Current returns object, but there's no corresponding
  1490. // Add (System.Object) method
  1491. public class ObjectEnumerableNoMatchingAddMethod : IEnumerable
  1492. {
  1493. public void Add (int value)
  1494. {
  1495. }
  1496. public IEnumerator GetEnumerator ()
  1497. {
  1498. return new ArrayList ().GetEnumerator ();
  1499. }
  1500. }
  1501. // GetEnumerator().Current returns SimpleClass, but there's no
  1502. // corresponding Add (SimpleClass) method
  1503. public class SimpleClassCollectionNoMatchingAddMethod : ICollection
  1504. {
  1505. public SimpleClass this[int index]
  1506. {
  1507. get
  1508. {
  1509. return (SimpleClass) _list[index];
  1510. }
  1511. }
  1512. public int Count
  1513. {
  1514. get { return _list.Count; }
  1515. }
  1516. public bool IsSynchronized
  1517. {
  1518. get { return _list.IsSynchronized; }
  1519. }
  1520. public object SyncRoot
  1521. {
  1522. get { return _list.SyncRoot; }
  1523. }
  1524. public void CopyTo (Array array, int index)
  1525. {
  1526. _list.CopyTo (array, index);
  1527. }
  1528. IEnumerator IEnumerable.GetEnumerator ()
  1529. {
  1530. return GetEnumerator ();
  1531. }
  1532. public SimpleClassEnumerator GetEnumerator ()
  1533. {
  1534. return new SimpleClassEnumerator (_list);
  1535. }
  1536. private ArrayList _list = new ArrayList ();
  1537. }
  1538. // GetEnumerator().Current returns object, but there's no corresponding
  1539. // Add (System.Object) method
  1540. public class ObjectCollectionNoMatchingAddMethod : ICollection
  1541. {
  1542. public object this[int index]
  1543. {
  1544. get
  1545. {
  1546. return _list[index];
  1547. }
  1548. }
  1549. public int Count
  1550. {
  1551. get { return _list.Count; }
  1552. }
  1553. public bool IsSynchronized
  1554. {
  1555. get { return _list.IsSynchronized; }
  1556. }
  1557. public object SyncRoot
  1558. {
  1559. get { return _list.SyncRoot; }
  1560. }
  1561. public void CopyTo (Array array, int index)
  1562. {
  1563. _list.CopyTo (array, index);
  1564. }
  1565. IEnumerator IEnumerable.GetEnumerator ()
  1566. {
  1567. return GetEnumerator ();
  1568. }
  1569. public IEnumerator GetEnumerator ()
  1570. {
  1571. return _list.GetEnumerator ();
  1572. }
  1573. private ArrayList _list = new ArrayList ();
  1574. }
  1575. // Does not have int indexer.
  1576. public class SimpleClassCollectionNoIntIndexer : ICollection
  1577. {
  1578. public SimpleClass this[string name]
  1579. {
  1580. get
  1581. {
  1582. return new SimpleClass ();
  1583. }
  1584. }
  1585. public int Count
  1586. {
  1587. get { return _list.Count; }
  1588. }
  1589. public bool IsSynchronized
  1590. {
  1591. get { return _list.IsSynchronized; }
  1592. }
  1593. public object SyncRoot
  1594. {
  1595. get { return _list.SyncRoot; }
  1596. }
  1597. public void CopyTo (Array array, int index)
  1598. {
  1599. _list.CopyTo (array, index);
  1600. }
  1601. IEnumerator IEnumerable.GetEnumerator ()
  1602. {
  1603. return GetEnumerator ();
  1604. }
  1605. public SimpleClassEnumerator GetEnumerator ()
  1606. {
  1607. return new SimpleClassEnumerator (_list);
  1608. }
  1609. public void Add (SimpleClass value)
  1610. {
  1611. _list.Add (value);
  1612. }
  1613. private ArrayList _list = new ArrayList ();
  1614. }
  1615. // Does not have int indexer.
  1616. public class ObjectCollectionNoIntIndexer : ICollection
  1617. {
  1618. public object this[string name]
  1619. {
  1620. get
  1621. {
  1622. return new SimpleClass ();
  1623. }
  1624. }
  1625. public int Count
  1626. {
  1627. get { return _list.Count; }
  1628. }
  1629. public bool IsSynchronized
  1630. {
  1631. get { return _list.IsSynchronized; }
  1632. }
  1633. public object SyncRoot
  1634. {
  1635. get { return _list.SyncRoot; }
  1636. }
  1637. public void CopyTo (Array array, int index)
  1638. {
  1639. _list.CopyTo (array, index);
  1640. }
  1641. public IEnumerator GetEnumerator ()
  1642. {
  1643. return _list.GetEnumerator ();
  1644. }
  1645. public void Add (object value)
  1646. {
  1647. _list.Add (value);
  1648. }
  1649. private ArrayList _list = new ArrayList ();
  1650. }
  1651. public class SimpleClassCollection : ICollection
  1652. {
  1653. public SimpleClass this[int index]
  1654. {
  1655. get
  1656. {
  1657. return (SimpleClass) _list[index];
  1658. }
  1659. }
  1660. public int Count
  1661. {
  1662. get { return _list.Count; }
  1663. }
  1664. public bool IsSynchronized
  1665. {
  1666. get { return _list.IsSynchronized; }
  1667. }
  1668. public object SyncRoot
  1669. {
  1670. get { return _list.SyncRoot; }
  1671. }
  1672. public void CopyTo (Array array, int index)
  1673. {
  1674. _list.CopyTo (array, index);
  1675. }
  1676. IEnumerator IEnumerable.GetEnumerator ()
  1677. {
  1678. return GetEnumerator ();
  1679. }
  1680. public SimpleClassEnumerator GetEnumerator ()
  1681. {
  1682. return new SimpleClassEnumerator (_list);
  1683. }
  1684. public void Add (SimpleClass value)
  1685. {
  1686. _list.Add (value);
  1687. }
  1688. private ArrayList _list = new ArrayList ();
  1689. }
  1690. public class ObjectCollection : ICollection
  1691. {
  1692. public object this[int name]
  1693. {
  1694. get
  1695. {
  1696. return new SimpleClass ();
  1697. }
  1698. }
  1699. public int Count
  1700. {
  1701. get { return _list.Count; }
  1702. }
  1703. public bool IsSynchronized
  1704. {
  1705. get { return _list.IsSynchronized; }
  1706. }
  1707. public object SyncRoot
  1708. {
  1709. get { return _list.SyncRoot; }
  1710. }
  1711. public void CopyTo (Array array, int index)
  1712. {
  1713. _list.CopyTo (array, index);
  1714. }
  1715. public IEnumerator GetEnumerator ()
  1716. {
  1717. return _list.GetEnumerator ();
  1718. }
  1719. public void Add (object value)
  1720. {
  1721. _list.Add (value);
  1722. }
  1723. private ArrayList _list = new ArrayList ();
  1724. }
  1725. public class SimpleClassEnumerator : IEnumerator
  1726. {
  1727. internal SimpleClassEnumerator (ArrayList arguments)
  1728. {
  1729. IEnumerable temp = (IEnumerable) (arguments);
  1730. _baseEnumerator = temp.GetEnumerator ();
  1731. }
  1732. public SimpleClass Current
  1733. {
  1734. get { return (SimpleClass) _baseEnumerator.Current; }
  1735. }
  1736. object IEnumerator.Current
  1737. {
  1738. get { return _baseEnumerator.Current; }
  1739. }
  1740. public bool MoveNext ()
  1741. {
  1742. return _baseEnumerator.MoveNext ();
  1743. }
  1744. bool IEnumerator.MoveNext ()
  1745. {
  1746. return _baseEnumerator.MoveNext ();
  1747. }
  1748. public void Reset ()
  1749. {
  1750. _baseEnumerator.Reset ();
  1751. }
  1752. void IEnumerator.Reset ()
  1753. {
  1754. _baseEnumerator.Reset ();
  1755. }
  1756. private IEnumerator _baseEnumerator;
  1757. }
  1758. public class NoCurrentEnumerator : IEnumerator
  1759. {
  1760. internal NoCurrentEnumerator (ArrayList arguments)
  1761. {
  1762. IEnumerable temp = (IEnumerable) (arguments);
  1763. _baseEnumerator = temp.GetEnumerator ();
  1764. }
  1765. object IEnumerator.Current
  1766. {
  1767. get { return _baseEnumerator.Current; }
  1768. }
  1769. public bool MoveNext ()
  1770. {
  1771. return _baseEnumerator.MoveNext ();
  1772. }
  1773. bool IEnumerator.MoveNext ()
  1774. {
  1775. return _baseEnumerator.MoveNext ();
  1776. }
  1777. public void Reset ()
  1778. {
  1779. _baseEnumerator.Reset ();
  1780. }
  1781. void IEnumerator.Reset ()
  1782. {
  1783. _baseEnumerator.Reset ();
  1784. }
  1785. private IEnumerator _baseEnumerator;
  1786. }
  1787. #if NET_2_0
  1788. public class NullableContainer
  1789. {
  1790. [XmlElement (IsNullable = true)]
  1791. public int? NilInt;
  1792. }
  1793. public class NullableContainer2
  1794. {
  1795. int? value;
  1796. public int? NullableInt {
  1797. get { return value; }
  1798. set { this.value = value; }
  1799. }
  1800. }
  1801. #endif
  1802. }
  1803. }