Skip to content

Commit d1fdeb2

Browse files
author
dotnetgeek
committed
merge master to development
2 parents 22f687e + 2eb9179 commit d1fdeb2

File tree

10 files changed

+236
-48
lines changed

10 files changed

+236
-48
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
[![Build status](https://ci.appveyor.com/api/projects/status/q31a2qtgi4bw3e9b/branch/develop?svg=true)](https://ci.appveyor.com/project/dotnetgeek/dng-syndication-cq83f/branch/develop)
1+
[![Build status](https://ci.appveyor.com/api/projects/status/q31a2qtgi4bw3e9b/branch/develop?svg=true)](https://ci.appveyor.com/project/dotnetgeek/dng-syndication/branch/develop)
22
[![Build status](https://ci.appveyor.com/api/projects/status/80gqbde41fru5wlb/branch/master?svg=true)](https://ci.appveyor.com/project/dotnetgeek/dng-syndication/branch/master)
33
[![NuGet](https://img.shields.io/nuget/v/dng.Syndication.svg)](https://www.nuget.org/packages/dng.Syndication)
44
![MIT License](https://img.shields.io/badge/license-MIT-orange.svg)
55

66
# dng.Syndication
77

8-
A simple feed generator which can be used to create valid RSS 2.0 and Atom feeds. It is written in C# and available as NuGet-Package.
9-
10-
11-
# How to use
8+
A feed generator which can be used to create valid RSS 2.0 ([spec](http://cyber.harvard.edu/rss/rss.html)) and Atom([spec](https://tools.ietf.org/html/rfc4287)) syndication feeds. It is written in C# and available as NuGet-Package.
129

10+
### Supports:
11+
* .NET Standard 2.0
12+
* .NET 4.5.x
1313

1414
# Objects and Fields description
1515

@@ -30,6 +30,8 @@ This is the main object which description the general information about the feed
3030
| UpdatedDate | lastBuildDate | updated | Defines the last-modified date of the content of the feed. |
3131
| Generator | generator | generator | The program used to generate the feed |
3232
| Description | description (*) | subtitle | Describes the feed |
33+
| Image | image | logo | Allows an image to be displayed when aggregators present a feed |
34+
| WebMaster | webMaster | - | Defines the e-mail address to the webmaster of the feed |
3335

3436

3537
* required
@@ -61,4 +63,4 @@ This is the main object which description the general information about the feed
6163
* Validate Atom-Feed
6264
* Implement 'image'
6365
* Code Samples and Demo Application
64-
* Validation of input parameter, required fields,...
66+
* Validation of input parameter, required fields,...

src/Feed.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,15 @@ public class Feed
5454
/// Describes the feed
5555
/// </summary>
5656
public string Description { get; set; }
57+
58+
/// <summary>
59+
/// Specifies a GIF, JPEG or PNG image that can be displayed with the channel
60+
/// </summary>
61+
public Image Image { get; set; }
62+
63+
/// <summary>
64+
/// Defines the e-mail address to the webmaster of the feed
65+
/// </summary>
66+
public string WebMaster {get; set; }
5767
}
5868
}

src/FeedEntry.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class FeedEntry
1414
/// </summary>
1515
public Uri Link { get; set; }
1616

17-
1817
public string Summary { get; set; }
1918

2019
/// <summary>

src/Generators/AtomGenerator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public string Process()
5959
if (Feed.PublishedDate != DateTime.MinValue)
6060
root.Add(new XElement(ns + "published", Feed.PublishedDate.ToString(DateTimeRfc3339Format)));
6161

62+
if (Feed.Image != null)
63+
root.Add(new XElement(ns + "logo", Feed.Image.Url));
64+
6265
foreach (var feedEntry in Feed.FeedEntries)
6366
{
6467
var itemElement = new XElement(ns + "entry");

src/Generators/Rss20Generator.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,28 @@ public string Process()
5757

5858
if (Feed.UpdatedDate != DateTime.MinValue)
5959
channel.Add(new XElement("lastBuildDate", FormatDate(Feed.UpdatedDate)));
60+
61+
if (!string.IsNullOrWhiteSpace(Feed.WebMaster))
62+
channel.Add(new XElement("webMaster", Feed.WebMaster));
63+
64+
if (Feed.Image != null)
65+
{
66+
var imageNode = new XElement("image");
67+
imageNode.Add(new XElement("url", Feed.Image.Url));
68+
imageNode.Add(new XElement("title", Feed.Image.Title));
69+
imageNode.Add(new XElement("link", Feed.Image.Link));
70+
71+
if (!string.IsNullOrWhiteSpace(Feed.Image.Description))
72+
imageNode.Add(new XElement("description", Feed.Image.Description));
73+
74+
if (Feed.Image.Height.HasValue)
75+
imageNode.Add(new XElement("height", Feed.Image.Height));
76+
77+
if (Feed.Image.Width.HasValue)
78+
imageNode.Add(new XElement("width", Feed.Image.Width));
79+
80+
channel.Add(imageNode);
81+
}
6082

6183
doc.Root.Add(channel);
6284

src/Image.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace dng.Syndication
8+
{
9+
public class Image
10+
{
11+
12+
/// <summary>
13+
/// The image element allows an image to be displayed when aggregators present a feed.
14+
/// </summary>
15+
/// <param name="url">Specifies the URL to the image</param>
16+
/// <param name="title">Defines the text to display if the image could not be shown</param>
17+
/// <param name="link">Defines the hyperlink to the website that offers the channel</param>
18+
public Image(
19+
Uri url,
20+
string title,
21+
Uri link)
22+
{
23+
if (url == null)
24+
throw new ArgumentException("Parameter Url is required.");
25+
26+
if (link == null)
27+
throw new ArgumentException("Parameter Link is required.");
28+
29+
if (string.IsNullOrWhiteSpace(title))
30+
throw new ArgumentException("Parameter Titel is required.");
31+
32+
Title = title;
33+
Link = link;
34+
Url = url;
35+
}
36+
37+
/// <summary>
38+
/// <para>Optional</para>
39+
/// <para>Specifies the text in the HTML title attribute of the link around the image</para>
40+
/// </summary>
41+
public string Description { get; set; }
42+
43+
/// <summary>
44+
/// <para>Optional</para>
45+
/// <para>Defines the height of the image. Default is 31. Maximum value is 400</para>
46+
/// </summary>
47+
public int? Height { get; set; }
48+
49+
/// <summary>
50+
/// <para>Required.</para>
51+
/// <para>Defines the hyperlink to the website that offers the channel</para>
52+
/// </summary>
53+
public Uri Link { get; private set; }
54+
55+
/// <summary>
56+
/// <para>Required.</para>
57+
/// <para>Defines the text to display if the image could not be shown</para>
58+
/// </summary>
59+
public string Title { get; private set; }
60+
61+
/// <summary>
62+
/// <para>Required.</para>
63+
/// <para>Specifies the URL to the image</para>
64+
/// </summary>
65+
public Uri Url { get; private set; }
66+
67+
/// <summary>
68+
/// <para>Optional.</para>
69+
/// <para>Defines the width of the image. Default is 88. Maximum value is 144</para>
70+
/// </summary>
71+
public int? Width { get; set; }
72+
}
73+
}

src/dng.Syndication.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
<PropertyGroup>
44
<TargetFrameworks>net452;netstandard2.0</TargetFrameworks>
55
<AssemblyName>dng.Syndication</AssemblyName>
6-
<Version>1.3.0</Version>
6+
<Version>1.4.1</Version>
77
<Authors>Daniel Mueller</Authors>
88
<Company />
9-
<PackageTags>RSS and Atom Feeds</PackageTags>
9+
<PackageTags>RSS Atom Feeds Syndication</PackageTags>
1010
<Copyright>2017</Copyright>
1111
<PackageLicenseUrl>https://github.com/dotnetgeek/dng.Syndication/blob/master/LICENSE</PackageLicenseUrl>
1212
<PackageProjectUrl></PackageProjectUrl>
13-
<Description>A simple feed generator which can be used to create valid RSS 2.0 and Atom feeds.</Description>
13+
<Description>A feed generator (for .NET Full Framework und .NET CORE) which can be used to create valid RSS 2.0 and Atom feeds.</Description>
1414
<RepositoryUrl>https://github.com/dotnetgeek/dng.Syndication</RepositoryUrl>
1515
</PropertyGroup>
1616

tests/AtomGeneratorTests.cs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,7 @@ namespace dng.Syndication.Tests
77
{
88
public class AtomGeneratorTests
99
{
10-
11-
private readonly string _feedXml;
12-
13-
public AtomGeneratorTests()
14-
{
15-
var atomGenerator = new AtomGenerator(CreateFeed());
16-
_feedXml = atomGenerator.Process();
17-
}
18-
19-
private Feed CreateFeed()
10+
private Feed CreateSimpleFeed()
2011
{
2112
var feed = new Feed
2213
{
@@ -51,8 +42,41 @@ private Feed CreateFeed()
5142
}
5243

5344
[Fact]
54-
public void CreatedFeedIsAsExpected()
45+
public void Create_a_simple_atom_feed()
5546
{
47+
var atomGenerator = new AtomGenerator(CreateSimpleFeed());
48+
var feedXml = atomGenerator.Process();
49+
50+
const string expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
51+
"<feed xmlns=\"http://www.w3.org/2005/Atom\">" +
52+
"<title type=\"text\">dotnetgeek feed</title>" +
53+
"<subtitle type=\"text\">Dotnet relevant thinks</subtitle>" +
54+
"<id>http://www.dotnetgeek.de/rss</id>" +
55+
"<link rel=\"self\" type=\"application/rss+xml\" href=\"http://www.dotnetgeek.de/rss\" />" +
56+
"<author><name>Daniel</name><email>[email protected]</email></author>" +
57+
"<rights>2016 @ www.dotnetgeek.com</rights>" +
58+
"<generator>dng.Syndication</generator>" +
59+
"<updated>2016-08-16T00:00:00Z</updated>" +
60+
"<entry><title>First Entry</title>" +
61+
"<link href=\"http://www.dotnetgeek.com/first-entry\" />" +
62+
"<summary>summary</summary><content>Content</content>" +
63+
"<author><name>Daniel</name><email>[email protected]</email></author>" +
64+
"<id>http://www.dotnetgeek.com/first-entry</id>" +
65+
"<updated>2016-08-16T00:00:00Z</updated>" +
66+
"<published>2016-08-16T00:00:00Z</published></entry></feed>";
67+
68+
Assert.Equal(expected, feedXml);
69+
}
70+
71+
[Fact]
72+
public void Create_a_simple_atom_feed_with_logo()
73+
{
74+
var feed = CreateSimpleFeed();
75+
feed.Image = new Image(new Uri("http://www.dotnetgeek.de/logo.png"), "dotnetgeek feed", new Uri("http://www.dotnetgeek.de"));
76+
77+
var atomGenerator = new AtomGenerator(feed);
78+
var feedXml = atomGenerator.Process();
79+
5680
const string expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
5781
"<feed xmlns=\"http://www.w3.org/2005/Atom\">" +
5882
"<title type=\"text\">dotnetgeek feed</title>" +
@@ -63,6 +87,7 @@ public void CreatedFeedIsAsExpected()
6387
"<rights>2016 @ www.dotnetgeek.com</rights>" +
6488
"<generator>dng.Syndication</generator>" +
6589
"<updated>2016-08-16T00:00:00Z</updated>" +
90+
"<logo>http://www.dotnetgeek.de/logo.png</logo>" +
6691
"<entry><title>First Entry</title>" +
6792
"<link href=\"http://www.dotnetgeek.com/first-entry\" />" +
6893
"<summary>summary</summary><content>Content</content>" +
@@ -71,7 +96,7 @@ public void CreatedFeedIsAsExpected()
7196
"<updated>2016-08-16T00:00:00Z</updated>" +
7297
"<published>2016-08-16T00:00:00Z</published></entry></feed>";
7398

74-
Assert.Equal(expected, _feedXml);
99+
Assert.Equal(expected, feedXml);
75100
}
76101
}
77102
}

tests/ImageTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using dng.Syndication.Generators;
4+
using Xunit;
5+
6+
namespace dng.Syndication.Tests
7+
{
8+
public class ImageTests
9+
{
10+
[Theory]
11+
[InlineData("http://www.dotnetgeek.de/icon.png","", "http://www.dotnetgeek.de", "Parameter Titel is required.")]
12+
[InlineData("","Title", "http://www.dotnetgeek.de", "Parameter Url is required.")]
13+
[InlineData("http://www.dotnetgeek.de/icon.png","Title", "", "Parameter Link is required.")]
14+
15+
public void Check_for_required_field_title(string url, string title,string link, string expectedMessage)
16+
{
17+
var exception = Assert.Throws<ArgumentException>(() => new Image(
18+
string.IsNullOrWhiteSpace(url) ? null : new Uri(url) ,
19+
title,
20+
string.IsNullOrWhiteSpace(link) ? null : new Uri(link) ));
21+
22+
Assert.Equal(expectedMessage, exception.Message);
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)