Procházet zdrojové kódy

2009-04-15 Atsushi Enomoto <[email protected]>

	* ServiceDocument.cs : remove Utility class. It is not precise
	  implementation to write extensions.
	* ServiceDocumentFormatter.cs : virtual extension writer methods
	  should call possibly overriden Write[Element/Attribute]Extensions()
	  in possibly derived document item classes.
	  Implemented LoadElementExtensions().
	* AtomPub10CategoriesDocumentFormatter.cs,
	  AtomPub10ServiceDocumentFormatter.cs : Implemented GetSchema().

	* AtomPub10CategoriesDocumentFormatterTest.cs,
	  AtomPub10ServiceDocumentFormatterTest.cs : aded GetSchema() and
	  WriteElementExtensions() tests.


svn path=/trunk/mcs/; revision=131737
Atsushi Eno před 16 roky
rodič
revize
a7cbc14542

+ 1 - 2
mcs/class/System.ServiceModel.Web/System.ServiceModel.Syndication/AtomPub10CategoriesDocumentFormatter.cs

@@ -183,10 +183,9 @@ namespace System.ServiceModel.Syndication
 				atom10_formatter.WriteCategory (cat, writer);
 		}
 
-		[MonoTODO]
 		XmlSchema IXmlSerializable.GetSchema ()
 		{
-			throw new NotImplementedException ();
+			return null;
 		}
 
 		void IXmlSerializable.ReadXml (XmlReader reader)

+ 1 - 2
mcs/class/System.ServiceModel.Web/System.ServiceModel.Syndication/AtomPub10ServiceDocumentFormatter.cs

@@ -145,10 +145,9 @@ namespace System.ServiceModel.Syndication
 			writer.WriteEndElement ();
 		}
 
-		[MonoTODO]
 		XmlSchema IXmlSerializable.GetSchema ()
 		{
-			throw new NotImplementedException ();
+			return null;
 		}
 
 		void IXmlSerializable.ReadXml (XmlReader reader)

+ 11 - 0
mcs/class/System.ServiceModel.Web/System.ServiceModel.Syndication/ChangeLog

@@ -1,3 +1,14 @@
+2009-04-15  Atsushi Enomoto  <[email protected]>
+
+	* ServiceDocument.cs : remove Utility class. It is not precise
+	  implementation to write extensions.
+	* ServiceDocumentFormatter.cs : virtual extension writer methods
+	  should call possibly overriden Write[Element/Attribute]Extensions()
+	  in possibly derived document item classes.
+	  Implemented LoadElementExtensions().
+	* AtomPub10CategoriesDocumentFormatter.cs,
+	  AtomPub10ServiceDocumentFormatter.cs : Implemented GetSchema().
+
 2009-04-06  Atsushi Enomoto  <[email protected]>
 
 	* ServiceDocumentFormatter.cs

+ 0 - 15
mcs/class/System.ServiceModel.Web/System.ServiceModel.Syndication/ServiceDocument.cs

@@ -35,21 +35,6 @@ using System.Xml;
 
 namespace System.ServiceModel.Syndication
 {
-	internal class Utility
-	{
-		public static void WriteAttributeExtensions (Dictionary<XmlQualifiedName,string> attributes, XmlWriter writer, string version)
-		{
-			foreach (var p in attributes)
-				writer.WriteAttributeString (p.Key.Name, p.Key.Namespace, p.Value);
-		}
-
-		public static void WriteElementExtensions (SyndicationElementExtensionCollection elements, XmlWriter writer, string version)
-		{
-			foreach (var x in elements)
-				x.WriteTo (writer);
-		}
-	}
-
 	public class ServiceDocument
 	{
 		public static TServiceDocument Load<TServiceDocument> (XmlReader reader)

+ 24 - 32
mcs/class/System.ServiceModel.Web/System.ServiceModel.Syndication/ServiceDocumentFormatter.cs

@@ -63,116 +63,108 @@ namespace System.ServiceModel.Syndication
 			return document.CreateWorkspace ();
 		}
 
-		[MonoTODO]
+		[MonoTODO ("Use maxExtensionSize somewhere")]
 		protected static void LoadElementExtensions (XmlReader reader, CategoriesDocument categories, int maxExtensionSize)
 		{
-			throw new NotImplementedException ();
+			categories.ElementExtensions.Add (reader);
 		}
 
-		[MonoTODO]
+		[MonoTODO ("Use maxExtensionSize somewhere")]
 		protected static void LoadElementExtensions (XmlReader reader,ResourceCollectionInfo collection, int maxExtensionSize)
 		{
-			throw new NotImplementedException ();
+			collection.ElementExtensions.Add (reader);
 		}
 
-		[MonoTODO]
+		[MonoTODO ("Use maxExtensionSize somewhere")]
 		protected static void LoadElementExtensions (XmlReader reader, ServiceDocument document, int maxExtensionSize)
 		{
-			throw new NotImplementedException ();
+			document.ElementExtensions.Add (reader);
 		}
 
-		[MonoTODO]
+		[MonoTODO ("Use maxExtensionSize somewhere")]
 		protected static void LoadElementExtensions (XmlReader reader, Workspace workspace, int maxExtensionSize)
 		{
-			throw new NotImplementedException ();
+			workspace.ElementExtensions.Add (reader);
 		}
 
-		[MonoTODO]
 		protected static bool TryParseAttribute (string name, string ns, string value, CategoriesDocument categories, string version)
 		{
-			throw new NotImplementedException ();
+			return categories.TryParseAttribute (name, ns, value, version);
 		}
 
-		[MonoTODO]
 		protected static bool TryParseAttribute (string name, string ns, string value, ResourceCollectionInfo collection, string version)
 		{
-			throw new NotImplementedException ();
+			return collection.TryParseAttribute (name, ns, value, version);
 		}
 
-		[MonoTODO]
 		protected static bool TryParseAttribute (string name, string ns, string value, ServiceDocument document, string version)
 		{
-			throw new NotImplementedException ();
+			return document.TryParseAttribute (name, ns, value, version);
 		}
 
-		[MonoTODO]
 		protected static bool TryParseAttribute (string name, string ns, string value, Workspace workspace, string version)
 		{
-			throw new NotImplementedException ();
+			return workspace.TryParseAttribute (name, ns, value, version);
 		}
 
-		[MonoTODO]
 		protected static bool TryParseElement (XmlReader reader, CategoriesDocument categories, string version)
 		{
-			throw new NotImplementedException ();
+			return categories.TryParseElement (reader, version);
 		}
 
-		[MonoTODO]
 		protected static bool TryParseElement (XmlReader reader, ResourceCollectionInfo collection, string version)
 		{
-			throw new NotImplementedException ();
+			return collection.TryParseElement (reader, version);
 		}
 
-		[MonoTODO]
 		protected static bool TryParseElement (XmlReader reader, ServiceDocument document, string version)
 		{
-			throw new NotImplementedException ();
+			return document.TryParseElement (reader, version);
 		}
 
-		[MonoTODO]
 		protected static bool TryParseElement (XmlReader reader, Workspace workspace, string version)
 		{
-			throw new NotImplementedException ();
+			return workspace.TryParseElement (reader, version);
 		}
 
 		protected static void WriteAttributeExtensions (XmlWriter writer, CategoriesDocument categories, string version)
 		{
-			Utility.WriteAttributeExtensions (categories.AttributeExtensions, writer, version);
+			categories.WriteAttributeExtensions (writer, version);
 		}
 
 		protected static void WriteAttributeExtensions (XmlWriter writer, ResourceCollectionInfo collection, string version)
 		{
-			Utility.WriteAttributeExtensions (collection.AttributeExtensions, writer, version);
+			collection.WriteAttributeExtensions (writer, version);
 		}
 
 		protected static void WriteAttributeExtensions (XmlWriter writer, ServiceDocument document, string version)
 		{
-			Utility.WriteAttributeExtensions (document.AttributeExtensions, writer, version);
+			document.WriteAttributeExtensions (writer, version);
 		}
 
 		protected static void WriteAttributeExtensions (XmlWriter writer, Workspace workspace, string version)
 		{
-			Utility.WriteAttributeExtensions (workspace.AttributeExtensions, writer, version);
+			workspace.WriteAttributeExtensions (writer, version);
 		}
 
 		protected static void WriteElementExtensions (XmlWriter writer, CategoriesDocument categories, string version)
 		{
-			Utility.WriteElementExtensions (categories.ElementExtensions, writer, version);
+			categories.WriteElementExtensions (writer, version);
 		}
 
 		protected static void WriteElementExtensions (XmlWriter writer, ResourceCollectionInfo collection, string version)
 		{
-			Utility.WriteElementExtensions (collection.ElementExtensions, writer, version);
+			collection.WriteElementExtensions (writer, version);
 		}
 
 		protected static void WriteElementExtensions (XmlWriter writer, ServiceDocument document, string version)
 		{
-			Utility.WriteElementExtensions (document.ElementExtensions, writer, version);
+			document.WriteElementExtensions (writer, version);
 		}
 
 		protected static void WriteElementExtensions (XmlWriter writer, Workspace workspace, string version)
 		{
-			Utility.WriteElementExtensions (workspace.ElementExtensions, writer, version);
+			workspace.WriteElementExtensions (writer, version);
 		}
 
 		// instance members

+ 8 - 0
mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/AtomPub10CategoriesDocumentFormatterTest.cs

@@ -32,6 +32,7 @@ using System.IO;
 using System.Runtime.Serialization;
 using System.Text;
 using System.Xml;
+using System.Xml.Serialization;
 using System.ServiceModel.Syndication;
 using NUnit.Framework;
 
@@ -115,5 +116,12 @@ namespace MonoTests.System.ServiceModel.Syndication
 			Assert.IsNull (inline.Scheme, "#2");
 			Assert.AreEqual (1, inline.Categories.Count, "#3");
 		}
+
+		[Test]
+		public void GetSchema ()
+		{
+			IXmlSerializable i = new AtomPub10CategoriesDocumentFormatter ();
+			Assert.IsNull (i.GetSchema ());
+		}
 	}
 }

+ 30 - 0
mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/AtomPub10ServiceDocumentFormatterTest.cs

@@ -32,6 +32,7 @@ using System.IO;
 using System.Runtime.Serialization;
 using System.Text;
 using System.Xml;
+using System.Xml.Serialization;
 using System.ServiceModel.Syndication;
 using NUnit.Framework;
 
@@ -45,6 +46,20 @@ namespace MonoTests.System.ServiceModel.Syndication
 		{
 			ReadFrom (reader);
 		}
+
+		public void CallWriteDocument ()
+		{
+			var w = XmlWriter.Create (TextWriter.Null);
+			ServiceDocumentFormatter.WriteElementExtensions (w, new MyDocument (), "http://www.w3.org/2007/app");
+		}
+	}
+
+	class MyDocument : ServiceDocument
+	{
+		protected override void WriteElementExtensions (XmlWriter writer, string version)
+		{
+			throw new ApplicationException ();
+		}
 	}
 
 	[TestFixture]
@@ -105,5 +120,20 @@ namespace MonoTests.System.ServiceModel.Syndication
 		{
 			new MyServiceFormatter ().Read (XmlReader.Create (new StringReader (app2)));
 		}
+
+		[Test]
+		public void GetSchema ()
+		{
+			IXmlSerializable i = new AtomPub10ServiceDocumentFormatter ();
+			Assert.IsNull (i.GetSchema ());
+		}
+
+		[Test]
+		[ExpectedException (typeof (ApplicationException))]
+		public void WriteElementExtensions ()
+		{
+			// this test is to verify that the overriden WriteElementExtensions() is called in the staic ServiceDocumentFormatter method.
+			new MyServiceFormatter ().CallWriteDocument ();
+		}
 	}
 }

+ 6 - 0
mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/ChangeLog

@@ -1,3 +1,9 @@
+2009-04-15  Atsushi Enomoto  <[email protected]>
+
+	* AtomPub10CategoriesDocumentFormatterTest.cs,
+	  AtomPub10ServiceDocumentFormatterTest.cs : aded GetSchema() and
+	  WriteElementExtensions() tests.
+
 2009-04-06  Atsushi Enomoto  <[email protected]>
 
 	* AtomPub10ServiceDocumentFormatterTest.cs : add ReadFrom() test.