XmlSerializerTests.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. //
  2. // System.Xml.XmlSerializerTests
  3. //
  4. // Author:
  5. // Erik LeBel <[email protected]>
  6. //
  7. // (C) 2003 Erik LeBel
  8. //
  9. //
  10. // NOTES:
  11. // Where possible, these tests avoid testing the order of
  12. // an object's members serialization. Mono and .NET do not
  13. // reflect members in the same order.
  14. //
  15. // Only serializations tests so far, no deserialization.
  16. //
  17. // FIXME
  18. // test XmlArrayAttribute
  19. // test XmlArrayItemAttribute
  20. // test serialization of decimal type
  21. // test serialization of Guid type
  22. // test XmlNode serialization with and without modifying attributes.
  23. // test deserialization
  24. // FIXMEs found in this file
  25. using System;
  26. using System.IO;
  27. using System.Text;
  28. using System.Xml;
  29. using System.Xml.Schema;
  30. using System.Xml.Serialization;
  31. using NUnit.Framework;
  32. using MonoTests.System.Xml.TestClasses;
  33. namespace MonoTests.System.Xml
  34. {
  35. [TestFixture]
  36. public class XmlSerializerTests : Assertion
  37. {
  38. StringWriter sw;
  39. XmlTextWriter xtw;
  40. XmlSerializer xs;
  41. private void SetUpWriter()
  42. {
  43. sw = new StringWriter ();
  44. xtw = new XmlTextWriter (sw);
  45. xtw.QuoteChar = '\'';
  46. xtw.Formatting = Formatting.None;
  47. }
  48. private string WriterText
  49. {
  50. get
  51. {
  52. string val = sw.GetStringBuilder().ToString();
  53. int offset = val.IndexOf('>') + 1;
  54. val = val.Substring(offset);
  55. return val;
  56. }
  57. }
  58. private void Serialize(object o)
  59. {
  60. SetUpWriter();
  61. xs = new XmlSerializer(o.GetType());
  62. xs.Serialize(xtw, o);
  63. }
  64. private void Serialize(object o, Type type)
  65. {
  66. SetUpWriter();
  67. xs = new XmlSerializer(type);
  68. xs.Serialize(xtw, o);
  69. }
  70. private void Serialize(object o, XmlSerializerNamespaces ns)
  71. {
  72. SetUpWriter();
  73. xs = new XmlSerializer(o.GetType());
  74. xs.Serialize(xtw, o, ns);
  75. }
  76. private void Serialize(object o, XmlAttributeOverrides ao)
  77. {
  78. SetUpWriter();
  79. xs = new XmlSerializer(o.GetType(), ao);
  80. xs.Serialize(xtw, o);
  81. }
  82. private void Serialize(object o, XmlRootAttribute root)
  83. {
  84. SetUpWriter();
  85. xs = new XmlSerializer(o.GetType(), root);
  86. xs.Serialize(xtw, o);
  87. }
  88. // test constructors
  89. [Test]
  90. public void TestConstructor()
  91. {
  92. XmlSerializer ser=new XmlSerializer(null, "");
  93. }
  94. // test basic types ////////////////////////////////////////////////////////
  95. [Test]
  96. public void TestSerializeInt()
  97. {
  98. Serialize(10);
  99. AssertEquals(WriterText, "<int>10</int>");
  100. }
  101. [Test]
  102. public void TestSerializeBool()
  103. {
  104. Serialize(true);
  105. AssertEquals("<boolean>true</boolean>", WriterText);
  106. Serialize(false);
  107. AssertEquals("<boolean>false</boolean>", WriterText);
  108. }
  109. [Test]
  110. public void TestSerializeString()
  111. {
  112. Serialize("hello");
  113. AssertEquals("<string>hello</string>", WriterText);
  114. }
  115. [Test]
  116. public void TestSerializeEmptyString()
  117. {
  118. Serialize(String.Empty);
  119. AssertEquals("<string />", WriterText);
  120. }
  121. [Test]
  122. public void TestSerializeNullObject()
  123. {
  124. Serialize(null, typeof(object));
  125. AssertEquals(WriterText, "<anyType xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true' />");
  126. }
  127. [Test]
  128. public void TestSerializeNullString()
  129. {
  130. Serialize(null, typeof(string));
  131. Assert(WriterText.EndsWith("xsi:nil='true' />"));
  132. }
  133. [Test]
  134. public void TestSerializeIntArray()
  135. {
  136. Serialize(new int[] {1, 2, 3, 4});
  137. Assert(WriterText.EndsWith("<int>1</int><int>2</int><int>3</int><int>4</int></ArrayOfInt>"));
  138. }
  139. [Test]
  140. public void TestSerializeEmptyArray()
  141. {
  142. Serialize(new int[] {});
  143. AssertEquals(WriterText, "<ArrayOfInt xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />");
  144. }
  145. [Test]
  146. public void TestSerializeChar()
  147. {
  148. Serialize('A');
  149. AssertEquals(WriterText, "<char>65</char>");
  150. Serialize('\0');
  151. AssertEquals(WriterText, "<char>0</char>");
  152. Serialize('\n');
  153. AssertEquals(WriterText, "<char>10</char>");
  154. Serialize('\uFF01');
  155. AssertEquals(WriterText, "<char>65281</char>");
  156. }
  157. [Test]
  158. public void TestSerializeFloat()
  159. {
  160. Serialize(10.78);
  161. AssertEquals(WriterText, "<double>10.78</double>");
  162. Serialize(-1e8);
  163. AssertEquals(WriterText, "<double>-100000000</double>");
  164. // FIXME test INF and other boundary conditions that may exist with floats
  165. }
  166. [Test]
  167. public void TestSerializeEnumeration()
  168. {
  169. Serialize(SimpleEnumeration.FIRST);
  170. AssertEquals(WriterText, "<SimpleEnumeration>FIRST</SimpleEnumeration>");
  171. Serialize(SimpleEnumeration.SECOND);
  172. AssertEquals(WriterText, "<SimpleEnumeration>SECOND</SimpleEnumeration>");
  173. }
  174. [Test]
  175. public void TestSerializeQualifiedName()
  176. {
  177. Serialize(new XmlQualifiedName("me", "home.urn"));
  178. AssertEquals(WriterText, "<QName xmlns:q1='home.urn'>q1:me</QName>");
  179. }
  180. [Test]
  181. public void TestSerializeBytes()
  182. {
  183. Serialize((byte)0xAB);
  184. AssertEquals(WriterText, "<unsignedByte>171</unsignedByte>");
  185. Serialize((byte)15);
  186. AssertEquals(WriterText, "<unsignedByte>15</unsignedByte>");
  187. }
  188. [Test]
  189. public void TestSerializeByteArrays()
  190. {
  191. Serialize(new byte[] {});
  192. AssertEquals(WriterText, "<base64Binary />");
  193. Serialize(new byte[] {0xAB, 0xCD});
  194. AssertEquals(WriterText, "<base64Binary>q80=</base64Binary>");
  195. }
  196. [Test]
  197. public void TestSerializeDateTime()
  198. {
  199. DateTime d = new DateTime();
  200. Serialize(d);
  201. AssertEquals ("<dateTime>0001-01-01T00:00:00.0000000", WriterText.Substring (0, 37));
  202. }
  203. /*
  204. FIXME
  205. - decimal
  206. - Guid
  207. - XmlNode objects
  208. [Test]
  209. public void TestSerialize()
  210. {
  211. Serialize();
  212. AssertEquals(WriterText, "");
  213. }
  214. */
  215. // test basic class serialization /////////////////////////////////////
  216. [Test]
  217. public void TestSerializeSimpleClass()
  218. {
  219. SimpleClass simple = new SimpleClass();
  220. Serialize(simple);
  221. AssertEquals(WriterText, "<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />");
  222. simple.something = "hello";
  223. Serialize(simple);
  224. AssertEquals(WriterText, "<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something>hello</something></SimpleClass>");
  225. }
  226. [Test]
  227. public void TestSerializeStringCollection()
  228. {
  229. StringCollection strings = new StringCollection();
  230. Serialize(strings);
  231. AssertEquals(WriterText, "<ArrayOfString xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />");
  232. strings.Add("hello");
  233. strings.Add("goodbye");
  234. Serialize(strings);
  235. Assert(WriterText.EndsWith("><string>hello</string><string>goodbye</string></ArrayOfString>"));
  236. }
  237. [Test]
  238. public void TestSerializePlainContainer()
  239. {
  240. StringCollectionContainer container = new StringCollectionContainer();
  241. Serialize(container);
  242. Assert(WriterText.EndsWith("><Messages /></StringCollectionContainer>"));
  243. container.Messages.Add("hello");
  244. container.Messages.Add("goodbye");
  245. Serialize(container);
  246. Assert(WriterText.EndsWith("><Messages><string>hello</string><string>goodbye</string></Messages></StringCollectionContainer>"));
  247. }
  248. [Test]
  249. public void TestSerializeArrayContainer()
  250. {
  251. ArrayContainer container = new ArrayContainer();
  252. Serialize(container);
  253. AssertEquals(WriterText, "<ArrayContainer xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />");
  254. container.items = new object[] {10, 20};
  255. Serialize(container);
  256. Assert(WriterText.EndsWith("><items><anyType xsi:type='xsd:int'>10</anyType><anyType xsi:type='xsd:int'>20</anyType></items></ArrayContainer>"));
  257. container.items = new object[] {10, "hello"};
  258. Serialize(container);
  259. Assert(WriterText.EndsWith("><items><anyType xsi:type='xsd:int'>10</anyType><anyType xsi:type='xsd:string'>hello</anyType></items></ArrayContainer>"));
  260. }
  261. [Test]
  262. public void TestSerializeClassArrayContainer()
  263. {
  264. ClassArrayContainer container = new ClassArrayContainer();
  265. Serialize(container);
  266. AssertEquals(WriterText, "<ClassArrayContainer xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />");
  267. SimpleClass simple1 = new SimpleClass();
  268. simple1.something = "hello";
  269. SimpleClass simple2 = new SimpleClass();
  270. simple2.something = "hello";
  271. container.items = new SimpleClass[2];
  272. container.items[0] = simple1;
  273. container.items[1] = simple2;
  274. Serialize(container);
  275. Assert(WriterText.EndsWith("><items><SimpleClass><something>hello</something></SimpleClass><SimpleClass><something>hello</something></SimpleClass></items></ClassArrayContainer>"));
  276. }
  277. // test basic attributes ///////////////////////////////////////////////
  278. [Test]
  279. public void TestSerializeSimpleClassWithXmlAttributes()
  280. {
  281. SimpleClassWithXmlAttributes simple = new SimpleClassWithXmlAttributes();
  282. Serialize(simple);
  283. AssertEquals(WriterText, "<simple xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />");
  284. simple.something = "hello";
  285. Serialize(simple);
  286. Assert(WriterText.EndsWith(" member='hello' />"));
  287. }
  288. // test overrides ///////////////////////////////////////////////////////
  289. [Test]
  290. public void TestSerializeSimpleClassWithOverrides()
  291. {
  292. // Also tests XmlIgnore
  293. XmlAttributeOverrides overrides = new XmlAttributeOverrides();
  294. XmlAttributes attr = new XmlAttributes();
  295. attr.XmlIgnore = true;
  296. overrides.Add(typeof(SimpleClassWithXmlAttributes), "something", attr);
  297. SimpleClassWithXmlAttributes simple = new SimpleClassWithXmlAttributes();
  298. simple.something = "hello";
  299. Serialize(simple, overrides);
  300. AssertEquals(WriterText, "<simple xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />");
  301. }
  302. // test xmlText //////////////////////////////////////////////////////////
  303. [Test]
  304. public void TestSerializeXmlTextAttribute()
  305. {
  306. SimpleClass simple = new SimpleClass();
  307. simple.something = "hello";
  308. XmlAttributeOverrides overrides = new XmlAttributeOverrides();
  309. XmlAttributes attr = new XmlAttributes();
  310. overrides.Add(typeof(SimpleClass), "something", attr);
  311. attr.XmlText = new XmlTextAttribute();
  312. Serialize(simple, overrides);
  313. AssertEquals(WriterText, "<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>hello</SimpleClass>");
  314. attr.XmlText = new XmlTextAttribute(typeof(string));
  315. Serialize(simple, overrides);
  316. Assert(WriterText.EndsWith(">hello</SimpleClass>"));
  317. try
  318. {
  319. attr.XmlText = new XmlTextAttribute(typeof(byte[]));
  320. Serialize(simple, overrides);
  321. Fail("XmlText.Type does not match the type it serializes: this should have failed");
  322. }
  323. catch (Exception)
  324. {
  325. }
  326. try
  327. {
  328. attr.XmlText = new XmlTextAttribute();
  329. attr.XmlText.DataType = "sometype";
  330. Serialize(simple, overrides);
  331. Fail("XmlText.DataType does not match the type it serializes: this should have failed");
  332. }
  333. catch (Exception)
  334. {
  335. }
  336. }
  337. // test xmlRoot //////////////////////////////////////////////////////////
  338. [Test]
  339. public void TestSerializeXmlRootAttribute()
  340. {
  341. // constructor override & element name
  342. XmlRootAttribute root = new XmlRootAttribute();
  343. root.ElementName = "renamed";
  344. SimpleClassWithXmlAttributes simpleWithAttributes = new SimpleClassWithXmlAttributes();
  345. Serialize(simpleWithAttributes, root);
  346. Assert(WriterText.StartsWith("<renamed "));
  347. SimpleClass simple = null;
  348. root.IsNullable = false;
  349. try
  350. {
  351. Serialize(simple, root);
  352. Fail("Cannot serialize null object if XmlRoot's IsNullable == false");
  353. }
  354. catch (Exception)
  355. {
  356. }
  357. root.IsNullable = true;
  358. try
  359. {
  360. Serialize(simple, root);
  361. Fail("Cannot serialize null object if XmlRoot's IsNullable == true");
  362. }
  363. catch (Exception)
  364. {
  365. }
  366. simple = new SimpleClass();
  367. root.ElementName = null;
  368. root.Namespace = "some.urn";
  369. Serialize(simple, root);
  370. AssertEquals(WriterText, "<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='some.urn' />");
  371. }
  372. [Test]
  373. public void TestSerializeXmlRootAttributeOnMember()
  374. {
  375. // nested root
  376. XmlAttributeOverrides overrides = new XmlAttributeOverrides();
  377. XmlAttributes childAttr = new XmlAttributes();
  378. childAttr.XmlRoot = new XmlRootAttribute("simple");
  379. overrides.Add(typeof(SimpleClass), childAttr);
  380. XmlAttributes attr = new XmlAttributes();
  381. attr.XmlRoot = new XmlRootAttribute("simple");
  382. overrides.Add(typeof(ClassArrayContainer), attr);
  383. ClassArrayContainer container = new ClassArrayContainer();
  384. container.items = new SimpleClass[1];
  385. container.items[0] = new SimpleClass();;
  386. Serialize(container, overrides);
  387. Assert(WriterText.EndsWith("><items><SimpleClass /></items></simple>"));
  388. // FIXME test data type
  389. }
  390. // test XmlAttribute /////////////////////////////////////////////////////
  391. [Test]
  392. public void TestSerializeXmlAttributeAttribute()
  393. {
  394. // null
  395. XmlAttributeOverrides overrides = new XmlAttributeOverrides();
  396. XmlAttributes attr = new XmlAttributes();
  397. attr.XmlAttribute = new XmlAttributeAttribute();
  398. overrides.Add(typeof(SimpleClass), "something", attr);
  399. SimpleClass simple = new SimpleClass();;
  400. Serialize(simple, overrides);
  401. AssertEquals(WriterText, "<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />");
  402. // regular
  403. simple.something = "hello";
  404. Serialize(simple, overrides);
  405. Assert(WriterText.EndsWith(" something='hello' />"));
  406. // AttributeName
  407. attr.XmlAttribute.AttributeName = "somethingelse";
  408. Serialize(simple, overrides);
  409. Assert(WriterText.EndsWith(" somethingelse='hello' />"));
  410. // Type
  411. // FIXME this should work, shouldnt it?
  412. // attr.XmlAttribute.Type = typeof(string);
  413. // Serialize(simple, overrides);
  414. // Assert(WriterText.EndsWith(" something='hello' />"));
  415. // Namespace
  416. attr.XmlAttribute.Namespace = "some:urn";
  417. Serialize(simple, overrides);
  418. Assert(WriterText.EndsWith(" d1p1:somethingelse='hello' xmlns:d1p1='some:urn' />"));
  419. // FIXME DataType
  420. // FIXME XmlSchemaForm Form
  421. // FIXME write XmlQualifiedName as attribute
  422. }
  423. // test XmlElement ///////////////////////////////////////////////////////
  424. [Test]
  425. public void TestSerializeXmlElementAttribute()
  426. {
  427. XmlAttributeOverrides overrides = new XmlAttributeOverrides();
  428. XmlAttributes attr = new XmlAttributes();
  429. XmlElementAttribute element = new XmlElementAttribute();
  430. attr.XmlElements.Add(element);
  431. overrides.Add(typeof(SimpleClass), "something", attr);
  432. // null
  433. SimpleClass simple = new SimpleClass();;
  434. Serialize(simple, overrides);
  435. AssertEquals(WriterText, "<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />");
  436. // not null
  437. simple.something = "hello";
  438. Serialize(simple, overrides);
  439. Assert(WriterText.EndsWith("><something>hello</something></SimpleClass>"));
  440. //ElementName
  441. element.ElementName = "saying";
  442. Serialize(simple, overrides);
  443. Assert(WriterText.EndsWith("><saying>hello</saying></SimpleClass>"));
  444. //IsNullable
  445. element.IsNullable = false;
  446. simple.something = null;
  447. Serialize(simple, overrides);
  448. AssertEquals(WriterText, "<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />");
  449. element.IsNullable = true;
  450. simple.something = null;
  451. Serialize(simple, overrides);
  452. Assert(WriterText.EndsWith("><saying xsi:nil='true' /></SimpleClass>"));
  453. //Namespace
  454. element.ElementName = null;
  455. element.IsNullable = false;
  456. element.Namespace = "some:urn";
  457. simple.something = "hello";
  458. Serialize(simple, overrides);
  459. Assert(WriterText.EndsWith("><something xmlns='some:urn'>hello</something></SimpleClass>"));
  460. //FIXME DataType
  461. //FIXME Form
  462. //FIXME Type
  463. }
  464. // test XmlElementAttribute with arrays and collections //////////////////
  465. [Test]
  466. public void TestSerializeCollectionWithXmlElementAttribute()
  467. {
  468. // the rule is:
  469. // if no type is specified or the specified type
  470. // matches the contents of the collection,
  471. // serialize each element in an element named after the member.
  472. // if the type does not match, or matches the collection itself,
  473. // create a base wrapping element for the member, and then
  474. // wrap each collection item in its own wrapping element based on type.
  475. XmlAttributeOverrides overrides = new XmlAttributeOverrides();
  476. XmlAttributes attr = new XmlAttributes();
  477. XmlElementAttribute element = new XmlElementAttribute();
  478. attr.XmlElements.Add(element);
  479. overrides.Add(typeof(StringCollectionContainer), "Messages", attr);
  480. // empty collection & no type info in XmlElementAttribute
  481. StringCollectionContainer container = new StringCollectionContainer();
  482. Serialize(container, overrides);
  483. AssertEquals(WriterText, "<StringCollectionContainer xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />");
  484. // non-empty collection & no type info in XmlElementAttribute
  485. container.Messages.Add("hello");
  486. Serialize(container, overrides);
  487. Assert(WriterText.EndsWith("><Messages>hello</Messages></StringCollectionContainer>"));
  488. // non-empty collection & only type info in XmlElementAttribute
  489. element.Type = typeof(StringCollection);
  490. Serialize(container, overrides);
  491. Assert(WriterText.EndsWith("><Messages><string>hello</string></Messages></StringCollectionContainer>"));
  492. // non-empty collection & only type info in XmlElementAttribute
  493. element.Type = typeof(string);
  494. Serialize(container, overrides);
  495. Assert(WriterText.EndsWith("><Messages>hello</Messages></StringCollectionContainer>"));
  496. // two elements
  497. container.Messages.Add("goodbye");
  498. element.Type = null;
  499. Serialize(container, overrides);
  500. Assert(WriterText.EndsWith("><Messages>hello</Messages><Messages>goodbye</Messages></StringCollectionContainer>"));
  501. }
  502. // test DefaultValue /////////////////////////////////////////////////////
  503. [Test]
  504. public void TestSerializeDefaultValueAttribute()
  505. {
  506. XmlAttributeOverrides overrides = new XmlAttributeOverrides();
  507. XmlAttributes attr = new XmlAttributes();
  508. string defaultValueInstance = "nothing";
  509. attr.XmlDefaultValue = defaultValueInstance;
  510. overrides.Add(typeof(SimpleClass), "something", attr);
  511. // use the default
  512. SimpleClass simple = new SimpleClass();
  513. Serialize(simple, overrides);
  514. AssertEquals(WriterText, "<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />");
  515. // same value as default
  516. simple.something = defaultValueInstance;
  517. Serialize(simple, overrides);
  518. AssertEquals(WriterText, "<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />");
  519. // some other value
  520. simple.something = "hello";
  521. Serialize(simple, overrides);
  522. AssertEquals(WriterText, "<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something>hello</something></SimpleClass>");
  523. }
  524. // test XmlEnum //////////////////////////////////////////////////////////
  525. [Test]
  526. public void TestSerializeXmlEnumAttribute()
  527. {
  528. // technically this has an XmlIgnore attribute,
  529. // but it is not being serialized as a member.
  530. Serialize(XmlSchemaForm.None);
  531. AssertEquals(WriterText, "<XmlSchemaForm>0</XmlSchemaForm>");
  532. Serialize(XmlSchemaForm.Qualified);
  533. AssertEquals(WriterText, "<XmlSchemaForm>qualified</XmlSchemaForm>");
  534. Serialize(XmlSchemaForm.Unqualified);
  535. AssertEquals(WriterText, "<XmlSchemaForm>unqualified</XmlSchemaForm>");
  536. }
  537. }
  538. }