2 // System.Xml.XmlAttributesTests
7 // (C) 2003 Atsushi Enomoto
14 using System
.Xml
.Schema
;
15 using System
.Xml
.Serialization
;
17 using NUnit
.Framework
;
19 namespace MonoTests
.System
.XmlSerialization
22 public class XmlAttributesTests
: Assertion
28 private void SetUpWriter ()
30 sw
= new StringWriter ();
31 xtw
= new XmlTextWriter (sw
);
33 xtw
.Formatting
= Formatting
.None
;
36 private string WriterText
40 string val
= sw
.GetStringBuilder ().ToString();
41 int offset
= val
.IndexOf ('>') + 1;
42 val
= val
.Substring (offset
);
47 private void Serialize (object o
, XmlAttributeOverrides ao
)
50 xs
= new XmlSerializer (o
.GetType (), ao
);
51 xs
.Serialize (xtw
, o
);
54 private void Serialize (object o
, XmlRootAttribute root
)
57 xs
= new XmlSerializer (o
.GetType(), root
);
58 xs
.Serialize (xtw
, o
);
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
);
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
);
91 public void XmlTextAttribute ()
93 // based on default ctor.
94 XmlTextAttribute attr
= new XmlTextAttribute ();
95 AssertEquals ("", attr
.DataType
);
96 AssertNull (attr
.Type
);
98 XmlTextAttribute attr2
= new XmlTextAttribute (typeof (XmlNode
));
99 AssertEquals ("", attr
.DataType
);
100 AssertNull (attr
.Type
);
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
);
112 Fail ("Should be invalid.");
113 } catch (InvalidOperationException ex
) {