XmlReflectionImporterTests.cs 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281
  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. [Test]
  1448. public void Bug708178Type()
  1449. {
  1450. XmlSerializer xmlSerializer = new XmlSerializer (typeof(Bug708178Type));
  1451. Bug708178Type bugType = new Bug708178Type ();
  1452. bugType.Foo.Add ("test");
  1453. Assert.AreEqual (1, bugType.Foo.Count);
  1454. //xml Serialize
  1455. TextWriter WriteFileStream = new StreamWriter (@"Bug708178Type.xml", false);
  1456. xmlSerializer.Serialize (WriteFileStream, bugType);
  1457. WriteFileStream.Close ();
  1458. //xml Deserialize
  1459. FileStream ReadFileStream = new FileStream (@"Bug708178Type.xml", FileMode.Open, FileAccess.Read, FileShare.Read);
  1460. Bug708178Type bugTypeReload = (Bug708178Type)xmlSerializer.Deserialize (ReadFileStream);
  1461. //should have deserialized the relationship
  1462. Assert.AreEqual(1, bugTypeReload.Foo.Count);
  1463. }
  1464. #endif
  1465. public class Employee : IXmlSerializable
  1466. {
  1467. private string _firstName;
  1468. private string _lastName;
  1469. private string _address;
  1470. public XmlSchema GetSchema ()
  1471. {
  1472. return null;
  1473. }
  1474. public void WriteXml (XmlWriter writer)
  1475. {
  1476. writer.WriteStartElement ("employee", "urn:devx-com");
  1477. writer.WriteAttributeString ("firstName", _firstName);
  1478. writer.WriteAttributeString ("lastName", _lastName);
  1479. writer.WriteAttributeString ("address", _address);
  1480. writer.WriteEndElement ();
  1481. }
  1482. public void ReadXml (XmlReader reader)
  1483. {
  1484. XmlNodeType type = reader.MoveToContent ();
  1485. if (type == XmlNodeType.Element && reader.LocalName == "employee") {
  1486. _firstName = reader["firstName"];
  1487. _lastName = reader["lastName"];
  1488. _address = reader["address"];
  1489. }
  1490. }
  1491. }
  1492. public class NestedStruct
  1493. {
  1494. public TimeSpan Period = TimeSpan.MaxValue;
  1495. }
  1496. public class ObjectEnumerable : IEnumerable
  1497. {
  1498. public void Add (int value)
  1499. {
  1500. }
  1501. public void Add (object value)
  1502. {
  1503. }
  1504. public IEnumerator GetEnumerator ()
  1505. {
  1506. return new ArrayList ().GetEnumerator ();
  1507. }
  1508. }
  1509. public class SimpleClassEnumerable : IEnumerable
  1510. {
  1511. public void Add (int value)
  1512. {
  1513. }
  1514. public void Add (object value)
  1515. {
  1516. }
  1517. IEnumerator IEnumerable.GetEnumerator ()
  1518. {
  1519. return GetEnumerator ();
  1520. }
  1521. public SimpleClassEnumerator GetEnumerator ()
  1522. {
  1523. return new SimpleClassEnumerator (new ArrayList ());
  1524. }
  1525. }
  1526. public class SimpleClassEnumerablePrivateGetEnumerator : IEnumerable
  1527. {
  1528. public void Add (object value)
  1529. {
  1530. }
  1531. IEnumerator IEnumerable.GetEnumerator ()
  1532. {
  1533. return new ArrayList ().GetEnumerator ();
  1534. }
  1535. }
  1536. public class SimpleClassEnumerablePrivateCurrent : IEnumerable
  1537. {
  1538. public void Add (object value)
  1539. {
  1540. }
  1541. IEnumerator IEnumerable.GetEnumerator ()
  1542. {
  1543. return GetEnumerator ();
  1544. }
  1545. public NoCurrentEnumerator GetEnumerator ()
  1546. {
  1547. return new NoCurrentEnumerator (new ArrayList ());
  1548. }
  1549. }
  1550. // GetEnumerator().Current returns object, but there's no corresponding
  1551. // Add (System.Object) method
  1552. public class ObjectEnumerableNoMatchingAddMethod : IEnumerable
  1553. {
  1554. public void Add (int value)
  1555. {
  1556. }
  1557. public IEnumerator GetEnumerator ()
  1558. {
  1559. return new ArrayList ().GetEnumerator ();
  1560. }
  1561. }
  1562. // GetEnumerator().Current returns SimpleClass, but there's no
  1563. // corresponding Add (SimpleClass) method
  1564. public class SimpleClassCollectionNoMatchingAddMethod : ICollection
  1565. {
  1566. public SimpleClass this[int index]
  1567. {
  1568. get
  1569. {
  1570. return (SimpleClass) _list[index];
  1571. }
  1572. }
  1573. public int Count
  1574. {
  1575. get { return _list.Count; }
  1576. }
  1577. public bool IsSynchronized
  1578. {
  1579. get { return _list.IsSynchronized; }
  1580. }
  1581. public object SyncRoot
  1582. {
  1583. get { return _list.SyncRoot; }
  1584. }
  1585. public void CopyTo (Array array, int index)
  1586. {
  1587. _list.CopyTo (array, index);
  1588. }
  1589. IEnumerator IEnumerable.GetEnumerator ()
  1590. {
  1591. return GetEnumerator ();
  1592. }
  1593. public SimpleClassEnumerator GetEnumerator ()
  1594. {
  1595. return new SimpleClassEnumerator (_list);
  1596. }
  1597. private ArrayList _list = new ArrayList ();
  1598. }
  1599. // GetEnumerator().Current returns object, but there's no corresponding
  1600. // Add (System.Object) method
  1601. public class ObjectCollectionNoMatchingAddMethod : ICollection
  1602. {
  1603. public object this[int index]
  1604. {
  1605. get
  1606. {
  1607. return _list[index];
  1608. }
  1609. }
  1610. public int Count
  1611. {
  1612. get { return _list.Count; }
  1613. }
  1614. public bool IsSynchronized
  1615. {
  1616. get { return _list.IsSynchronized; }
  1617. }
  1618. public object SyncRoot
  1619. {
  1620. get { return _list.SyncRoot; }
  1621. }
  1622. public void CopyTo (Array array, int index)
  1623. {
  1624. _list.CopyTo (array, index);
  1625. }
  1626. IEnumerator IEnumerable.GetEnumerator ()
  1627. {
  1628. return GetEnumerator ();
  1629. }
  1630. public IEnumerator GetEnumerator ()
  1631. {
  1632. return _list.GetEnumerator ();
  1633. }
  1634. private ArrayList _list = new ArrayList ();
  1635. }
  1636. // Does not have int indexer.
  1637. public class SimpleClassCollectionNoIntIndexer : ICollection
  1638. {
  1639. public SimpleClass this[string name]
  1640. {
  1641. get
  1642. {
  1643. return new SimpleClass ();
  1644. }
  1645. }
  1646. public int Count
  1647. {
  1648. get { return _list.Count; }
  1649. }
  1650. public bool IsSynchronized
  1651. {
  1652. get { return _list.IsSynchronized; }
  1653. }
  1654. public object SyncRoot
  1655. {
  1656. get { return _list.SyncRoot; }
  1657. }
  1658. public void CopyTo (Array array, int index)
  1659. {
  1660. _list.CopyTo (array, index);
  1661. }
  1662. IEnumerator IEnumerable.GetEnumerator ()
  1663. {
  1664. return GetEnumerator ();
  1665. }
  1666. public SimpleClassEnumerator GetEnumerator ()
  1667. {
  1668. return new SimpleClassEnumerator (_list);
  1669. }
  1670. public void Add (SimpleClass value)
  1671. {
  1672. _list.Add (value);
  1673. }
  1674. private ArrayList _list = new ArrayList ();
  1675. }
  1676. // Does not have int indexer.
  1677. public class ObjectCollectionNoIntIndexer : ICollection
  1678. {
  1679. public object this[string name]
  1680. {
  1681. get
  1682. {
  1683. return new SimpleClass ();
  1684. }
  1685. }
  1686. public int Count
  1687. {
  1688. get { return _list.Count; }
  1689. }
  1690. public bool IsSynchronized
  1691. {
  1692. get { return _list.IsSynchronized; }
  1693. }
  1694. public object SyncRoot
  1695. {
  1696. get { return _list.SyncRoot; }
  1697. }
  1698. public void CopyTo (Array array, int index)
  1699. {
  1700. _list.CopyTo (array, index);
  1701. }
  1702. public IEnumerator GetEnumerator ()
  1703. {
  1704. return _list.GetEnumerator ();
  1705. }
  1706. public void Add (object value)
  1707. {
  1708. _list.Add (value);
  1709. }
  1710. private ArrayList _list = new ArrayList ();
  1711. }
  1712. public class SimpleClassCollection : ICollection
  1713. {
  1714. public SimpleClass this[int index]
  1715. {
  1716. get
  1717. {
  1718. return (SimpleClass) _list[index];
  1719. }
  1720. }
  1721. public int Count
  1722. {
  1723. get { return _list.Count; }
  1724. }
  1725. public bool IsSynchronized
  1726. {
  1727. get { return _list.IsSynchronized; }
  1728. }
  1729. public object SyncRoot
  1730. {
  1731. get { return _list.SyncRoot; }
  1732. }
  1733. public void CopyTo (Array array, int index)
  1734. {
  1735. _list.CopyTo (array, index);
  1736. }
  1737. IEnumerator IEnumerable.GetEnumerator ()
  1738. {
  1739. return GetEnumerator ();
  1740. }
  1741. public SimpleClassEnumerator GetEnumerator ()
  1742. {
  1743. return new SimpleClassEnumerator (_list);
  1744. }
  1745. public void Add (SimpleClass value)
  1746. {
  1747. _list.Add (value);
  1748. }
  1749. private ArrayList _list = new ArrayList ();
  1750. }
  1751. public class ObjectCollection : ICollection
  1752. {
  1753. public object this[int name]
  1754. {
  1755. get
  1756. {
  1757. return new SimpleClass ();
  1758. }
  1759. }
  1760. public int Count
  1761. {
  1762. get { return _list.Count; }
  1763. }
  1764. public bool IsSynchronized
  1765. {
  1766. get { return _list.IsSynchronized; }
  1767. }
  1768. public object SyncRoot
  1769. {
  1770. get { return _list.SyncRoot; }
  1771. }
  1772. public void CopyTo (Array array, int index)
  1773. {
  1774. _list.CopyTo (array, index);
  1775. }
  1776. public IEnumerator GetEnumerator ()
  1777. {
  1778. return _list.GetEnumerator ();
  1779. }
  1780. public void Add (object value)
  1781. {
  1782. _list.Add (value);
  1783. }
  1784. private ArrayList _list = new ArrayList ();
  1785. }
  1786. public class SimpleClassEnumerator : IEnumerator
  1787. {
  1788. internal SimpleClassEnumerator (ArrayList arguments)
  1789. {
  1790. IEnumerable temp = (IEnumerable) (arguments);
  1791. _baseEnumerator = temp.GetEnumerator ();
  1792. }
  1793. public SimpleClass Current
  1794. {
  1795. get { return (SimpleClass) _baseEnumerator.Current; }
  1796. }
  1797. object IEnumerator.Current
  1798. {
  1799. get { return _baseEnumerator.Current; }
  1800. }
  1801. public bool MoveNext ()
  1802. {
  1803. return _baseEnumerator.MoveNext ();
  1804. }
  1805. bool IEnumerator.MoveNext ()
  1806. {
  1807. return _baseEnumerator.MoveNext ();
  1808. }
  1809. public void Reset ()
  1810. {
  1811. _baseEnumerator.Reset ();
  1812. }
  1813. void IEnumerator.Reset ()
  1814. {
  1815. _baseEnumerator.Reset ();
  1816. }
  1817. private IEnumerator _baseEnumerator;
  1818. }
  1819. public class NoCurrentEnumerator : IEnumerator
  1820. {
  1821. internal NoCurrentEnumerator (ArrayList arguments)
  1822. {
  1823. IEnumerable temp = (IEnumerable) (arguments);
  1824. _baseEnumerator = temp.GetEnumerator ();
  1825. }
  1826. object IEnumerator.Current
  1827. {
  1828. get { return _baseEnumerator.Current; }
  1829. }
  1830. public bool MoveNext ()
  1831. {
  1832. return _baseEnumerator.MoveNext ();
  1833. }
  1834. bool IEnumerator.MoveNext ()
  1835. {
  1836. return _baseEnumerator.MoveNext ();
  1837. }
  1838. public void Reset ()
  1839. {
  1840. _baseEnumerator.Reset ();
  1841. }
  1842. void IEnumerator.Reset ()
  1843. {
  1844. _baseEnumerator.Reset ();
  1845. }
  1846. private IEnumerator _baseEnumerator;
  1847. }
  1848. public class XmlArrayOnByteArrayType
  1849. {
  1850. [XmlArray]
  1851. [XmlArrayItem ("Byte", IsNullable =false)]
  1852. public byte [] Args;
  1853. }
  1854. #if NET_2_0
  1855. public class NullableContainer
  1856. {
  1857. [XmlElement (IsNullable = true)]
  1858. public int? NilInt;
  1859. }
  1860. public class NullableContainer2
  1861. {
  1862. int? value;
  1863. public int? NullableInt {
  1864. get { return value; }
  1865. set { this.value = value; }
  1866. }
  1867. }
  1868. [XmlSchemaProvider ("GetXsdType")]
  1869. public class XmlSchemaProviderMissingMethodType : IXmlSerializable
  1870. {
  1871. public void ReadXml (XmlReader reader)
  1872. {
  1873. }
  1874. public void WriteXml (XmlWriter writer)
  1875. {
  1876. }
  1877. public XmlSchema GetSchema ()
  1878. {
  1879. return null;
  1880. }
  1881. }
  1882. [XmlSchemaProvider ("GetXsdType")]
  1883. public class XmlSchemaProviderNonStaticType : IXmlSerializable
  1884. {
  1885. public void ReadXml (XmlReader reader)
  1886. {
  1887. }
  1888. public void WriteXml (XmlWriter writer)
  1889. {
  1890. }
  1891. public XmlSchema GetSchema ()
  1892. {
  1893. return null;
  1894. }
  1895. public object GetXsdType ()
  1896. {
  1897. return null;
  1898. }
  1899. }
  1900. [XmlSchemaProvider ("GetXsdType")]
  1901. public class XmlSchemaProviderIncorrectReturnType : IXmlSerializable
  1902. {
  1903. public void ReadXml (XmlReader reader)
  1904. {
  1905. }
  1906. public void WriteXml (XmlWriter writer)
  1907. {
  1908. }
  1909. public XmlSchema GetSchema ()
  1910. {
  1911. return null;
  1912. }
  1913. public static object GetXsdType ()
  1914. {
  1915. return null;
  1916. }
  1917. }
  1918. [XmlSchemaProvider ("GetXsd")]
  1919. public class XmlSchemaProviderAndDefaultNamespaceType : IXmlSerializable
  1920. {
  1921. public static XmlQualifiedName GetXsd (XmlSchemaSet xss)
  1922. {
  1923. XmlSchema xs = new XmlSchema ();
  1924. xs.TargetNamespace = "urn:foo";
  1925. XmlSchemaComplexType ct = new XmlSchemaComplexType ();
  1926. ct.Name = "foo";
  1927. xs.Items.Add (ct);
  1928. xss.Add (xs);
  1929. return new XmlQualifiedName ("foo", "urn:foo");
  1930. }
  1931. public void WriteXml (XmlWriter write)
  1932. {
  1933. }
  1934. public void ReadXml (XmlReader reader)
  1935. {
  1936. }
  1937. public XmlSchema GetSchema ()
  1938. {
  1939. return null;
  1940. }
  1941. }
  1942. public class MyCollection : ICollection<string>
  1943. {
  1944. public int Count { get { return 0; } }
  1945. public bool IsReadOnly { get { return false; } }
  1946. public void Add (string s)
  1947. {
  1948. }
  1949. public void Clear ()
  1950. {
  1951. }
  1952. public bool Contains (string item)
  1953. {
  1954. return false;
  1955. }
  1956. public void CopyTo (string [] array, int arrayIndex)
  1957. {
  1958. }
  1959. public IEnumerator<string> GetEnumerator ()
  1960. {
  1961. throw new Exception ();
  1962. }
  1963. IEnumerator IEnumerable.GetEnumerator ()
  1964. {
  1965. return GetEnumerator ();
  1966. }
  1967. public bool Remove (string item)
  1968. {
  1969. return false;
  1970. }
  1971. }
  1972. #endif
  1973. }
  1974. }