Merge pull request #1676 from ninjarobot/fix-xml-ser-tests
[mono.git] / mcs / class / System.XML / Test / System.Xml.Serialization / XmlAttributesTests.cs
index cf0e58c6283ab310f4af7705812cd84854c15cde..9cf534f2012fd87cf1d55ac7ac0238af9e865885 100644 (file)
-//\r
-// System.Xml.XmlAttributesTests\r
-//\r
-// Author:\r
-//   Atsushi Enomoto\r
-//\r
-// (C) 2003 Atsushi Enomoto\r
-//\r
-\r
-using System;\r
-using System.IO;\r
-using System.Text;\r
-using System.Xml;\r
-using System.Xml.Schema;\r
-using System.Xml.Serialization;\r
-\r
-using NUnit.Framework;\r
-\r
-namespace MonoTests.System.XmlSerialization\r
-{\r
-       [TestFixture]\r
-       public class XmlAttributesTests\r
-       {\r
-               StringWriter sw;\r
-               XmlTextWriter xtw;\r
-               XmlSerializer xs;\r
-\r
-               private void SetUpWriter ()\r
-               {\r
-                       sw = new StringWriter ();\r
-                       xtw = new XmlTextWriter (sw);\r
-                       xtw.QuoteChar = '\'';\r
-                       xtw.Formatting = Formatting.None;\r
-               }\r
-               \r
-               private string WriterText \r
-               {\r
-                       get\r
-                       {\r
-                               string val = sw.GetStringBuilder ().ToString();\r
-                               int offset = val.IndexOf ('>') + 1;\r
-                               val = val.Substring (offset);\r
-                               return val;\r
-                       }\r
-               }\r
-\r
-               private void Serialize (object o, XmlAttributeOverrides ao)\r
-               {\r
-                       SetUpWriter ();\r
-                       xs = new XmlSerializer (o.GetType (), ao);\r
-                       xs.Serialize (xtw, o);\r
-               }\r
-               \r
-               private void Serialize (object o, XmlRootAttribute root)\r
-               {\r
-                       SetUpWriter ();\r
-                       xs = new XmlSerializer (o.GetType(), root);\r
-                       xs.Serialize (xtw, o);\r
-               }\r
-\r
-               // Testcases.\r
-\r
-               [Test]\r
-               public void NewXmlAttributes ()\r
-               {\r
-                       // seems not different from Type specified ctor().\r
-                       XmlAttributes atts = new XmlAttributes ();\r
-                       Assert.IsNull (atts.XmlAnyAttribute, "#1");\r
-                       Assert.IsNotNull (atts.XmlAnyElements, "#2");\r
-                       Assert.AreEqual (0, atts.XmlAnyElements.Count, "#3");\r
-                       Assert.IsNull (atts.XmlArray, "#4");\r
-                       Assert.IsNotNull (atts.XmlArrayItems, "#5");\r
-                       Assert.AreEqual (0, atts.XmlArrayItems.Count, "#6");\r
-                       Assert.IsNull (atts.XmlAttribute, "#7");\r
-                       Assert.IsNull (atts.XmlChoiceIdentifier, "#8");\r
-                       Assert.IsNotNull (atts.XmlDefaultValue, "#9");\r
-                       // DBNull??\r
-                       Assert.AreEqual (DBNull.Value, atts.XmlDefaultValue, "#10");\r
-                       Assert.IsNotNull (atts.XmlElements, "#11");\r
-                       Assert.AreEqual (0, atts.XmlElements.Count, "#12");\r
-                       Assert.IsNull (atts.XmlEnum, "#13");\r
-                       Assert.IsNotNull (atts.XmlIgnore, "#14");\r
-                       Assert.AreEqual (TypeCode.Boolean, atts.XmlIgnore.GetTypeCode (), "#15");\r
-                       Assert.AreEqual (false, atts.Xmlns, "#16");\r
-                       Assert.IsNull (atts.XmlRoot, "#17");\r
-                       Assert.IsNull (atts.XmlText, "#18");\r
-                       Assert.IsNull (atts.XmlType, "#19");\r
-               }\r
-\r
-               [Test]\r
-               public void XmlTextAttribute ()\r
-               {\r
-                       // based on default ctor.\r
-                       XmlTextAttribute attr = new XmlTextAttribute ();\r
-                       Assert.AreEqual ("", attr.DataType, "#1");\r
-                       Assert.IsNull (attr.Type, "#2");\r
-                       // based on a type.\r
-                       XmlTextAttribute attr2 = new XmlTextAttribute (typeof (XmlNode));\r
-                       Assert.AreEqual ("", attr.DataType, "#3");\r
-                       Assert.IsNull (attr.Type, "#4");\r
-               }\r
-\r
-               [Test]\r
-               public void XmlInvalidElementAttribute ()\r
-               {\r
-                       XmlAttributeOverrides ao = new XmlAttributeOverrides ();\r
-                       XmlAttributes atts = new XmlAttributes ();\r
-                       atts.XmlElements.Add (new XmlElementAttribute ("xInt"));\r
-                       ao.Add (typeof (int), atts);\r
-                       try {\r
-                               Serialize (10, ao);\r
-                               Assert.Fail ("Should be invalid.");\r
-                       } catch (InvalidOperationException ex) {\r
-                       }\r
-               }\r
-       }\r
-}\r
+//
+// System.Xml.XmlAttributesTests
+//
+// Author:
+//   Atsushi Enomoto
+//
+// (C) 2003 Atsushi Enomoto
+//
+
+using System;
+using System.IO;
+using System.Text;
+using System.Reflection;
+using System.Xml;
+using System.Xml.Schema;
+using System.Xml.Serialization;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.XmlSerialization
+{
+       [TestFixture]
+       public class XmlAttributesTests
+       {
+               StringWriter sw;
+               XmlTextWriter xtw;
+               XmlSerializer xs;
+
+               private void SetUpWriter ()
+               {
+                       sw = new StringWriter ();
+                       xtw = new XmlTextWriter (sw);
+                       xtw.QuoteChar = '\'';
+                       xtw.Formatting = Formatting.None;
+               }
+               
+               private string WriterText 
+               {
+                       get
+                       {
+                               string val = sw.GetStringBuilder ().ToString();
+                               int offset = val.IndexOf ('>') + 1;
+                               val = val.Substring (offset);
+                               return val;
+                       }
+               }
+
+               private void Serialize (object o, XmlAttributeOverrides ao)
+               {
+                       SetUpWriter ();
+                       xs = new XmlSerializer (o.GetType (), ao);
+                       xs.Serialize (xtw, o);
+               }
+               
+               private void Serialize (object o, XmlRootAttribute root)
+               {
+                       SetUpWriter ();
+                       xs = new XmlSerializer (o.GetType(), root);
+                       xs.Serialize (xtw, o);
+               }
+
+               // Testcases.
+
+               [Test]
+               public void NewXmlAttributes ()
+               {
+                       // seems not different from Type specified ctor().
+                       XmlAttributes atts = new XmlAttributes ();
+                       Assert.IsNull (atts.XmlAnyAttribute, "#1");
+                       Assert.IsNotNull (atts.XmlAnyElements, "#2");
+                       Assert.AreEqual (0, atts.XmlAnyElements.Count, "#3");
+                       Assert.IsNull (atts.XmlArray, "#4");
+                       Assert.IsNotNull (atts.XmlArrayItems, "#5");
+                       Assert.AreEqual (0, atts.XmlArrayItems.Count, "#6");
+                       Assert.IsNull (atts.XmlAttribute, "#7");
+                       Assert.IsNull (atts.XmlChoiceIdentifier, "#8");
+                       Assert.IsNotNull (atts.XmlDefaultValue, "#9");
+                       // DBNull??
+                       Assert.AreEqual (DBNull.Value, atts.XmlDefaultValue, "#10");
+                       Assert.IsNotNull (atts.XmlElements, "#11");
+                       Assert.AreEqual (0, atts.XmlElements.Count, "#12");
+                       Assert.IsNull (atts.XmlEnum, "#13");
+                       Assert.IsNotNull (atts.XmlIgnore, "#14");
+                       Assert.AreEqual (TypeCode.Boolean, atts.XmlIgnore.GetTypeCode (), "#15");
+                       Assert.AreEqual (false, atts.Xmlns, "#16");
+                       Assert.IsNull (atts.XmlRoot, "#17");
+                       Assert.IsNull (atts.XmlText, "#18");
+                       Assert.IsNull (atts.XmlType, "#19");
+               }
+
+               [Test]
+               public void XmlTextAttribute ()
+               {
+                       // based on default ctor.
+                       XmlTextAttribute attr = new XmlTextAttribute ();
+                       Assert.AreEqual ("", attr.DataType, "#1");
+                       Assert.IsNull (attr.Type, "#2");
+                       // based on a type.
+                       XmlTextAttribute attr2 = new XmlTextAttribute (typeof (XmlNode));
+                       Assert.AreEqual ("", attr.DataType, "#3");
+                       Assert.IsNull (attr.Type, "#4");
+               }
+
+               [Test]
+               public void XmlInvalidElementAttribute ()
+               {
+                       XmlAttributeOverrides ao = new XmlAttributeOverrides ();
+                       XmlAttributes atts = new XmlAttributes ();
+                       atts.XmlElements.Add (new XmlElementAttribute ("xInt"));
+                       ao.Add (typeof (int), atts);
+                       try {
+                               Serialize (10, ao);
+                               Assert.Fail ("Should be invalid.");
+                       } catch (InvalidOperationException ex) {
+                       }
+               }
+               
+               [Test]
+               public void XmlIgnore ()
+               {
+                       FieldInfo field = GetType ().GetField ("XmlIgnoreField");
+                       XmlAttributes atts = new XmlAttributes (field);
+                       Assert.AreEqual (true, atts.XmlIgnore, "#1");
+                       Assert.AreEqual (0, atts.XmlElements.Count, "#2");
+                       Assert.AreEqual (0, atts.XmlAnyElements.Count, "#3");
+               }
+               
+               [XmlIgnore]
+               [XmlElement (IsNullable = true)]
+               [XmlAnyElement]
+               public int XmlIgnoreField;
+       }
+}