Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Rss/RssElementNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static class RssElementNames
public const string TextInput = "textInput";
public const string TimeToLive = "ttl";
public const string Title = "title";
public const string Updated = "updated";
public const string Url = "url";
public const string Version = "version";
}
Expand Down
7 changes: 7 additions & 0 deletions src/Rss/RssFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@ public virtual ISyndicationContent CreateContent(ISyndicationItem item)
content.AddField(new SyndicationContent(RssElementNames.PubDate, FormatValue(item.Published)));
}

//
// Updated
if (item.LastUpdated != DateTimeOffset.MinValue)
{
content.AddField(new SyndicationContent(RssElementNames.Updated, Atom.AtomConstants.Atom10Namespace, FormatValue(item.LastUpdated)));
}

return content;
}

Expand Down
11 changes: 10 additions & 1 deletion src/Rss/RssParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,16 @@ public virtual ISyndicationItem CreateItem(ISyndicationContent content)
var item = new SyndicationItem();

foreach (var field in content.Fields)
{
{
//
// Updated
if (field.Namespace == Atom.AtomConstants.Atom10Namespace
&& field.Name == RssElementNames.Updated
&& TryParseValue(field.Value, out DateTimeOffset updated))
{
item.LastUpdated = updated;
}

if (field.Namespace != RssConstants.Rss20Namespace)
{
continue;
Expand Down
5 changes: 5 additions & 0 deletions tests/RssReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public async Task ReadItemAsContent()

Assert.Equal("pubDate", fields[5].Name);
Assert.False(string.IsNullOrEmpty(fields[5].Value));

Assert.Equal("updated", fields[6].Name);
Assert.False(string.IsNullOrEmpty(fields[6].Value));
}
}
}
Expand Down Expand Up @@ -211,12 +214,14 @@ public static async Task TestReadFeedElements(XmlReader outerXmlReader)
Assert.True(item.Title == "Lorem ipsum 2017-07-06T20:25:00+00:00");
Assert.True(item.Description == "Exercitation sit dolore mollit et est eiusmod veniam aute officia veniam ipsum.");
Assert.True(item.Links.Count() == 3);
Assert.True(item.LastUpdated.ToString() == "12/6/2017 8:25:00 PM +00:00");
}
else if(items == 2)
{
Assert.True(item.Title == "Lorem ipsum 2017-07-06T20:24:00+00:00");
Assert.True(item.Description == "Do ipsum dolore veniam minim est cillum aliqua ea.");
Assert.True(item.Links.Count() == 3);
Assert.True(item.LastUpdated.ToString() == "12/6/2017 8:25:00 PM +00:00");
}

break;
Expand Down
7 changes: 4 additions & 3 deletions tests/RssWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,9 @@ public async Task Echo()
var sw = new StringWriterWithEncoding(Encoding.UTF8);

using (var xmlWriter = XmlWriter.Create(sw))
{
var writer = new RssFeedWriter(xmlWriter);
{
var attributes = new SyndicationAttribute[] { new SyndicationAttribute("xmlns:a10", "http://www.w3.org/2005/Atom") };
var writer = new RssFeedWriter(xmlWriter, attributes);

while (await reader.Read())
{
Expand Down Expand Up @@ -293,7 +294,7 @@ public async Task Echo()
}

res = sw.ToString();
Assert.True(res == "<?xml version=\"1.0\" encoding=\"utf-8\"?><rss version=\"2.0\"><channel><title asd=\"123\">Lorem ipsum feed for an interval of 1 minutes</title><description>This is a constantly updating lorem ipsum feed</description><link length=\"123\" type=\"testType\">http://example.com/</link><image><url>http://2.bp.blogspot.com/-NA5Jb-64eUg/URx8CSdcj_I/AAAAAAAAAUo/eCx0irI0rq0/s1600/bg_Microsoft_logo3-20120824073001907469-620x349.jpg</url><title>Microsoft News</title><link>http://www.microsoft.com/news</link><description>Test description</description></image><generator>RSS for Node</generator><lastBuildDate>Thu, 06 Jul 2017 20:25:17 GMT</lastBuildDate><managingEditor>John Smith</managingEditor><pubDate>Thu, 06 Jul 2017 20:25:00 GMT</pubDate><copyright>Michael Bertolacci, licensed under a Creative Commons Attribution 3.0 Unported License.</copyright><ttl>60</ttl><item><title>Lorem ipsum 2017-07-06T20:25:00+00:00</title><enclosure url=\"http://www.scripting.com/mp3s/weatherReportSuite.mp3\" length=\"12216320\" type=\"audio/mpeg\" /><link>http://example.com/test/1499372700</link><guid>http://example.com/test/1499372700</guid><description>Exercitation sit dolore mollit et est eiusmod veniam aute officia veniam ipsum.</description><author>John Smith</author><pubDate>Thu, 06 Jul 2017 20:25:00 GMT</pubDate></item><item><title>Lorem ipsum 2017-07-06T20:24:00+00:00</title><link>http://example.com/test/1499372640</link><guid>http://example.com/test/1499372640</guid><enclosure url=\"http://www.scripting.com/mp3s/weatherReportSuite.mp3\" length=\"12216320\" type=\"audio/mpeg\" /><description>Do ipsum dolore veniam minim est cillum aliqua ea.</description><author>John Smith</author><pubDate>Thu, 06 Jul 2017 20:24:00 GMT</pubDate></item></channel></rss>");
Assert.True(res == "<?xml version=\"1.0\" encoding=\"utf-8\"?><rss xmlns:a10=\"http://www.w3.org/2005/Atom\" version=\"2.0\"><channel><title asd=\"123\">Lorem ipsum feed for an interval of 1 minutes</title><description>This is a constantly updating lorem ipsum feed</description><link length=\"123\" type=\"testType\">http://example.com/</link><image><url>http://2.bp.blogspot.com/-NA5Jb-64eUg/URx8CSdcj_I/AAAAAAAAAUo/eCx0irI0rq0/s1600/bg_Microsoft_logo3-20120824073001907469-620x349.jpg</url><title>Microsoft News</title><link>http://www.microsoft.com/news</link><description>Test description</description></image><generator>RSS for Node</generator><lastBuildDate>Thu, 06 Jul 2017 20:25:17 GMT</lastBuildDate><managingEditor>John Smith</managingEditor><pubDate>Thu, 06 Jul 2017 20:25:00 GMT</pubDate><copyright>Michael Bertolacci, licensed under a Creative Commons Attribution 3.0 Unported License.</copyright><ttl>60</ttl><item><title>Lorem ipsum 2017-07-06T20:25:00+00:00</title><enclosure url=\"http://www.scripting.com/mp3s/weatherReportSuite.mp3\" length=\"12216320\" type=\"audio/mpeg\" /><link>http://example.com/test/1499372700</link><guid>http://example.com/test/1499372700</guid><description>Exercitation sit dolore mollit et est eiusmod veniam aute officia veniam ipsum.</description><author>John Smith</author><pubDate>Thu, 06 Jul 2017 20:25:00 GMT</pubDate><a10:updated>Wed, 06 Dec 2017 20:25:00 GMT</a10:updated></item><item><title>Lorem ipsum 2017-07-06T20:24:00+00:00</title><link>http://example.com/test/1499372640</link><guid>http://example.com/test/1499372640</guid><enclosure url=\"http://www.scripting.com/mp3s/weatherReportSuite.mp3\" length=\"12216320\" type=\"audio/mpeg\" /><description>Do ipsum dolore veniam minim est cillum aliqua ea.</description><author>John Smith</author><pubDate>Thu, 06 Jul 2017 20:24:00 GMT</pubDate><a10:updated>Wed, 06 Dec 2017 20:25:00 GMT</a10:updated></item></channel></rss>");
}

await RssReader.TestReadFeedElements(XmlReader.Create(new StringReader(res)));
Expand Down
4 changes: 3 additions & 1 deletion tests/TestFeeds/rss20-2items.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:example="http://contoso.com/syndication/feed/examples" version="2.0">
<rss xmlns:example="http://contoso.com/syndication/feed/examples" xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title asd="123"><![CDATA[Lorem ipsum feed for an interval of 1 minutes]]></title>
<description><![CDATA[This is a constantly updating lorem ipsum feed]]></description>
Expand All @@ -24,6 +24,7 @@
<guid isPermaLink="true">http://example.com/test/1499372700</guid>
<author><![CDATA[John Smith]]></author>
<pubDate>Thu, 06 Jul 2017 20:25:00 GMT</pubDate>
<a10:updated>Thu, 06 Dec 2017 20:25:00 GMT</a10:updated>
<example:customElement>Testing Custom Elements</example:customElement>
</item>
<item>
Expand All @@ -33,6 +34,7 @@
<guid isPermaLink="true">http://example.com/test/1499372640</guid>
<author><![CDATA[John Smith]]></author>
<pubDate>Thu, 06 Jul 2017 20:24:00 GMT</pubDate>
<a10:updated>Thu, 06 Dec 2017 20:25:00 GMT</a10:updated>
<enclosure url="http://www.scripting.com/mp3s/weatherReportSuite.mp3" length="12216320" type="audio/mpeg">Ignored Text</enclosure>
<example:customElement>Testing Custom Elements</example:customElement>
</item>
Expand Down
12 changes: 11 additions & 1 deletion tests/TestFeeds/rss20.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<author>abc@def.com (John Doe)</author>
<title asd="123"><![CDATA[Lorem ipsum feed for an interval of 1 minutes]]></title>
Expand All @@ -25,6 +25,7 @@
<guid isPermaLink="true">http://example.com/test/1499372700</guid>
<dc:creator><![CDATA[John Smith]]></dc:creator>
<pubDate>Thu, 06 Jul 2017 20:25:00 GMT</pubDate>
<a10:updated>Thu, 06 Dec 2017 20:25:00 GMT</a10:updated>
<category domain="http://example.com/news/item">Newspapers</category>
</item>
<item>
Expand All @@ -34,6 +35,7 @@
<guid isPermaLink="true">http://example.com/test/1499372640</guid>
<dc:creator><![CDATA[John Smith]]></dc:creator>
<pubDate>Thu, 06 Jul 2017 20:24:00 GMT</pubDate>
<a10:updated>Thu, 06 Dec 2017 20:25:00 GMT</a10:updated>
<category>Newspapers</category>
</item>
<item>
Expand All @@ -43,6 +45,7 @@
<guid isPermaLink="true">http://example.com/test/1499372580</guid>
<dc:creator><![CDATA[John Smith]]></dc:creator>
<pubDate>Thu, 06 Jul 2017 20:23:00 GMT</pubDate>
<a10:updated>Thu, 06 Dec 2017 20:25:00 GMT</a10:updated>
</item>
<item>
<title><![CDATA[Lorem ipsum 2017-07-06T20:22:00+00:00]]></title>
Expand All @@ -51,6 +54,7 @@
<guid isPermaLink="true">http://example.com/test/1499372520</guid>
<dc:creator><![CDATA[John Smith]]></dc:creator>
<pubDate>Thu, 06 Jul 2017 20:22:00 GMT</pubDate>
<a10:updated>Thu, 06 Dec 2017 20:25:00 GMT</a10:updated>
</item>
<item>
<title><![CDATA[Lorem ipsum 2017-07-06T20:21:00+00:00]]></title>
Expand All @@ -59,6 +63,7 @@
<guid isPermaLink="true">http://example.com/test/1499372460</guid>
<dc:creator><![CDATA[John Smith]]></dc:creator>
<pubDate>Thu, 06 Jul 2017 20:21:00 GMT</pubDate>
<a10:updated>Thu, 06 Dec 2017 20:25:00 GMT</a10:updated>
</item>
<item>
<title><![CDATA[Lorem ipsum 2017-07-06T20:20:00+00:00]]></title>
Expand All @@ -67,6 +72,7 @@
<guid isPermaLink="true">http://example.com/test/1499372400</guid>
<dc:creator><![CDATA[John Smith]]></dc:creator>
<pubDate>Thu, 06 Jul 2017 20:20:00 GMT</pubDate>
<a10:updated>Thu, 06 Dec 2017 20:25:00 GMT</a10:updated>
</item>
<item>
<title><![CDATA[Lorem ipsum 2017-07-06T20:19:00+00:00]]></title>
Expand All @@ -75,6 +81,7 @@
<guid isPermaLink="true">http://example.com/test/1499372340</guid>
<dc:creator><![CDATA[John Smith]]></dc:creator>
<pubDate>Thu, 06 Jul 2017 20:19:00 GMT</pubDate>
<a10:updated>Thu, 06 Dec 2017 20:25:00 GMT</a10:updated>
</item>
<item>
<title><![CDATA[Lorem ipsum 2017-07-06T20:18:00+00:00]]></title>
Expand All @@ -83,6 +90,7 @@
<guid isPermaLink="true">http://example.com/test/1499372280</guid>
<dc:creator><![CDATA[John Smith]]></dc:creator>
<pubDate>Thu, 06 Jul 2017 20:18:00 GMT</pubDate>
<a10:updated>Thu, 06 Dec 2017 20:25:00 GMT</a10:updated>
</item>
<item>
<title><![CDATA[Lorem ipsum 2017-07-06T20:17:00+00:00]]></title>
Expand All @@ -91,6 +99,7 @@
<guid isPermaLink="true">http://example.com/test/1499372220</guid>
<dc:creator><![CDATA[John Smith]]></dc:creator>
<pubDate>Thu, 06 Jul 2017 20:17:00 GMT</pubDate>
<a10:updated>Thu, 06 Dec 2017 20:25:00 GMT</a10:updated>
</item>
<item>
<title><![CDATA[Lorem ipsum 2017-07-06T20:16:00+00:00]]></title>
Expand All @@ -99,6 +108,7 @@
<guid isPermaLink="true">http://example.com/test/1499372160</guid>
<dc:creator><![CDATA[John Smith]]></dc:creator>
<pubDate>Thu, 06 Jul 2017 20:16:00 GMT</pubDate>
<a10:updated>Thu, 06 Dec 2017 20:25:00 GMT</a10:updated>
</item>
</channel>
</rss>