XmlReflectionImporterTests.cs 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890
  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 (ArgumentNullException))]
  1106. public void TypeMapping_Null ()
  1107. {
  1108. Map ((Type) null);
  1109. }
  1110. [Test]
  1111. [ExpectedException (typeof (NotSupportedException))]
  1112. public void TypeMapping_Void ()
  1113. {
  1114. Map (typeof (void));
  1115. }
  1116. [Test]
  1117. public void TypeMapping_WrongChoices ()
  1118. {
  1119. try {
  1120. Map (typeof (WrongChoices));
  1121. Assert.Fail ("#1");
  1122. } catch (InvalidOperationException ex) {
  1123. // There was an error reflecting type 'MonoTests.System.Xml.TestClasses.WrongChoices'
  1124. Assert.IsNotNull (ex.Message, "#2");
  1125. Assert.IsTrue (ex.Message.IndexOf ("'" + typeof (WrongChoices).FullName + "'") != -1, "#3");
  1126. Assert.IsNotNull (ex.InnerException, "#4");
  1127. // There was an error reflecting field 'MyChoice'
  1128. Assert.IsNotNull (ex.InnerException.Message, "#5");
  1129. Assert.IsTrue (ex.InnerException.Message.IndexOf ("'MyChoice'") != -1, "#6");
  1130. Assert.IsNotNull (ex.InnerException.InnerException, "#7");
  1131. // Type MonoTests.System.Xml.TestClasses.ItemChoiceType is missing
  1132. // enumeration value 'StrangeOne' for element 'StrangeOne' from
  1133. // namespace ''.
  1134. Assert.IsNotNull (ex.InnerException.InnerException.Message, "#8");
  1135. Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf (typeof (ItemChoiceType).FullName) != -1, "#9");
  1136. Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("'StrangeOne'") != -1, "#10");
  1137. Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("''") != -1, "#11");
  1138. }
  1139. }
  1140. [Test] // bug #77591
  1141. public void TypeMapping_XmlText_PrimitiveTypes ()
  1142. {
  1143. XmlAttributeOverrides overrides = null;
  1144. XmlAttributes attrs = null;
  1145. overrides = new XmlAttributeOverrides ();
  1146. attrs = new XmlAttributes ();
  1147. attrs.XmlText = new XmlTextAttribute (typeof (int));
  1148. overrides.Add (typeof (Field), "Modifiers", attrs);
  1149. try {
  1150. Map (typeof (Field), overrides);
  1151. Assert.Fail ("#A1");
  1152. } catch (InvalidOperationException ex) {
  1153. // There was an error reflecting type 'MonoTests.System.Xml.TestClasses.Field'
  1154. Assert.IsNotNull (ex.Message, "#A2");
  1155. Assert.IsTrue (ex.Message.IndexOf ("'" + typeof (Field).FullName + "'") != -1, "#A3");
  1156. Assert.IsNotNull (ex.InnerException, "#A4");
  1157. // There was an error reflecting field 'Modifiers'
  1158. Assert.IsNotNull (ex.InnerException.Message, "#A5");
  1159. Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Modifiers'") != -1, "#A6");
  1160. Assert.IsNotNull (ex.InnerException.InnerException, "#A7");
  1161. // The type for XmlText may not be specified for primitive types
  1162. Assert.IsNotNull (ex.InnerException.InnerException.Message, "#A8");
  1163. Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("XmlText") != -1, "#A9");
  1164. }
  1165. overrides = new XmlAttributeOverrides ();
  1166. attrs = new XmlAttributes ();
  1167. attrs.XmlText = new XmlTextAttribute (typeof (int));
  1168. overrides.Add (typeof (Field), "Street", attrs);
  1169. try {
  1170. Map (typeof (Field), overrides);
  1171. Assert.Fail ("#B1");
  1172. } catch (InvalidOperationException ex) {
  1173. // There was an error reflecting type 'MonoTests.System.Xml.TestClasses.Field'
  1174. Assert.IsNotNull (ex.Message, "#B2");
  1175. Assert.IsTrue (ex.Message.IndexOf ("'" + typeof (Field).FullName + "'") != -1, "#B3");
  1176. Assert.IsNotNull (ex.InnerException, "#B4");
  1177. // There was an error reflecting field 'Street'
  1178. Assert.IsNotNull (ex.InnerException.Message, "#B5");
  1179. Assert.IsTrue (ex.InnerException.Message.IndexOf ("'Street'") != -1, "#B6");
  1180. Assert.IsNotNull (ex.InnerException.InnerException, "#B7");
  1181. // The type for XmlText may not be specified for primitive types
  1182. Assert.IsNotNull (ex.InnerException.InnerException.Message, "#B8");
  1183. Assert.IsTrue (ex.InnerException.InnerException.Message.IndexOf ("XmlText") != -1, "#B9");
  1184. }
  1185. overrides = new XmlAttributeOverrides ();
  1186. attrs = new XmlAttributes ();
  1187. attrs.XmlText = new XmlTextAttribute (typeof (MapModifiers));
  1188. overrides.Add (typeof (Field), "Modifiers", attrs);
  1189. Map (typeof (Field), overrides);
  1190. overrides = new XmlAttributeOverrides ();
  1191. attrs = new XmlAttributes ();
  1192. attrs.XmlText = new XmlTextAttribute (typeof (string));
  1193. overrides.Add (typeof (Field), "Street", attrs);
  1194. Map (typeof (Field), overrides);
  1195. }
  1196. [Test]
  1197. [Category ("NotWorking")] // mark it NotWorking until fixes have landed in svn
  1198. public void TestImportMembersMapping()
  1199. {
  1200. Type type = typeof(SimpleClass);
  1201. XmlAttributes attrs = new XmlAttributes();
  1202. XmlAttributeOverrides overrides = new XmlAttributeOverrides();
  1203. overrides.Add(typeof(SimpleClass), attrs);
  1204. XmlReflectionMember[] members = new XmlReflectionMember[0];
  1205. XmlMembersMapping mm;
  1206. try
  1207. {
  1208. mm = MembersMap(type, overrides, members, true);
  1209. Assert.Fail("Should not be able to fetch an empty XmlMembersMapping");
  1210. }
  1211. catch (Exception)
  1212. {
  1213. }
  1214. XmlReflectionMember rm = new XmlReflectionMember();
  1215. rm.IsReturnValue = false;
  1216. rm.MemberName = "something";
  1217. rm.MemberType = typeof(string);
  1218. members = new XmlReflectionMember[1];
  1219. members[0] = rm;
  1220. mm = MembersMap(type, overrides, members, false);
  1221. Equals(mm.Count, 1);
  1222. XmlMemberMapping smm = mm[0];
  1223. Assert.IsFalse (smm.Any, "#1");
  1224. Assert.AreEqual ("something", smm.ElementName, "#2");
  1225. Assert.AreEqual ("something", smm.MemberName, "#3");
  1226. Assert.IsNull (smm.Namespace, "#4");
  1227. Assert.AreEqual ("System.String", smm.TypeFullName, "#5");
  1228. Assert.AreEqual ("string", smm.TypeName, "#6");
  1229. #if NET_2_0
  1230. Assert.AreEqual (XmlSchemaNamespace, smm.TypeNamespace, "#7");
  1231. #else
  1232. Assert.IsNull (smm.TypeNamespace, "#7");
  1233. #endif
  1234. rm = new XmlReflectionMember();
  1235. rm.IsReturnValue = false;
  1236. rm.MemberName = "nothing";
  1237. rm.MemberType = typeof(string);
  1238. members = new XmlReflectionMember[1];
  1239. members[0] = rm;
  1240. mm = MembersMap(type, overrides, members, false);
  1241. Assert.AreEqual (1, mm.Count, "#8");
  1242. }
  1243. [Test]
  1244. public void TestIntTypeMappingWithXmlRootAttribute()
  1245. {
  1246. const string TheNamespace = "another:urn";
  1247. XmlRootAttribute root = new XmlRootAttribute("price");
  1248. root.Namespace = TheNamespace;
  1249. XmlTypeMapping tm = Map(typeof(int), root);
  1250. Assert.AreEqual ("price", tm.ElementName, "#1");
  1251. Assert.AreEqual (TheNamespace, tm.Namespace, "#2");
  1252. Assert.AreEqual ("Int32", tm.TypeName, "#3");
  1253. Assert.AreEqual ("System.Int32", tm.TypeFullName, "#4");
  1254. }
  1255. [Test]
  1256. [ExpectedException (typeof (InvalidOperationException))]
  1257. public void TestSerializeWrongChoice ()
  1258. {
  1259. new XmlSerializer (typeof(WrongChoices));
  1260. }
  1261. public class Employee : IXmlSerializable
  1262. {
  1263. private string _firstName;
  1264. private string _lastName;
  1265. private string _address;
  1266. public XmlSchema GetSchema ()
  1267. {
  1268. return null;
  1269. }
  1270. public void WriteXml (XmlWriter writer)
  1271. {
  1272. writer.WriteStartElement ("employee", "urn:devx-com");
  1273. writer.WriteAttributeString ("firstName", _firstName);
  1274. writer.WriteAttributeString ("lastName", _lastName);
  1275. writer.WriteAttributeString ("address", _address);
  1276. writer.WriteEndElement ();
  1277. }
  1278. public void ReadXml (XmlReader reader)
  1279. {
  1280. XmlNodeType type = reader.MoveToContent ();
  1281. if (type == XmlNodeType.Element && reader.LocalName == "employee") {
  1282. _firstName = reader["firstName"];
  1283. _lastName = reader["lastName"];
  1284. _address = reader["address"];
  1285. }
  1286. }
  1287. }
  1288. public class NestedStruct
  1289. {
  1290. public TimeSpan Period = TimeSpan.MaxValue;
  1291. }
  1292. public class ObjectEnumerable : IEnumerable
  1293. {
  1294. public void Add (int value)
  1295. {
  1296. }
  1297. public void Add (object value)
  1298. {
  1299. }
  1300. public IEnumerator GetEnumerator ()
  1301. {
  1302. return new ArrayList ().GetEnumerator ();
  1303. }
  1304. }
  1305. public class SimpleClassEnumerable : IEnumerable
  1306. {
  1307. public void Add (int value)
  1308. {
  1309. }
  1310. public void Add (object value)
  1311. {
  1312. }
  1313. IEnumerator IEnumerable.GetEnumerator ()
  1314. {
  1315. return GetEnumerator ();
  1316. }
  1317. public SimpleClassEnumerator GetEnumerator ()
  1318. {
  1319. return new SimpleClassEnumerator (new ArrayList ());
  1320. }
  1321. }
  1322. public class SimpleClassEnumerablePrivateGetEnumerator : IEnumerable
  1323. {
  1324. public void Add (object value)
  1325. {
  1326. }
  1327. IEnumerator IEnumerable.GetEnumerator ()
  1328. {
  1329. return new ArrayList ().GetEnumerator ();
  1330. }
  1331. }
  1332. public class SimpleClassEnumerablePrivateCurrent : IEnumerable
  1333. {
  1334. public void Add (object value)
  1335. {
  1336. }
  1337. IEnumerator IEnumerable.GetEnumerator ()
  1338. {
  1339. return GetEnumerator ();
  1340. }
  1341. public NoCurrentEnumerator GetEnumerator ()
  1342. {
  1343. return new NoCurrentEnumerator (new ArrayList ());
  1344. }
  1345. }
  1346. // GetEnumerator().Current returns object, but there's no corresponding
  1347. // Add (System.Object) method
  1348. public class ObjectEnumerableNoMatchingAddMethod : IEnumerable
  1349. {
  1350. public void Add (int value)
  1351. {
  1352. }
  1353. public IEnumerator GetEnumerator ()
  1354. {
  1355. return new ArrayList ().GetEnumerator ();
  1356. }
  1357. }
  1358. // GetEnumerator().Current returns SimpleClass, but there's no
  1359. // corresponding Add (SimpleClass) method
  1360. public class SimpleClassCollectionNoMatchingAddMethod : ICollection
  1361. {
  1362. public SimpleClass this[int index]
  1363. {
  1364. get
  1365. {
  1366. return (SimpleClass) _list[index];
  1367. }
  1368. }
  1369. public int Count
  1370. {
  1371. get { return _list.Count; }
  1372. }
  1373. public bool IsSynchronized
  1374. {
  1375. get { return _list.IsSynchronized; }
  1376. }
  1377. public object SyncRoot
  1378. {
  1379. get { return _list.SyncRoot; }
  1380. }
  1381. public void CopyTo (Array array, int index)
  1382. {
  1383. _list.CopyTo (array, index);
  1384. }
  1385. IEnumerator IEnumerable.GetEnumerator ()
  1386. {
  1387. return GetEnumerator ();
  1388. }
  1389. public SimpleClassEnumerator GetEnumerator ()
  1390. {
  1391. return new SimpleClassEnumerator (_list);
  1392. }
  1393. private ArrayList _list = new ArrayList ();
  1394. }
  1395. // GetEnumerator().Current returns object, but there's no corresponding
  1396. // Add (System.Object) method
  1397. public class ObjectCollectionNoMatchingAddMethod : ICollection
  1398. {
  1399. public object this[int index]
  1400. {
  1401. get
  1402. {
  1403. return _list[index];
  1404. }
  1405. }
  1406. public int Count
  1407. {
  1408. get { return _list.Count; }
  1409. }
  1410. public bool IsSynchronized
  1411. {
  1412. get { return _list.IsSynchronized; }
  1413. }
  1414. public object SyncRoot
  1415. {
  1416. get { return _list.SyncRoot; }
  1417. }
  1418. public void CopyTo (Array array, int index)
  1419. {
  1420. _list.CopyTo (array, index);
  1421. }
  1422. IEnumerator IEnumerable.GetEnumerator ()
  1423. {
  1424. return GetEnumerator ();
  1425. }
  1426. public IEnumerator GetEnumerator ()
  1427. {
  1428. return _list.GetEnumerator ();
  1429. }
  1430. private ArrayList _list = new ArrayList ();
  1431. }
  1432. // Does not have int indexer.
  1433. public class SimpleClassCollectionNoIntIndexer : ICollection
  1434. {
  1435. public SimpleClass this[string name]
  1436. {
  1437. get
  1438. {
  1439. return new SimpleClass ();
  1440. }
  1441. }
  1442. public int Count
  1443. {
  1444. get { return _list.Count; }
  1445. }
  1446. public bool IsSynchronized
  1447. {
  1448. get { return _list.IsSynchronized; }
  1449. }
  1450. public object SyncRoot
  1451. {
  1452. get { return _list.SyncRoot; }
  1453. }
  1454. public void CopyTo (Array array, int index)
  1455. {
  1456. _list.CopyTo (array, index);
  1457. }
  1458. IEnumerator IEnumerable.GetEnumerator ()
  1459. {
  1460. return GetEnumerator ();
  1461. }
  1462. public SimpleClassEnumerator GetEnumerator ()
  1463. {
  1464. return new SimpleClassEnumerator (_list);
  1465. }
  1466. public void Add (SimpleClass value)
  1467. {
  1468. _list.Add (value);
  1469. }
  1470. private ArrayList _list = new ArrayList ();
  1471. }
  1472. // Does not have int indexer.
  1473. public class ObjectCollectionNoIntIndexer : ICollection
  1474. {
  1475. public object this[string name]
  1476. {
  1477. get
  1478. {
  1479. return new SimpleClass ();
  1480. }
  1481. }
  1482. public int Count
  1483. {
  1484. get { return _list.Count; }
  1485. }
  1486. public bool IsSynchronized
  1487. {
  1488. get { return _list.IsSynchronized; }
  1489. }
  1490. public object SyncRoot
  1491. {
  1492. get { return _list.SyncRoot; }
  1493. }
  1494. public void CopyTo (Array array, int index)
  1495. {
  1496. _list.CopyTo (array, index);
  1497. }
  1498. public IEnumerator GetEnumerator ()
  1499. {
  1500. return _list.GetEnumerator ();
  1501. }
  1502. public void Add (object value)
  1503. {
  1504. _list.Add (value);
  1505. }
  1506. private ArrayList _list = new ArrayList ();
  1507. }
  1508. public class SimpleClassCollection : ICollection
  1509. {
  1510. public SimpleClass this[int index]
  1511. {
  1512. get
  1513. {
  1514. return (SimpleClass) _list[index];
  1515. }
  1516. }
  1517. public int Count
  1518. {
  1519. get { return _list.Count; }
  1520. }
  1521. public bool IsSynchronized
  1522. {
  1523. get { return _list.IsSynchronized; }
  1524. }
  1525. public object SyncRoot
  1526. {
  1527. get { return _list.SyncRoot; }
  1528. }
  1529. public void CopyTo (Array array, int index)
  1530. {
  1531. _list.CopyTo (array, index);
  1532. }
  1533. IEnumerator IEnumerable.GetEnumerator ()
  1534. {
  1535. return GetEnumerator ();
  1536. }
  1537. public SimpleClassEnumerator GetEnumerator ()
  1538. {
  1539. return new SimpleClassEnumerator (_list);
  1540. }
  1541. public void Add (SimpleClass value)
  1542. {
  1543. _list.Add (value);
  1544. }
  1545. private ArrayList _list = new ArrayList ();
  1546. }
  1547. public class ObjectCollection : ICollection
  1548. {
  1549. public object this[int name]
  1550. {
  1551. get
  1552. {
  1553. return new SimpleClass ();
  1554. }
  1555. }
  1556. public int Count
  1557. {
  1558. get { return _list.Count; }
  1559. }
  1560. public bool IsSynchronized
  1561. {
  1562. get { return _list.IsSynchronized; }
  1563. }
  1564. public object SyncRoot
  1565. {
  1566. get { return _list.SyncRoot; }
  1567. }
  1568. public void CopyTo (Array array, int index)
  1569. {
  1570. _list.CopyTo (array, index);
  1571. }
  1572. public IEnumerator GetEnumerator ()
  1573. {
  1574. return _list.GetEnumerator ();
  1575. }
  1576. public void Add (object value)
  1577. {
  1578. _list.Add (value);
  1579. }
  1580. private ArrayList _list = new ArrayList ();
  1581. }
  1582. public class SimpleClassEnumerator : IEnumerator
  1583. {
  1584. internal SimpleClassEnumerator (ArrayList arguments)
  1585. {
  1586. IEnumerable temp = (IEnumerable) (arguments);
  1587. _baseEnumerator = temp.GetEnumerator ();
  1588. }
  1589. public SimpleClass Current
  1590. {
  1591. get { return (SimpleClass) _baseEnumerator.Current; }
  1592. }
  1593. object IEnumerator.Current
  1594. {
  1595. get { return _baseEnumerator.Current; }
  1596. }
  1597. public bool MoveNext ()
  1598. {
  1599. return _baseEnumerator.MoveNext ();
  1600. }
  1601. bool IEnumerator.MoveNext ()
  1602. {
  1603. return _baseEnumerator.MoveNext ();
  1604. }
  1605. public void Reset ()
  1606. {
  1607. _baseEnumerator.Reset ();
  1608. }
  1609. void IEnumerator.Reset ()
  1610. {
  1611. _baseEnumerator.Reset ();
  1612. }
  1613. private IEnumerator _baseEnumerator;
  1614. }
  1615. public class NoCurrentEnumerator : IEnumerator
  1616. {
  1617. internal NoCurrentEnumerator (ArrayList arguments)
  1618. {
  1619. IEnumerable temp = (IEnumerable) (arguments);
  1620. _baseEnumerator = temp.GetEnumerator ();
  1621. }
  1622. object IEnumerator.Current
  1623. {
  1624. get { return _baseEnumerator.Current; }
  1625. }
  1626. public bool MoveNext ()
  1627. {
  1628. return _baseEnumerator.MoveNext ();
  1629. }
  1630. bool IEnumerator.MoveNext ()
  1631. {
  1632. return _baseEnumerator.MoveNext ();
  1633. }
  1634. public void Reset ()
  1635. {
  1636. _baseEnumerator.Reset ();
  1637. }
  1638. void IEnumerator.Reset ()
  1639. {
  1640. _baseEnumerator.Reset ();
  1641. }
  1642. private IEnumerator _baseEnumerator;
  1643. }
  1644. }
  1645. }