Explorar o código

2009-10-07 Atsushi Enomoto <[email protected]>

	* SyndicationVersions.cs :
	  Handle atom feed as well. Patch by David Mitchell.

	* SyndicationItemTest.cs, SyndicationFeedTest.cs : allow atom feed
	  too. More Load() tests. Patch by David Mitchell.


svn path=/trunk/mcs/; revision=143704
Atsushi Eno %!s(int64=16) %!d(string=hai) anos
pai
achega
fd2cd12aae

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

@@ -1,3 +1,8 @@
+2009-10-07  Atsushi Enomoto  <[email protected]>
+
+	* SyndicationVersions.cs :
+	  Handle atom feed as well. Patch by David Mitchell.
+
 2009-10-07  Atsushi Enomoto  <[email protected]>
 
 	* SyndicationElementExtension.cs : give OuterName and OuterNamespace

+ 11 - 4
mcs/class/System.ServiceModel.Web/System.ServiceModel.Syndication/SyndicationVersions.cs

@@ -37,12 +37,18 @@ namespace System.ServiceModel.Syndication
 {
 	public static class SyndicationVersions
 	{
+		private enum ReaderKind
+		{
+			Item,
+			Feed,
+		}
+
 		public const string Atom10 = "Atom10";
 		public const string Rss20 = "Rss20";
 
 		const string AtomNamespace ="http://www.w3.org/2005/Atom";
 
-		static string DetectVersion (XmlReader reader)
+		static string DetectVersion (XmlReader reader, ReaderKind kind)
 		{
 			if (reader == null)
 				throw new ArgumentNullException ("reader");
@@ -51,7 +57,8 @@ namespace System.ServiceModel.Syndication
 				throw new XmlException ("An element is expected for syndication item");
 			if (reader.IsStartElement ("rss", String.Empty) && reader.GetAttribute ("version") == "2.0")
 				return SyndicationVersions.Rss20;
-			if (reader.IsStartElement ("entry", AtomNamespace))
+			if ((kind == ReaderKind.Item && reader.IsStartElement ("entry", AtomNamespace)) ||
+			    (kind == ReaderKind.Feed && reader.IsStartElement("feed", AtomNamespace)))
 				return SyndicationVersions.Atom10;
 			else if (reader.IsStartElement ("item", String.Empty))
 				return SyndicationVersions.Rss20;
@@ -61,7 +68,7 @@ namespace System.ServiceModel.Syndication
 
 		internal static TSyndicationFeed LoadFeed<TSyndicationFeed> (XmlReader reader) where TSyndicationFeed : SyndicationFeed, new()
 		{
-			switch (DetectVersion (reader)) {
+			switch (DetectVersion (reader, ReaderKind.Feed)) {
 			case SyndicationVersions.Atom10:
 				Atom10FeedFormatter af = new Atom10FeedFormatter<TSyndicationFeed> ();
 				af.ReadFrom (reader);
@@ -76,7 +83,7 @@ namespace System.ServiceModel.Syndication
 
 		internal static TSyndicationItem LoadItem<TSyndicationItem> (XmlReader reader) where TSyndicationItem : SyndicationItem, new()
 		{
-			switch (DetectVersion (reader)) {
+			switch (DetectVersion (reader, ReaderKind.Item)) {
 			case SyndicationVersions.Atom10:
 				Atom10ItemFormatter af = new Atom10ItemFormatter<TSyndicationItem> ();
 				af.ReadFrom (reader);

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

@@ -1,3 +1,8 @@
+2009-10-07  Atsushi Enomoto  <[email protected]>
+
+	* SyndicationItemTest.cs, SyndicationFeedTest.cs : allow atom feed
+	  too. More Load() tests. Patch by David Mitchell.
+
 2009-10-07  Atsushi Enomoto  <[email protected]>
 
 	* SyndicationElementExtensionTest.cs : added test for OuterName/ns

+ 14 - 0
mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/SyndicationFeedTest.cs

@@ -86,5 +86,19 @@ namespace MonoTests.System.ServiceModel.Syndication
 			Assert.IsFalse (feed.Items.GetEnumerator ().MoveNext (), "#4"); // make sure we reset it
 			*/
 		}
+
+		[Test]
+		public void LoadFeed ()
+		{
+			SyndicationFeed.Load (XmlReader.Create (new StringReader ("<feed xmlns=\"http://www.w3.org/2005/Atom\"></feed>")));
+		}
+
+		[Test]
+		[ExpectedException (typeof (XmlException))]
+		public void LoadEntry ()
+		{
+			// entry is not allowed.
+			SyndicationFeed.Load (XmlReader.Create (new StringReader ("<entry xmlns=\"http://www.w3.org/2005/Atom\"></entry>")));
+		}
 	}
 }

+ 7 - 1
mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/SyndicationItemTest.cs

@@ -134,7 +134,13 @@ namespace MonoTests.System.ServiceModel.Syndication
 		public void LoadFeed ()
 		{
 			// feed is not allowed.
-			SyndicationItem.Load (XmlReader.Create (new StringReader ("<feed />")));
+			SyndicationItem.Load (XmlReader.Create (new StringReader ("<feed xmlns=\"http://www.w3.org/2005/Atom\"></feed>")));
+		}
+
+		[Test]
+		public void LoadEntry ()
+		{
+			SyndicationItem.Load (XmlReader.Create (new StringReader ("<entry xmlns=\"http://www.w3.org/2005/Atom\"></entry>")));
 		}
 	}
 }