(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.XML / Test / System.Xml.Serialization / XmlAttributesTests.cs
blobc08bad3d96ca901f1e02ddd753f31dde76b1b310
1 //
2 // System.Xml.XmlAttributesTests
3 //
4 // Author:
5 // Atsushi Enomoto
6 //
7 // (C) 2003 Atsushi Enomoto
8 //
10 using System;
11 using System.IO;
12 using System.Text;
13 using System.Xml;
14 using System.Xml.Schema;
15 using System.Xml.Serialization;
17 using NUnit.Framework;
19 namespace MonoTests.System.XmlSerialization
21 [TestFixture]
22 public class XmlAttributesTests : Assertion
24 StringWriter sw;
25 XmlTextWriter xtw;
26 XmlSerializer xs;
28 private void SetUpWriter ()
30 sw = new StringWriter ();
31 xtw = new XmlTextWriter (sw);
32 xtw.QuoteChar = '\'';
33 xtw.Formatting = Formatting.None;
36 private string WriterText
38 get
40 string val = sw.GetStringBuilder ().ToString();
41 int offset = val.IndexOf ('>') + 1;
42 val = val.Substring (offset);
43 return val;
47 private void Serialize (object o, XmlAttributeOverrides ao)
49 SetUpWriter ();
50 xs = new XmlSerializer (o.GetType (), ao);
51 xs.Serialize (xtw, o);
54 private void Serialize (object o, XmlRootAttribute root)
56 SetUpWriter ();
57 xs = new XmlSerializer (o.GetType(), root);
58 xs.Serialize (xtw, o);
61 // Testcases.
63 [Test]
64 public void NewXmlAttributes ()
66 // seems not different from Type specified ctor().
67 XmlAttributes atts = new XmlAttributes ();
68 AssertNull (atts.XmlAnyAttribute);
69 AssertNotNull (atts.XmlAnyElements);
70 AssertEquals (0, atts.XmlAnyElements.Count);
71 AssertNull (atts.XmlArray);
72 AssertNotNull (atts.XmlArrayItems);
73 AssertEquals (0, atts.XmlArrayItems.Count);
74 AssertNull (atts.XmlAttribute);
75 AssertNull (atts.XmlChoiceIdentifier);
76 AssertNotNull (atts.XmlDefaultValue);
77 // DBNull??
78 AssertEquals (DBNull.Value, atts.XmlDefaultValue);
79 AssertNotNull (atts.XmlElements);
80 AssertEquals (0, atts.XmlElements.Count);
81 AssertNull (atts.XmlEnum);
82 AssertNotNull (atts.XmlIgnore);
83 AssertEquals (TypeCode.Boolean, atts.XmlIgnore.GetTypeCode ());
84 AssertEquals (false, atts.Xmlns);
85 AssertNull (atts.XmlRoot);
86 AssertNull (atts.XmlText);
87 AssertNull (atts.XmlType);
90 [Test]
91 public void XmlTextAttribute ()
93 // based on default ctor.
94 XmlTextAttribute attr = new XmlTextAttribute ();
95 AssertEquals ("", attr.DataType);
96 AssertNull (attr.Type);
97 // based on a type.
98 XmlTextAttribute attr2 = new XmlTextAttribute (typeof (XmlNode));
99 AssertEquals ("", attr.DataType);
100 AssertNull (attr.Type);
103 [Test]
104 public void XmlInvalidElementAttribute ()
106 XmlAttributeOverrides ao = new XmlAttributeOverrides ();
107 XmlAttributes atts = new XmlAttributes ();
108 atts.XmlElements.Add (new XmlElementAttribute ("xInt"));
109 ao.Add (typeof (int), atts);
110 try {
111 Serialize (10, ao);
112 Fail ("Should be invalid.");
113 } catch (InvalidOperationException ex) {