Author: atsushi
Date: 2007-12-15 15:16:02 -0500 (Sat, 15 Dec 2007)
New Revision: 91362

Added:
   
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/Rss20FeedFormatterTest.cs
Modified:
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/ChangeLog
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/Rss20FeedFormatter.cs
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/Rss20ItemFormatter.cs
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/SyndicationFeedFormatter.cs
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/SyndicationItemFormatter.cs
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web_test.dll.sources
   
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/ChangeLog
   
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/UrlSyndicationContentTest.cs
   
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/XmlSyndicationContentTest.cs
Log:
2007-12-15  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * Rss20ItemFormatter.cs : some parameter renaming.
        * SyndicationFeedFormatter.cs, Rss20FeedFormatter.cs : implemented,
          based on item formatter.
        * SyndicationItemFormatter.cs : implemented syndication element
          creation methods. Added null argument checks.

        * Rss20FeedFormatterTest.cs : new, mostly copied from item formatter.



Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/ChangeLog
 2007-12-15 20:01:25 UTC (rev 91361)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/ChangeLog
 2007-12-15 20:16:02 UTC (rev 91362)
@@ -1,5 +1,13 @@
 2007-12-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * Rss20ItemFormatter.cs : some parameter renaming.
+       * SyndicationFeedFormatter.cs, Rss20FeedFormatter.cs : implemented,
+         based on item formatter.
+       * SyndicationItemFormatter.cs : implemented syndication element
+         creation methods. Added null argument checks.
+
+2007-12-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * Rss20ItemFormatter.cs : write remaining properties in item.
        * UrlSyndicationContent.cs : implemented.
        * XmlSyndicationContent.cs, SyndicationContent.cs,

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/Rss20FeedFormatter.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/Rss20FeedFormatter.cs
     2007-12-15 20:01:25 UTC (rev 91361)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/Rss20FeedFormatter.cs
     2007-12-15 20:16:02 UTC (rev 91362)
@@ -28,6 +28,7 @@
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
+using System.Globalization;
 using System.IO;
 using System.Runtime.Serialization;
 using System.Text;
@@ -40,56 +41,55 @@
        [XmlRoot ("rss", Namespace = "")]
        public class Rss20FeedFormatter : SyndicationFeedFormatter, 
IXmlSerializable
        {
-               [MonoTODO]
+               const string AtomNamespace ="http://www.w3.org/2005/Atom";;
+
+               bool ext_atom_serialization, preserve_att_ext, 
preserve_elem_ext;
+               Type feed_type;
+
                public Rss20FeedFormatter ()
                {
-                       throw new NotImplementedException ();
+                       ext_atom_serialization = true;
                }
 
-               [MonoTODO]
                public Rss20FeedFormatter (SyndicationFeed feedToWrite)
+                       : this (feedToWrite, true)
                {
-                       throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public Rss20FeedFormatter (SyndicationFeed feedToWrite, bool 
serializeExtensionsAsAtom)
+                       : base (feedToWrite)
                {
-                       throw new NotImplementedException ();
+                       ext_atom_serialization = serializeExtensionsAsAtom;
                }
 
-               [MonoTODO]
                public Rss20FeedFormatter (Type feedTypeToCreate)
                {
-                       throw new NotImplementedException ();
+                       if (feedTypeToCreate == null)
+                               throw new ArgumentNullException 
("feedTypeToCreate");
+                       feed_type = feedTypeToCreate;
                }
 
-               [MonoTODO]
                public bool SerializeExtensionsAsAtom {
-                       get { throw new NotImplementedException (); }
-                       set { throw new NotImplementedException (); }
+                       get { return ext_atom_serialization; }
+                       set { ext_atom_serialization = value; }
                }
 
-               [MonoTODO]
                protected Type FeedType {
-                       get { throw new NotImplementedException (); }
+                       get { return feed_type; }
                }
 
-               [MonoTODO]
                public bool PreserveAttributeExtensions {
-                       get { throw new NotImplementedException (); }
-                       set { throw new NotImplementedException (); }
+                       get { return preserve_att_ext; }
+                       set { preserve_att_ext = value; }
                }
 
-               [MonoTODO]
                public bool PreserveElementExtensions {
-                       get { throw new NotImplementedException (); }
-                       set { throw new NotImplementedException (); }
+                       get { return preserve_elem_ext; }
+                       set { preserve_elem_ext = value; }
                }
 
-               [MonoTODO]
                public override string Version {
-                       get { throw new NotImplementedException (); }
+                       get { return "Rss20"; }
                }
 
                [MonoTODO]
@@ -98,10 +98,10 @@
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
+               [MonoTODO ("Find out what is expected here")]
                protected internal override void SetFeed (SyndicationFeed feed)
                {
-                       throw new NotImplementedException ();
+                       base.SetFeed (feed);
                }
 
                [MonoTODO]
@@ -128,22 +128,23 @@
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
+               [MonoTODO ("Find out how feedBaseUri is used")]
                protected virtual void WriteItem (XmlWriter writer, 
SyndicationItem item, Uri feedBaseUri)
                {
-                       throw new NotImplementedException ();
+                       item.SaveAsRss20 (writer);
                }
 
-               [MonoTODO]
                protected virtual void WriteItems (XmlWriter writer, 
IEnumerable<SyndicationItem> items, Uri feedBaseUri)
                {
-                       throw new NotImplementedException ();
+                       if (items == null)
+                               throw new ArgumentNullException ("items");
+                       foreach (SyndicationItem item in items)
+                               WriteItem (writer, item, feedBaseUri);
                }
 
-               [MonoTODO]
                public override void WriteTo (XmlWriter writer)
                {
-                       throw new NotImplementedException ();
+                       WriteXml (writer, true);
                }
 
                [MonoTODO]
@@ -152,10 +153,9 @@
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                void IXmlSerializable.WriteXml (XmlWriter writer)
                {
-                       throw new NotImplementedException ();
+                       WriteXml (writer, false);
                }
 
                [MonoTODO]
@@ -163,5 +163,123 @@
                {
                        throw new NotImplementedException ();
                }
+
+               void WriteXml (XmlWriter writer, bool writeRoot)
+               {
+                       if (writer == null)
+                               throw new ArgumentNullException ("writer");
+                       if (Feed == null)
+                               throw new InvalidOperationException 
("Syndication item must be set before writing");
+
+                       if (writeRoot)
+                               writer.WriteStartElement ("rss");
+
+                       if (SerializeExtensionsAsAtom)
+                               writer.WriteAttributeString ("xmlns", "a10", 
"http://www.w3.org/2000/xmlns/";, AtomNamespace);
+                       writer.WriteAttributeString ("version", "2.0");
+
+                       writer.WriteStartElement ("channel");
+
+                       if (Feed.BaseUri != null)
+                               writer.WriteAttributeString ("xml:base", 
Feed.BaseUri.ToString ());
+
+                       writer.WriteElementString ("title", String.Empty, 
Feed.Title != null ? Feed.Title.Text : String.Empty);
+
+                       writer.WriteElementString ("description", String.Empty, 
Feed.Description != null ? Feed.Description.Text : String.Empty);
+
+                       if (Feed.Copyright != null)
+                               writer.WriteElementString ("copyright", 
String.Empty, Feed.Copyright.Text);
+
+                       if (!Feed.LastUpdatedTime.Equals (default 
(DateTimeOffset))) {
+                               writer.WriteStartElement ("lastBuildDate");
+                               writer.WriteString (ToRFC822DateString 
(Feed.LastUpdatedTime));
+                               writer.WriteEndElement ();
+                       }
+
+                       if (Feed.Generator != null)
+                               writer.WriteElementString ("generator", 
String.Empty, Feed.Generator);
+                       if (Feed.ImageUrl != null) {
+                               writer.WriteStartElement ("image");
+                               writer.WriteElementString ("url", String.Empty, 
Feed.ImageUrl.ToString ());
+                               // FIXME: are they really empty?
+                               writer.WriteElementString ("title", 
String.Empty, String.Empty);
+                               writer.WriteElementString ("link", 
String.Empty, String.Empty);
+                               writer.WriteEndElement ();
+                       }
+                       if (Feed.Language != null)
+                               writer.WriteElementString ("language", 
String.Empty, Feed.Language);
+
+                       foreach (SyndicationPerson author in Feed.Authors)
+                               if (author != null) {
+                                       writer.WriteStartElement 
("managingEditor");
+                                       WriteAttributeExtensions (writer, 
author, Version);
+                                       writer.WriteString (author.Email);
+                                       WriteElementExtensions (writer, author, 
Version);
+                                       writer.WriteEndElement ();
+                               }
+                       foreach (SyndicationCategory category in 
Feed.Categories)
+                               if (category != null) {
+                                       writer.WriteStartElement ("category");
+                                       if (category.Scheme != null)
+                                               writer.WriteAttributeString 
("domain", category.Scheme);
+                                       WriteAttributeExtensions (writer, 
category, Version);
+                                       writer.WriteString (category.Name);
+                                       WriteElementExtensions (writer, 
category, Version);
+                                       writer.WriteEndElement ();
+                               }
+
+                       foreach (SyndicationLink link in Feed.Links)
+                               if (link != null) {
+                                       writer.WriteStartElement ("link");
+                                       WriteAttributeExtensions (writer, link, 
Version);
+                                       writer.WriteString (link.Uri != null ? 
link.Uri.ToString () : String.Empty);
+                                       WriteElementExtensions (writer, link, 
Version);
+                                       writer.WriteEndElement ();
+                               }
+
+                       WriteItems (writer, Feed.Items, Feed.BaseUri);
+
+                       if (SerializeExtensionsAsAtom) {
+
+                               if (Feed.Id != null) {
+                                       writer.WriteStartElement ("a10", "id", 
AtomNamespace);
+                                       writer.WriteString (Feed.Id);
+                                       writer.WriteEndElement ();
+                               }
+
+                               foreach (SyndicationPerson contributor in 
Feed.Contributors) {
+                                       if (contributor != null) {
+                                               writer.WriteStartElement 
("a10", "contributor", AtomNamespace);
+                                               WriteAttributeExtensions 
(writer, contributor, Version);
+                                               writer.WriteElementString 
("a10", "name", AtomNamespace, contributor.Name);
+                                               writer.WriteElementString 
("a10", "uri", AtomNamespace, contributor.Uri);
+                                               writer.WriteElementString 
("a10", "email", AtomNamespace, contributor.Email);
+                                               WriteElementExtensions (writer, 
contributor, Version);
+                                               writer.WriteEndElement ();
+                                       }
+                               }
+                       }
+
+                       writer.WriteEndElement (); // </channel>
+
+                       if (writeRoot)
+                               writer.WriteEndElement (); // </rss>
+               }
+
+               // FIXME: DateTimeOffset.ToString() needs another overload.
+               // When it is implemented, just remove ".DateTime" parts below.
+               string ToRFC822DateString (DateTimeOffset date)
+               {
+                       switch (date.DateTime.Kind) {
+                       case DateTimeKind.Utc:
+                               return date.DateTime.ToString ("ddd, dd MMM 
yyyy HH:mm:ss 'Z'", DateTimeFormatInfo.InvariantInfo);
+                       case DateTimeKind.Local:
+                               StringBuilder sb = new StringBuilder 
(date.DateTime.ToString ("ddd, dd MMM yyyy HH:mm:ss zzz", 
DateTimeFormatInfo.InvariantInfo));
+                               sb.Remove (sb.Length - 3, 1);
+                               return sb.ToString (); // remove ':' from +hh:mm
+                       default:
+                               return date.DateTime.ToString ("ddd, dd MMM 
yyyy HH:mm:ss", DateTimeFormatInfo.InvariantInfo);
+                       }
+               }
        }
 }

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/Rss20ItemFormatter.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/Rss20ItemFormatter.cs
     2007-12-15 20:01:25 UTC (rev 91361)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/Rss20ItemFormatter.cs
     2007-12-15 20:16:02 UTC (rev 91362)
@@ -51,13 +51,13 @@
                        ext_atom_serialization = true;
                }
 
-               public Rss20ItemFormatter (SyndicationItem feedToWrite)
-                       : this (feedToWrite, true)
+               public Rss20ItemFormatter (SyndicationItem itemToWrite)
+                       : this (itemToWrite, true)
                {
                }
 
-               public Rss20ItemFormatter (SyndicationItem feedToWrite, bool 
serializeExtensionsAsAtom)
-                       : base (feedToWrite)
+               public Rss20ItemFormatter (SyndicationItem itemToWrite, bool 
serializeExtensionsAsAtom)
+                       : base (itemToWrite)
                {
                        ext_atom_serialization = serializeExtensionsAsAtom;
                }

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/SyndicationFeedFormatter.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/SyndicationFeedFormatter.cs
       2007-12-15 20:01:25 UTC (rev 91361)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/SyndicationFeedFormatter.cs
       2007-12-15 20:16:02 UTC (rev 91362)
@@ -40,46 +40,53 @@
        {
                #region static members
 
-               [MonoTODO]
                protected internal static SyndicationCategory CreateCategory 
(SyndicationFeed feed)
                {
-                       throw new NotImplementedException ();
+                       if (feed == null)
+                               throw new ArgumentNullException ("feed");
+                       return feed.CreateCategory ();
                }
 
-               [MonoTODO]
                protected internal static SyndicationCategory CreateCategory 
(SyndicationItem item)
                {
-                       throw new NotImplementedException ();
+                       if (item == null)
+                               throw new ArgumentNullException ("item");
+                       return item.CreateCategory ();
                }
 
-               [MonoTODO]
                protected internal static SyndicationItem CreateItem 
(SyndicationFeed feed)
                {
-                       throw new NotImplementedException ();
+                       if (feed == null)
+                               throw new ArgumentNullException ("feed");
+                       return feed.CreateItem ();
                }
 
-               [MonoTODO]
                protected internal static SyndicationLink CreateLink 
(SyndicationFeed feed)
                {
-                       throw new NotImplementedException ();
+                       if (feed == null)
+                               throw new ArgumentNullException ("feed");
+                       return feed.CreateLink ();
                }
 
-               [MonoTODO]
                protected internal static SyndicationLink CreateLink 
(SyndicationItem item)
                {
-                       throw new NotImplementedException ();
+                       if (item == null)
+                               throw new ArgumentNullException ("item");
+                       return item.CreateLink ();
                }
 
-               [MonoTODO]
                protected internal static SyndicationPerson CreatePerson 
(SyndicationFeed feed)
                {
-                       throw new NotImplementedException ();
+                       if (feed == null)
+                               throw new ArgumentNullException ("feed");
+                       return feed.CreatePerson ();
                }
 
-               [MonoTODO]
                protected internal static SyndicationPerson CreatePerson 
(SyndicationItem item)
                {
-                       throw new NotImplementedException ();
+                       if (item == null)
+                               throw new ArgumentNullException ("item");
+                       return item.CreatePerson ();
                }
 
                [MonoTODO]
@@ -112,170 +119,189 @@
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                protected internal static bool TryParseAttribute (string name, 
string ns, string value, SyndicationCategory category, string version)
                {
-                       throw new NotImplementedException ();
+                       if (category == null)
+                               throw new ArgumentNullException ("category");
+                       return category.TryParseAttribute (name, ns, value, 
version);
                }
 
-               [MonoTODO]
                protected internal static bool TryParseAttribute (string name, 
string ns, string value, SyndicationFeed feed, string version)
                {
-                       throw new NotImplementedException ();
+                       if (feed == null)
+                               throw new ArgumentNullException ("feed");
+                       return feed.TryParseAttribute (name, ns, value, 
version);
                }
 
-               [MonoTODO]
                protected internal static bool TryParseAttribute (string name, 
string ns, string value, SyndicationItem item, string version)
                {
-                       throw new NotImplementedException ();
+                       if (item == null)
+                               throw new ArgumentNullException ("item");
+                       return item.TryParseAttribute (name, ns, value, 
version);
                }
 
-               [MonoTODO]
                protected internal static bool TryParseAttribute (string name, 
string ns, string value, SyndicationLink link, string version)
                {
-                       throw new NotImplementedException ();
+                       if (link == null)
+                               throw new ArgumentNullException ("link");
+                       return link.TryParseAttribute (name, ns, value, 
version);
                }
 
-               [MonoTODO]
                protected internal static bool TryParseAttribute (string name, 
string ns, string value, SyndicationPerson person, string version)
                {
-                       throw new NotImplementedException ();
+                       if (person == null)
+                               throw new ArgumentNullException ("person");
+                       return person.TryParseAttribute (name, ns, value, 
version);
                }
 
-               [MonoTODO]
                protected internal static bool TryParseContent (XmlReader 
reader, SyndicationItem item, string contentType, string version, out 
SyndicationContent content)
                {
-                       throw new NotImplementedException ();
+                       if (item == null)
+                               throw new ArgumentNullException ("item");
+                       return item.TryParseContent (reader, contentType, 
version, out content);
                }
 
-               [MonoTODO]
                protected internal static bool TryParseElement (XmlReader 
reader, SyndicationCategory category, string version)
                {
-                       throw new NotImplementedException ();
+                       if (category == null)
+                               throw new ArgumentNullException ("category");
+                       return category.TryParseElement (reader, version);
                }
 
-               [MonoTODO]
                protected internal static bool TryParseElement (XmlReader 
reader, SyndicationFeed feed, string version)
                {
-                       throw new NotImplementedException ();
+                       if (feed == null)
+                               throw new ArgumentNullException ("feed");
+                       return feed.TryParseElement (reader, version);
                }
 
-               [MonoTODO]
                protected internal static bool TryParseElement (XmlReader 
reader, SyndicationItem item, string version)
                {
-                       throw new NotImplementedException ();
+                       if (item == null)
+                               throw new ArgumentNullException ("item");
+                       return item.TryParseElement (reader, version);
                }
 
-               [MonoTODO]
                protected internal static bool TryParseElement (XmlReader 
reader, SyndicationLink link, string version)
                {
-                       throw new NotImplementedException ();
+                       if (link == null)
+                               throw new ArgumentNullException ("link");
+                       return link.TryParseElement (reader, version);
                }
 
-               [MonoTODO]
                protected internal static bool TryParseElement (XmlReader 
reader, SyndicationPerson person, string version)
                {
-                       throw new NotImplementedException ();
+                       if (person == null)
+                               throw new ArgumentNullException ("person");
+                       return person.TryParseElement (reader, version);
                }
 
-               [MonoTODO]
                protected internal static void WriteAttributeExtensions 
(XmlWriter writer, SyndicationCategory category, string version)
                {
-                       throw new NotImplementedException ();
+                       if (category == null)
+                               throw new ArgumentNullException ("category");
+                       category.WriteAttributeExtensions (writer, version);
                }
 
-               [MonoTODO]
-               protected internal static void WriteAttributeExtensions 
(XmlWriter writer, SyndicationFeed feed, string version)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               [MonoTODO]
                protected internal static void WriteAttributeExtensions 
(XmlWriter writer, SyndicationItem item, string version)
                {
-                       throw new NotImplementedException ();
+                       if (item == null)
+                               throw new ArgumentNullException ("item");
+                       item.WriteAttributeExtensions (writer, version);
                }
 
-               [MonoTODO]
                protected internal static void WriteAttributeExtensions 
(XmlWriter writer, SyndicationLink link, string version)
                {
-                       throw new NotImplementedException ();
+                       if (link == null)
+                               throw new ArgumentNullException ("link");
+                       link.WriteAttributeExtensions (writer, version);
                }
 
-               [MonoTODO]
                protected internal static void WriteAttributeExtensions 
(XmlWriter writer, SyndicationPerson person, string version)
                {
-                       throw new NotImplementedException ();
+                       if (person == null)
+                               throw new ArgumentNullException ("person");
+                       person.WriteAttributeExtensions (writer, version);
                }
 
-               [MonoTODO]
                protected internal static void WriteElementExtensions 
(XmlWriter writer, SyndicationCategory category, string version)
                {
-                       throw new NotImplementedException ();
+                       if (category == null)
+                               throw new ArgumentNullException ("category");
+                       category.WriteElementExtensions (writer, version);
                }
 
-               [MonoTODO]
+               protected internal static void WriteAttributeExtensions 
(XmlWriter writer, SyndicationFeed feed, string version)
+               {
+                       if (feed == null)
+                               throw new ArgumentNullException ("feed");
+                       feed.WriteElementExtensions (writer, version);
+               }
+
                protected internal static void WriteElementExtensions 
(XmlWriter writer, SyndicationFeed feed, string version)
                {
-                       throw new NotImplementedException ();
+                       if (feed == null)
+                               throw new ArgumentNullException ("feed");
+                       feed.WriteElementExtensions (writer, version);
                }
 
-               [MonoTODO]
                protected internal static void WriteElementExtensions 
(XmlWriter writer, SyndicationItem item, string version)
                {
-                       throw new NotImplementedException ();
+                       if (item == null)
+                               throw new ArgumentNullException ("item");
+                       item.WriteElementExtensions (writer, version);
                }
 
-               [MonoTODO]
                protected internal static void WriteElementExtensions 
(XmlWriter writer, SyndicationLink link, string version)
                {
-                       throw new NotImplementedException ();
+                       if (link == null)
+                               throw new ArgumentNullException ("link");
+                       link.WriteElementExtensions (writer, version);
                }
 
-               [MonoTODO]
                protected internal static void WriteElementExtensions 
(XmlWriter writer, SyndicationPerson person, string version)
                {
-                       throw new NotImplementedException ();
+                       if (person == null)
+                               throw new ArgumentNullException ("person");
+                       person.WriteElementExtensions (writer, version);
                }
 
                #endregion
 
                #region instance members
 
-               [MonoTODO]
+               SyndicationFeed feed;
+
                protected SyndicationFeedFormatter ()
                {
-                       throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                protected SyndicationFeedFormatter (SyndicationFeed feedToWrite)
                {
-                       throw new NotImplementedException ();
+                       if (feedToWrite == null)
+                               throw new ArgumentNullException ("feedToWrite");
+                       SetFeed (feedToWrite);
                }
 
-               [MonoTODO]
                protected internal virtual void SetFeed (SyndicationFeed feed)
                {
-                       throw new NotImplementedException ();
+                       if (feed == null)
+                               throw new ArgumentNullException ("feed");
+                       this.feed = feed;
                }
 
-               [MonoTODO]
                public SyndicationFeed Feed { 
-                       get { throw new NotImplementedException (); }
+                       get { return feed; }
                }
 
-               [MonoTODO]
                public abstract string Version { get; }
 
-               [MonoTODO]
                protected abstract SyndicationFeed CreateFeedInstance ();
 
                public abstract bool CanRead (XmlReader reader);
 
                public abstract void ReadFrom (XmlReader reader);
 
-               [MonoTODO]
                public abstract void WriteTo (XmlWriter writer);
 
                [MonoTODO]

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/SyndicationItemFormatter.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/SyndicationItemFormatter.cs
       2007-12-15 20:01:25 UTC (rev 91361)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/SyndicationItemFormatter.cs
       2007-12-15 20:16:02 UTC (rev 91362)
@@ -40,22 +40,31 @@
        {
                #region static members
 
-               [MonoTODO]
+               // My assumption is that those static methods are defined to
+               // be used in the derived classes and to dispatch the actual
+               // processing to each syndication element. Considering that
+               // they can be overriden in each element, I assume that these
+               // methods depend on the elements, not in reverse order.
+
                protected internal static SyndicationCategory CreateCategory 
(SyndicationItem item)
                {
-                       throw new NotImplementedException ();
+                       if (item == null)
+                               throw new ArgumentNullException ("item");
+                       return item.CreateCategory ();
                }
 
-               [MonoTODO]
                protected internal static SyndicationLink CreateLink 
(SyndicationItem item)
                {
-                       throw new NotImplementedException ();
+                       if (item == null)
+                               throw new ArgumentNullException ("item");
+                       return item.CreateLink ();
                }
 
-               [MonoTODO]
                protected internal static SyndicationPerson CreatePerson 
(SyndicationItem item)
                {
-                       throw new NotImplementedException ();
+                       if (item == null)
+                               throw new ArgumentNullException ("item");
+                       return item.CreatePerson ();
                }
 
                [MonoTODO]
@@ -82,94 +91,122 @@
                        throw new NotImplementedException ();
                }
 
-               // My assumption is that those static methods are defined to
-               // be used in the derived classes and to dispatch the actual
-               // processing to each syndication element. Considering that
-               // they can be overriden in each element, I assume that these
-               // methods depend on the elements, not in reverse order.
-
                protected internal static bool TryParseAttribute (string name, 
string ns, string value, SyndicationCategory category, string version)
                {
+                       if (category == null)
+                               throw new ArgumentNullException ("category");
                        return category.TryParseAttribute (name, ns, value, 
version);
                }
 
                protected internal static bool TryParseAttribute (string name, 
string ns, string value, SyndicationItem item, string version)
                {
+                       if (item == null)
+                               throw new ArgumentNullException ("item");
                        return item.TryParseAttribute (name, ns, value, 
version);
                }
 
                protected internal static bool TryParseAttribute (string name, 
string ns, string value, SyndicationLink link, string version)
                {
+                       if (link == null)
+                               throw new ArgumentNullException ("link");
                        return link.TryParseAttribute (name, ns, value, 
version);
                }
 
                protected internal static bool TryParseAttribute (string name, 
string ns, string value, SyndicationPerson person, string version)
                {
+                       if (person == null)
+                               throw new ArgumentNullException ("person");
                        return person.TryParseAttribute (name, ns, value, 
version);
                }
 
                protected internal static bool TryParseContent (XmlReader 
reader, SyndicationItem item, string contentType, string version, out 
SyndicationContent content)
                {
+                       if (item == null)
+                               throw new ArgumentNullException ("item");
                        return item.TryParseContent (reader, contentType, 
version, out content);
                }
 
                protected internal static bool TryParseElement (XmlReader 
reader, SyndicationCategory category, string version)
                {
+                       if (category == null)
+                               throw new ArgumentNullException ("category");
                        return category.TryParseElement (reader, version);
                }
 
                protected internal static bool TryParseElement (XmlReader 
reader, SyndicationItem item, string version)
                {
+                       if (item == null)
+                               throw new ArgumentNullException ("item");
                        return item.TryParseElement (reader, version);
                }
 
                protected internal static bool TryParseElement (XmlReader 
reader, SyndicationLink link, string version)
                {
+                       if (link == null)
+                               throw new ArgumentNullException ("link");
                        return link.TryParseElement (reader, version);
                }
 
                protected internal static bool TryParseElement (XmlReader 
reader, SyndicationPerson person, string version)
                {
+                       if (person == null)
+                               throw new ArgumentNullException ("person");
                        return person.TryParseElement (reader, version);
                }
 
                protected internal static void WriteAttributeExtensions 
(XmlWriter writer, SyndicationCategory category, string version)
                {
+                       if (category == null)
+                               throw new ArgumentNullException ("category");
                        category.WriteAttributeExtensions (writer, version);
                }
 
                protected internal static void WriteAttributeExtensions 
(XmlWriter writer, SyndicationItem item, string version)
                {
+                       if (item == null)
+                               throw new ArgumentNullException ("item");
                        item.WriteAttributeExtensions (writer, version);
                }
 
                protected internal static void WriteAttributeExtensions 
(XmlWriter writer, SyndicationLink link, string version)
                {
+                       if (link == null)
+                               throw new ArgumentNullException ("link");
                        link.WriteAttributeExtensions (writer, version);
                }
 
                protected internal static void WriteAttributeExtensions 
(XmlWriter writer, SyndicationPerson person, string version)
                {
+                       if (person == null)
+                               throw new ArgumentNullException ("person");
                        person.WriteAttributeExtensions (writer, version);
                }
 
                protected internal void WriteElementExtensions (XmlWriter 
writer, SyndicationCategory category, string version)
                {
+                       if (category == null)
+                               throw new ArgumentNullException ("category");
                        category.WriteElementExtensions (writer, version);
                }
 
                protected internal static void WriteElementExtensions 
(XmlWriter writer, SyndicationItem item, string version)
                {
+                       if (item == null)
+                               throw new ArgumentNullException ("item");
                        item.WriteElementExtensions (writer, version);
                }
 
                protected internal void WriteElementExtensions (XmlWriter 
writer, SyndicationLink link, string version)
                {
+                       if (link == null)
+                               throw new ArgumentNullException ("link");
                        link.WriteElementExtensions (writer, version);
                }
 
                protected internal void WriteElementExtensions (XmlWriter 
writer, SyndicationPerson person, string version)
                {
+                       if (person == null)
+                               throw new ArgumentNullException ("person");
                        person.WriteElementExtensions (writer, version);
                }
 
@@ -190,7 +227,6 @@
                        SetItem (itemToWrite);
                }
 
-               [MonoTODO]
                protected internal virtual void SetItem (SyndicationItem item)
                {
                        if (item == null)

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web_test.dll.sources
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web_test.dll.sources
  2007-12-15 20:01:25 UTC (rev 91361)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web_test.dll.sources
  2007-12-15 20:16:02 UTC (rev 91362)
@@ -2,6 +2,7 @@
 System.Runtime.Serialization.Json/JsonReaderTest.cs
 System.Runtime.Serialization.Json/JsonWriterTest.cs
 System.ServiceModel.Syndication/Atom10ItemFormatterTest.cs
+System.ServiceModel.Syndication/Rss20FeedFormatterTest.cs
 System.ServiceModel.Syndication/Rss20ItemFormatterTest.cs
 System.ServiceModel.Syndication/SyndicationElementExtensionTest.cs
 System.ServiceModel.Syndication/SyndicationFeedTest.cs

Modified: 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/ChangeLog
    2007-12-15 20:01:25 UTC (rev 91361)
+++ 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/ChangeLog
    2007-12-15 20:16:02 UTC (rev 91362)
@@ -1,5 +1,9 @@
 2007-12-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * Rss20FeedFormatterTest.cs : new, mostly copied from item formatter.
+
+2007-12-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * Rss20ItemFormatterTest.cs : added test for writing properties.
        * XmlSyndicationContentTest.cs, UrlSyndicationContentTest.cs : new.
 

Added: 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/Rss20FeedFormatterTest.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/Rss20FeedFormatterTest.cs
    2007-12-15 20:01:25 UTC (rev 91361)
+++ 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/Rss20FeedFormatterTest.cs
    2007-12-15 20:16:02 UTC (rev 91362)
@@ -0,0 +1,188 @@
+//
+// Rss20FeedFormatterTest.cs
+//
+// Author:
+//     Atsushi Enomoto  <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 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;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.IO;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Xml;
+using System.Xml.Serialization;
+using System.ServiceModel.Syndication;
+using NUnit.Framework;
+
+using QName = System.Xml.XmlQualifiedName;
+
+namespace MonoTests.System.ServiceModel.Syndication
+{
+       [TestFixture]
+       public class Rss20FeedFormatterTest
+       {
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void ConstructorNullFeed ()
+               {
+                       new Rss20FeedFormatter ((SyndicationFeed) null);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void ConstructorNullType ()
+               {
+                       new Rss20FeedFormatter ((Type) null);
+               }
+
+               /*
+               [Test]
+               public void FeedType ()
+               {
+                       Rss20FeedFormatter f = new Rss20FeedFormatter ();
+                       Assert.IsNull (f.FeedType, "#1");
+                       f = new Rss20FeedFormatter (new SyndicationFeed ());
+                       Assert.IsNull (f.FeedType, "#2");
+               }
+               */
+
+               [Test]
+               public void Version ()
+               {
+                       Rss20FeedFormatter f = new Rss20FeedFormatter ();
+                       Assert.AreEqual ("Rss20", f.Version, "#1");
+               }
+
+               [Test]
+               public void SerializeExtensionsAsAtom ()
+               {
+                       Rss20FeedFormatter f = new Rss20FeedFormatter ();
+                       Assert.IsTrue (f.SerializeExtensionsAsAtom, "#1");
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void DefaultConstructorThenWriteXml ()
+               {
+                       StringWriter sw = new StringWriter ();
+                       using (XmlWriter w = CreateWriter (sw))
+                               new Rss20FeedFormatter ().WriteTo (w);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void WriteToNull ()
+               {
+                       SyndicationFeed item = new SyndicationFeed ();
+                       new Rss20FeedFormatter (item).WriteTo (null);
+               }
+
+               [Test]
+               public void WriteTo_EmptyFeed ()
+               {
+                       SyndicationFeed item = new SyndicationFeed ();
+                       StringWriter sw = new StringWriter ();
+                       using (XmlWriter w = CreateWriter (sw))
+                               new Rss20FeedFormatter (item).WriteTo (w);
+                       // either title or description must exist (RSS 2.0 spec)
+                       Assert.AreEqual ("<rss 
xmlns:a10=\"http://www.w3.org/2005/Atom\"; version=\"2.0\"><channel><title 
/><description /></channel></rss>", sw.ToString ());
+               }
+
+               [Test]
+               public void WriteTo_TitleOnlyFeed ()
+               {
+                       SyndicationFeed item = new SyndicationFeed ();
+                       item.Title = new TextSyndicationContent ("title text");
+                       StringWriter sw = new StringWriter ();
+                       using (XmlWriter w = CreateWriter (sw))
+                               new Rss20FeedFormatter (item).WriteTo (w);
+                       Assert.AreEqual ("<rss 
xmlns:a10=\"http://www.w3.org/2005/Atom\"; version=\"2.0\"><channel><title>title 
text</title><description /></channel></rss>", sw.ToString ());
+               }
+
+               [Test]
+               public void WriteTo_CategoryAuthorsContributors ()
+               {
+                       SyndicationFeed item = new SyndicationFeed ();
+                       item.Categories.Add (new SyndicationCategory ("myname", 
"myscheme", "mylabel"));
+                       item.Authors.Add (new SyndicationPerson ("[EMAIL 
PROTECTED]", "John Doe", "http://john.doe.name";));
+                       item.Contributors.Add (new SyndicationPerson ("[EMAIL 
PROTECTED]", "Jane Doe", "http://jane.doe.name";));
+                       StringWriter sw = new StringWriter ();
+                       using (XmlWriter w = CreateWriter (sw))
+                               new Rss20FeedFormatter (item).WriteTo (w);
+                       // contributors are serialized as Atom extension
+                       Assert.AreEqual ("<rss 
xmlns:a10=\"http://www.w3.org/2005/Atom\"; version=\"2.0\"><channel><title 
/><description /><managingEditor>[EMAIL PROTECTED]</managingEditor><category 
domain=\"myscheme\">myname</category><a10:contributor><a10:name>Jane 
Doe</a10:name><a10:uri>http://jane.doe.name</a10:uri><a10:email>[EMAIL 
PROTECTED]</a10:email></a10:contributor></channel></rss>", sw.ToString ());
+               }
+
+               [Test]
+               public void WriteTo ()
+               {
+                       SyndicationFeed item = new SyndicationFeed ();
+                       item.BaseUri = new Uri ("http://mono-project.com";);
+                       item.Copyright = new TextSyndicationContent ("No rights 
reserved");
+                       item.Generator = "mono test generator";
+                       item.Id = "urn:myid";
+                       item.ImageUrl = new Uri 
("http://mono-project.com/images/mono.png";);
+                       item.LastUpdatedTime = new DateTimeOffset 
(DateTime.SpecifyKind (new DateTime (2008, 1, 1), DateTimeKind.Utc));
+
+                       StringWriter sw = new StringWriter ();
+                       using (XmlWriter w = CreateWriter (sw))
+                               new Rss20FeedFormatter (item).WriteTo (w);
+                       Assert.AreEqual ("<rss 
xmlns:a10=\"http://www.w3.org/2005/Atom\"; version=\"2.0\"><channel 
xml:base=\"http://mono-project.com/\";><title /><description /><copyright>No 
rights reserved</copyright><lastBuildDate>Tue, 01 Jan 2008 00:00:00 
Z</lastBuildDate><generator>mono test 
generator</generator><image><url>http://mono-project.com/images/mono.png</url><title
 /><link /></image><a10:id>urn:myid</a10:id></channel></rss>", sw.ToString ());
+               }
+
+               [Test]
+               public void SerializeExtensionsAsAtomFalse ()
+               {
+                       SyndicationFeed item = new SyndicationFeed ();
+                       item.Contributors.Add (new SyndicationPerson ("[EMAIL 
PROTECTED]", "Jane Doe", "http://jane.doe.name";));
+                       StringWriter sw = new StringWriter ();
+                       using (XmlWriter w = CreateWriter (sw))
+                               new Rss20FeedFormatter (item, false).WriteTo 
(w);
+                       // skip contributors
+                       Assert.AreEqual ("<rss version=\"2.0\"><channel><title 
/><description /></channel></rss>", sw.ToString ());
+               }
+
+               [Test]
+               public void ISerializableWriteXml ()
+               {
+                       SyndicationFeed item = new SyndicationFeed ();
+                       item.Title = new TextSyndicationContent ("title text");
+                       StringWriter sw = new StringWriter ();
+                       using (XmlWriter w = CreateWriter (sw)) {
+                               w.WriteStartElement ("dummy");
+                               ((IXmlSerializable) new Rss20FeedFormatter 
(item)).WriteXml (w);
+                               w.WriteEndElement ();
+                       }
+                       Assert.AreEqual ("<dummy 
xmlns:a10=\"http://www.w3.org/2005/Atom\"; version=\"2.0\"><channel><title>title 
text</title><description /></channel></dummy>", sw.ToString ());
+               }
+
+               XmlWriter CreateWriter (StringWriter sw)
+               {
+                       XmlWriterSettings s = new XmlWriterSettings ();
+                       s.OmitXmlDeclaration = true;
+                       return XmlWriter.Create (sw, s);
+               }
+       }
+}


Property changes on: 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/Rss20FeedFormatterTest.cs
___________________________________________________________________
Name: svn:eol-style
   + native


Property changes on: 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/UrlSyndicationContentTest.cs
___________________________________________________________________
Name: svn:executable
   - *


Property changes on: 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/XmlSyndicationContentTest.cs
___________________________________________________________________
Name: svn:executable
   - *

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to