View | Details | Raw Unified | Return to bug 18171
Collapse All | Expand All

(-)a/mcs/class/System.Runtime.Serialization/Test/System.Runtime.Serialization/DataContractSerializerTest_FrameworkTypes_System.Xml.Linq.cs (+82 lines)
Line 0 Link Here
1
//
2
// DataContractSerializerTest_FrameworkTypes_System.Xml.Linq.cs
3
//
4
// Author:
5
//  Brendan Zagaeski
6
//
7
// Copyright (C) 2013-2014 Xamarin Inc http://www.xamarin.com
8
//
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
16
// 
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
19
// 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
//
28
//
29
// This code contains tests for serializing and deserializing types in
30
// the System.Xml.Linq namespace using a DataContractSerializer.
31
32
using System;
33
using System.Runtime.Serialization;
34
using System.Xml;
35
using System.Xml.Linq;
36
using System.IO;
37
using NUnit.Framework;
38
using System.Collections.Generic;
39
using System.Text;
40
41
namespace MonoTests.System.Runtime.Serialization
42
{
43
	[TestFixture]
44
	public partial class DataContractSerializerTest_FrameworkTypes_System_Xml_Linq
45
		: DataContractSerializerTest_FrameworkTypes
46
	{
47
		static readonly XmlWriterSettings settings;
48
49
		static DataContractSerializerTest_FrameworkTypes_System_Xml_Linq ()
50
		{
51
			settings = new XmlWriterSettings ();
52
			settings.OmitXmlDeclaration = true;
53
		}
54
55
		[Test]
56
		public void Serialize_System_Xml_Linq_XElement_AnyTypeArray ()
57
		{
58
			Type t = typeof(XElement);
59
			var o = XElement.Parse ("<foo xmlns='' />");
60
			DataContractSerializer serializer = new DataContractSerializer (typeof(object[]), new List<Type> { typeof(XElement) });
61
			StringBuilder stringBuilder = new StringBuilder ();
62
			using (XmlWriter xmlWriter = XmlWriter.Create (new StringWriter (stringBuilder), settings))
63
				serializer.WriteObject (xmlWriter, new object[] { o });
64
			string actualXml = stringBuilder.ToString ();
65
			string expectedXml = "<ArrayOfanyType xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\"><anyType xmlns:d2p1=\"http://schemas.datacontract.org/2004/07/System.Xml.Linq\" i:type=\"d2p1:XElement\"><foo xmlns=\"\" /></anyType></ArrayOfanyType>";
66
67
			XmlComparer.AssertAreEqual (expectedXml, actualXml, "Serialization of " + t.FullName + " failed.");
68
		}
69
70
		[Test]
71
		public void Deserialize_System_Xml_Linq_XElement_AnyTypeArray ()
72
		{
73
			var o = XElement.Parse ("<foo xmlns='' />");
74
75
			var d = (XElement)Deserialize<object[]> (
76
				        "<ArrayOfanyType xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\"><anyType xmlns:d2p1=\"http://schemas.datacontract.org/2004/07/System.Xml.Linq\" i:type=\"d2p1:XElement\"><foo xmlns=\"\" /></anyType></ArrayOfanyType>",
77
				        new List<Type> { typeof(XElement) }) [0];
78
79
			Assert.IsTrue (XNode.DeepEquals (o, d), "The XElements were not equal.\nParse() created:\n{0}\n\nBut the deserialized object was:\n{1}\n", o, d);
80
		}
81
	}
82
}
(-)a/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XElementTest.cs (+11 lines)
Lines 2097-2101 namespace MonoTests.System.Xml.Linq Link Here
2097
			Assert.AreEqual (xe.Content.ToString (), "<Data />", "#3");
2097
			Assert.AreEqual (xe.Content.ToString (), "<Data />", "#3");
2098
		}
2098
		}
2099
#endif
2099
#endif
2100
2101
		[Test]
2102
		public void ParseVsReadXml ()
2103
		{
2104
			var p = XElement.Parse ("<root xmlns='urn:foo'><foo><xxx /></foo><x:bar xmlns:x='urn:bar'><yyy /></x:bar><baz xmlns=''><zzz /></baz></root>");
2105
			var r = XElement.Parse ("<foo />");
2106
			XmlReader xr = XmlReader.Create (new StringReader ("<root xmlns='urn:foo'><foo><xxx /></foo><x:bar xmlns:x='urn:bar'><yyy /></x:bar><baz xmlns=''><zzz /></baz></root>"), new XmlReaderSettings ());
2107
			((IXmlSerializable)r).ReadXml (xr);
2108
2109
			Assert.IsTrue (XNode.DeepEquals (p, r), "The XElements were not equal.\nParse() expected:\n{0}\n\nBut ReadXml() was:\n{1}\n", p, r);
2110
		}
2100
	}
2111
	}
2101
}
2112
}

Return to bug 18171