XmlReflectionImporterTests.cs 58 KB

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