Merge pull request #2400 from esdrubal/extrahead
authorMarcos Henrich <marcoshenrich@gmail.com>
Mon, 15 Feb 2016 12:21:29 +0000 (12:21 +0000)
committerMarcos Henrich <marcoshenrich@gmail.com>
Mon, 15 Feb 2016 12:21:29 +0000 (12:21 +0000)
[System] Fix extra head in config bug.

1  2 
mcs/class/System/Test/System.Configuration/ApplicationSettingsBaseTest.cs

index 7b0b3ac8152a99b66953033ad54429352806d452,7b69842a4c5dfa18952da96ebafb6f2c672af249..e12f53291d208b523a3b974f70e561018a4a9ea2
  
  //#define SPEW
  
  using System;
+ using System.IO;
+ using System.Xml;
+ using System.Xml.Serialization;
+ using System.Xml.Schema;
  using System.Text;
  using System.Configuration;
  using System.ComponentModel;
@@@ -284,7 -287,7 +287,7 @@@ namespace MonoTests.System.Configuratio
                [Test]
                public void TestSettings2_Properties ()
                {
 -                      string expected = "MonoTests.System.Configuration.ProviderPoker, System_test_net_4_x, Version=0.0.0.0";
 +                      string expected = "MonoTests.System.Configuration.ProviderPoker, net_4_x_System_test, Version=0.0.0.0";
                        Assert.AreEqual (expected, new SettingsProviderAttribute (typeof (ProviderPoker)).ProviderTypeName.Substring (0, expected.Length), "#1");
                        TestSettings2 settings = new TestSettings2 ();
  
                        Assert.AreEqual ("eclair", holder1.TestKey, "#4");
                        Assert.AreEqual ("", holder2.TestKey, "#5");
                }
+               class Settings : ApplicationSettingsBase
+               {
+                       [UserScopedSetting]
+                       public WindowPositionList WindowPositions {
+                               get {
+                                       return ((WindowPositionList)(this ["WindowPositions"]));
+                               }
+                               set {
+                                       this ["WindowPositions"] = value;
+                               }
+                       }
+               }
+               [Serializable]
+               public class WindowPositionList : IXmlSerializable
+               {
+                       public XmlSchema GetSchema ()
+                       {
+                               return null;
+                       }
+                       public void ReadXml (XmlReader reader)
+                       {
+                               reader.ReadStartElement ("sampleNode");
+                               reader.ReadEndElement ();
+                       }
+                       public void WriteXml (XmlWriter writer)
+                       {
+                               writer.WriteStartElement ("sampleNode");
+                               writer.WriteEndElement ();
+                       }
+               }
+               [Test] //Covers 36388
+               public void XmlHeader ()
+               {
+                       try {
+                               var settings = new Settings ();
+                               settings.Reset ();
+                               settings.Save ();
+                               settings.WindowPositions = new WindowPositionList ();
+                               settings.Save ();
+                               // If Reloads fails then saved data is corrupted
+                               settings.Reload ();
+                       } catch (ConfigurationErrorsException e) {
+                               // Delete corrupted config file so other test won't fail.
+                               File.Delete (e.Filename);
+                               Assert.Fail ("Invalid data was saved to config file.");
+                       }
+               }
        }
  }