Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Add XmlSerializer test (based on bnc #548913)
Browse files Browse the repository at this point in the history
* Makefile.am: Link and embed (xap) our own version of the System.Xml.
Serialization.dll SDK assembly since it allows us to test both our
own SXS assembly and how it reacts/interact with the platform assemblies
  • Loading branch information
Sebastien Pouliot committed May 6, 2011
1 parent dee018d commit dcbec70
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
8 changes: 7 additions & 1 deletion test/2.0/moon-unit/Makefile.am
Expand Up @@ -124,7 +124,9 @@ REFERENCES = \
-r:$(top_builddir)/test/2.0/moon-unit/Microsoft.Silverlight.Testing.dll \
-r:$(top_builddir)/test/2.0/moon-unit/Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll \
-r:$(top_builddir)/test/2.0/moon-unit/Mono.Moonlight.UnitTesting.dll \
-r:$(top_builddir)/test/2.0/moon-unit/MoonAtkBridge.dll
-r:$(top_builddir)/test/2.0/moon-unit/MoonAtkBridge.dll \
-r:$(top_builddir)/class/lib/2.1/System.Xml.Serialization.dll \
-r:$(top_builddir)/class/lib/2.1/System.Xml.Linq.dll

DLLS_TO_EMBED = \
Microsoft.Silverlight.Testing.dll \
Expand All @@ -133,6 +135,7 @@ DLLS_TO_EMBED = \
Mono.Moonlight.UnitTesting.dll \
System.Windows.Controls.dll \
System.Windows.Controls.Data.dll \
System.Xml.Serialization.dll \
MoonAtkBridge.dll

appmanifest_ASSEMBLYPARTS= \
Expand Down Expand Up @@ -186,6 +189,9 @@ Microsoft.Silverlight.Testing.dll: ../Microsoft.Silverlight.Testing/Microsoft.Si
System.Xml.Linq.dll: ../Microsoft.Silverlight.Testing/System.Xml.Linq.dll
@cp ../Microsoft.Silverlight.Testing/System.Xml.Linq.dll* .

System.Xml.Serialization.dll: $(top_builddir)/class/lib/2.1/System.Xml.Serialization.dll
@cp $(top_builddir)/class/lib/2.1/System.Xml.Serialization.dll* .

Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll: ../Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight/Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll
@cp ../Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight/Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll* .

Expand Down
84 changes: 84 additions & 0 deletions test/2.0/moon-unit/System.Xml.Serialization/XmlSerializerTest.cs
@@ -0,0 +1,84 @@
//
// Unit tests for System.Xml.Serialization.XmlSerializer
//
// Contact:
// Moonlight List (moonlight-list@lists.ximian.com)
//
// Copyright (C) 2011 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MoonTest.System.Net.Sockets {

public class BusinessObject {

public BusinessObject ()
{
}

[XmlAttribute]
public int ID { get; set; }

[XmlAttribute]
public string Name { get; set; }

[XmlAttribute]
public string Description { get; set; }
}

[TestClass]
public class XmlSerializerTest {

XElement Serialize (string sName, object obj, XmlSerializerNamespaces ns)
{
XmlWriterSettings ws = new XmlWriterSettings ();
ws.OmitXmlDeclaration = true;
ws.NamespaceHandling = NamespaceHandling.OmitDuplicates;

XDocument xDoc = new XDocument ();
using (XmlWriter oWriter = XmlWriter.Create (xDoc.CreateWriter (), ws)) {
XmlSerializer oSerializer = new XmlSerializer (obj.GetType ());
oSerializer.Serialize (oWriter, obj, ns);
}

XElement xElem = xDoc.Root;
xElem.Name = sName;
return xElem;
}

[TestMethod] // ensure our S.SM.dll has the required internals for serialization
public void Bug548913 ()
{
BusinessObject obj = new BusinessObject () { ID = 1, Name = "bo1", Description = "Business Object 1" };
XElement xField = Serialize ("bo1", obj, new XmlSerializerNamespaces ());
// our xml is not identical, but close enough to be valid, so we're checking only parts
Assert.AreEqual ("1", xField.Attribute (XName.Get ("ID")).Value, "ID");
Assert.AreEqual ("bo1", xField.Attribute (XName.Get ("Name")).Value, "Name");
Assert.AreEqual ("Business Object 1", xField.Attribute (XName.Get ("Description")).Value, "Description");
}
}
}

0 comments on commit dcbec70

Please sign in to comment.