XmlReflectionImporterTests.cs 71 KB

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