2 // XmlSyndicationContentTest.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2007 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
30 using System.Collections.Generic;
31 using System.Collections.ObjectModel;
33 using System.Runtime.Serialization;
36 using System.Xml.Serialization;
37 using System.ServiceModel.Syndication;
38 using NUnit.Framework;
40 using QName = System.Xml.XmlQualifiedName;
42 namespace MonoTests.System.ServiceModel.Syndication
45 public class XmlSyndicationContentTest
48 [ExpectedException (typeof (ArgumentNullException))]
49 public void ConstructorNullReader ()
51 new XmlSyndicationContent ((XmlReader) null);
55 [ExpectedException (typeof (ArgumentNullException))]
56 public void ConstructorNullExtensionObject ()
58 new XmlSyndicationContent ("text/plain", null, (XmlObjectSerializer) null);
62 public void ConstructorNullSerializer ()
65 new XmlSyndicationContent ("text/plain", 5, (XmlObjectSerializer) null);
66 new XmlSyndicationContent ("text/plain", 5, (XmlSerializer) null);
70 [ExpectedException (typeof (ArgumentNullException))]
71 public void ConstructorNullExtension ()
73 new XmlSyndicationContent ("text/plain", null);
77 public void ConstructorNullType ()
80 new XmlSyndicationContent (null, 5, (XmlObjectSerializer) null);
86 XmlSyndicationContent t = new XmlSyndicationContent (null, 3, (XmlObjectSerializer) null);
87 Assert.AreEqual ("text/xml", t.Type, "#1");
88 t = new XmlSyndicationContent ("text/plain", 3, (XmlObjectSerializer) null);
89 Assert.AreEqual ("text/plain", t.Type, "#2");
95 XmlSyndicationContent t = new XmlSyndicationContent ("text/plain", 3, (XmlObjectSerializer) null);
96 t = t.Clone () as XmlSyndicationContent;
97 Assert.AreEqual ("text/plain", t.Type, "#1");
101 public void WriteTo ()
103 XmlSyndicationContent t = new XmlSyndicationContent ("text/plain", 6, (XmlObjectSerializer) null);
104 StringWriter sw = new StringWriter ();
105 using (XmlWriter w = CreateWriter (sw))
106 t.WriteTo (w, "root", String.Empty);
107 Assert.AreEqual ("<root type=\"text/plain\"><int xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">6</int></root>", sw.ToString ());
110 XmlWriter CreateWriter (StringWriter sw)
112 XmlWriterSettings s = new XmlWriterSettings ();
113 s.OmitXmlDeclaration = true;
114 return XmlWriter.Create (sw, s);
118 public void GetReaderAtContent ()
120 var x = new SyndicationElementExtension (6);
122 Assert.AreEqual ("<int xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">6</int>", x.GetReader ().ReadOuterXml (), "#1");
124 var t = new XmlSyndicationContent ("text/xml", 6, (XmlObjectSerializer) null);
125 Assert.AreEqual ("<content type=\"text/xml\" xmlns=\"http://www.w3.org/2005/Atom\"><int xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">6</int></content>", t.GetReaderAtContent ().ReadOuterXml (), "#2");
129 public void GetReaderAtContent2 ()
131 var inxml = "<xcontent type=\"text/xhtml\" xmlns=\"XXX-http://www.w3.org/2005/Atom\"><int xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">6</int></xcontent>";
132 var ms = new MemoryStream ();
133 using (var xw = XmlWriter.Create (ms))
134 new XmlSyndicationContent (XmlReader.Create (new StringReader (inxml))).WriteTo (xw, "contentsss", "urn:x");
136 var expected = "<?xml version='1.0' encoding='utf-8'?><contentsss type='text/xml' xmlns='urn:x'><int xmlns='http://schemas.microsoft.com/2003/10/Serialization/'>6</int></contentsss>".Replace ('\'', '"');
137 Assert.AreEqual (expected, new StreamReader (ms).ReadToEnd (), "#1");