Add a couple of writer tests (NotWorking) and fixed XamlServices to not omit xmldecl.
authorAtsushi Eno <atsushi@ximian.com>
Mon, 25 Oct 2010 07:17:53 +0000 (16:17 +0900)
committerAtsushi Eno <atsushi@ximian.com>
Mon, 25 Oct 2010 07:17:53 +0000 (16:17 +0900)
mcs/class/System.Xaml/System.Xaml/XamlServices.cs
mcs/class/System.Xaml/Test/System.Xaml/XamlXmlWriterTest.cs

index b70f876cc05b0d4445707ba48dcb5674fec05743..5de7b6cacbb03273b8e175f1c656475b56620ade 100644 (file)
@@ -79,12 +79,14 @@ namespace System.Xaml
 
                public static void Save (Stream stream, object instance)
                {
-                       Save (new XamlXmlWriter (stream, new XamlSchemaContext ()), instance);
+                       using (var xw = XmlWriter.Create (stream, new XmlWriterSettings () { OmitXmlDeclaration = true }))
+                               Save (xw, instance);
                }
 
                public static void Save (TextWriter textWriter, object instance)
                {
-                       Save (new XamlXmlWriter (textWriter, new XamlSchemaContext ()), instance);
+                       using (var xw = XmlWriter.Create (textWriter, new XmlWriterSettings () { OmitXmlDeclaration = true }))
+                               Save (xw, instance);
                }
 
                public static void Save (XmlWriter xmlWriter, object instance)
index 78544df1b7cd96bd94bdc1ec442c02fe291cb0f8..ab844427d2761bcfdf54cff365db456e5c66229d 100644 (file)
@@ -25,6 +25,7 @@ using System.Collections;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.IO;
+using System.Linq;
 using System.Reflection;
 using System.Windows.Markup;
 using System.Xaml;
@@ -631,6 +632,115 @@ namespace MonoTests.System.Xaml
                        xw.Close ();
                        string xml = String.Format (@"<?xml version='1.0' encoding='utf-16'?><TestXmlWriterClass1 xmlns='clr-namespace:MonoTests.System.Xaml;assembly={0}' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'></TestXmlWriterClass1>",  GetType ().Assembly.GetName ().Name);
                }
+
+               string ReadXml (string name)
+               {
+                       return File.ReadAllText ("Test/XmlFiles/" + name).Trim ().Replace ("\r\n", "\n").Replace ("\n", Environment.NewLine);
+               }
+
+               [Test]
+               public void Write_String ()
+               {
+                       Assert.AreEqual (ReadXml ("String.xml"), XamlServices.Save ("foo"), "#1");
+               }
+
+               [Test]
+               public void Write_Int32 ()
+               {
+                       Assert.AreEqual (ReadXml ("Int32.xml"), XamlServices.Save (5), "#1");
+               }
+
+               [Test]
+               public void Write_DateTime ()
+               {
+                       Assert.AreEqual (ReadXml ("DateTime.xml"), XamlServices.Save (new DateTime (2010, 4, 14)), "#1");
+               }
+
+               [Test]
+               public void Write_TimeSpan ()
+               {
+                       Assert.AreEqual (ReadXml ("TimeSpan.xml"), XamlServices.Save (TimeSpan.FromMinutes (7)), "#1");
+               }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void Write_Null ()
+               {
+                       Assert.AreEqual (ReadXml ("NullExtension.xml"), XamlServices.Save (null), "#1");
+               }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void Write_NullExtension ()
+               {
+                       Assert.AreEqual (ReadXml ("NullExtension.xml"), XamlServices.Save (new NullExtension ()), "#1");
+               }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void Write_Type ()
+               {
+                       Assert.AreEqual (ReadXml ("Type.xml").Trim (), XamlServices.Save (typeof (int)), "#1");
+               }
+
+               [Test]
+               public void Write_Guid ()
+               {
+                       Assert.AreEqual (ReadXml ("Guid.xml").Trim (), XamlServices.Save (Guid.Parse ("9c3345ec-8922-4662-8e8d-a4e41f47cf09")), "#1");
+               }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void Write_StaticExtension ()
+               {
+                       Assert.AreEqual (ReadXml ("StaticExtension.xml").Trim (), XamlServices.Save (new StaticExtension ("FooBar")), "#1");
+               }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void Write_Reference ()
+               {
+                       Assert.AreEqual (ReadXml ("Reference.xml").Trim (), XamlServices.Save (new Reference ("FooBar")), "#1");
+               }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void Write_ArrayInt32 ()
+               {
+                       Assert.AreEqual (ReadXml ("Array_Int32.xml").Trim (), XamlServices.Save (new int [] {4, -5, 0, 255, int.MaxValue}), "#1");
+               }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void Write_ListInt32 ()
+               {
+                       Assert.AreEqual (ReadXml ("List_Int32.xml").Trim (), XamlServices.Save (new int [] {4, -5, 0, 255, int.MaxValue}.ToList ()), "#1");
+               }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void Write_DictionaryInt32String ()
+               {
+                       var dic = new Dictionary<int,string> ();
+                       dic.Add (0, "foo");
+                       dic.Add (5, "bar");
+                       dic.Add (-2, "baz");
+                       Assert.AreEqual (ReadXml ("Dictionary_Int32_String.xml").Trim (), XamlServices.Save (dic), "#1");
+               }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void Write_DictionaryStringType ()
+               {
+                       var dic = new Dictionary<string,Type> ();
+                       dic.Add ("t1", typeof (int));
+                       dic.Add ("t2", typeof (int []));
+                       dic.Add ("t3", typeof (int?));
+                       dic.Add ("t4", typeof (List<int>));
+                       dic.Add ("t5", typeof (Dictionary<int,DateTime>));
+                       dic.Add ("t6", typeof (List<KeyValuePair<int,DateTime>>));
+                       Assert.AreEqual (ReadXml ("Dictionary_String_Type.xml").Trim (), XamlServices.Save (dic), "#1");
+               }
        }
 
        public class TestXmlWriterClass1