diff --git a/ReadSharp.Tests/ReadTests.cs b/ReadSharp.Tests/ReadTests.cs index 2e6b366..93ea536 100644 --- a/ReadSharp.Tests/ReadTests.cs +++ b/ReadSharp.Tests/ReadTests.cs @@ -1,6 +1,8 @@ using System; using System.Threading.Tasks; using Xunit; +using System.Linq; +using System.Collections.Generic; namespace ReadSharp.Tests { @@ -9,8 +11,7 @@ namespace ReadSharp.Tests private Reader reader; - public ReadTests() - : base() + public ReadTests() : base() { reader = new Reader(); } @@ -44,9 +45,10 @@ namespace ReadSharp.Tests public async Task ReadArticleWithImagesTest() { Article result = await reader.Read(new Uri("https://hacks.mozilla.org/2013/12/application-layout-with-css3-flexible-box-module/")); - Assert.True(result.Images.Count >= 3); - Assert.True(result.Images[0].Uri.ToString().StartsWith("https://hacks.mozilla.org")); - Assert.True(result.Images[1].Uri.ToString().EndsWith(".gif")); + List images = result.Images.ToList(); + Assert.True(images.Count >= 3); + Assert.True(images[0].Uri.ToString().StartsWith("https://hacks.mozilla.org")); + Assert.True(images[1].Uri.ToString().EndsWith(".gif")); } @@ -54,7 +56,7 @@ namespace ReadSharp.Tests public async Task ReadArticleWithNoImagesTest() { Article result = await reader.Read(new Uri("http://getpocket.com/hits/awards/2013/")); - Assert.True(result.Images == null || result.Images.Count < 1); + Assert.True(result.Images == null || result.Images.Count() < 1); } @@ -195,7 +197,7 @@ namespace ReadSharp.Tests result = await reader.Read(new Uri("http://arstechnica.com/apple/2014/01/two-steps-forward-a-review-of-the-2013-mac-pro/"), options); Assert.Equal(result.PageCount, 7); - Assert.True(result.WordCount > 13000 && result.Images.Count > 10); + Assert.True(result.WordCount > 13000 && result.Images.Count() > 10); result = await reader.Read(new Uri("http://www.sueddeutsche.de/wirtschaft/netzbetreiber-und-die-energiewende-im-kampf-gegen-blackouts-und-buergerproteste-1.1880754"), options); Assert.Equal(result.PageCount, 2); @@ -217,10 +219,10 @@ namespace ReadSharp.Tests Assert.NotEmpty(result.Content); result = await reader.Read(new Uri("http://www.nytimes.com/2014/01/31/world/europe/ukraine-unrest.html?hp&_r=0")); - Assert.True(result.Images != null && result.Images.Count > 0); + Assert.True(result.Images != null && result.Images.Count() > 0); result = await reader.Read(new Uri("http://www.polygon.com/2013/2/25/4026668/tomb-raider-review")); - Assert.True(result.Images != null && result.Images.Count > 3 && result.Content.Contains("For a reboot of a series that had lost its focus and purpose")); + Assert.True(result.Images != null && result.Images.Count() > 3 && result.Content.Contains("For a reboot of a series that had lost its focus and purpose")); result = await reader.Read(new Uri("http://www.polygon.com/2014/1/31/5364728/super-bowl-xlviii-xbox-activities-new-york")); Assert.True(result.Content.Contains("week for Super Bowl XLVIII") && result.Content.Contains("two tickets to the Super Bowl.")); diff --git a/ReadSharp/Models/Article.cs b/ReadSharp/Models/Article.cs index 7597fe2..6895993 100644 --- a/ReadSharp/Models/Article.cs +++ b/ReadSharp/Models/Article.cs @@ -87,7 +87,7 @@ namespace ReadSharp /// /// The images. /// - public List Images { get; set; } + public IEnumerable Images { get; set; } /// /// Gets or sets the next page URL. diff --git a/ReadSharp/ReadSharp.csproj b/ReadSharp/ReadSharp.csproj index 831a3f5..afc7735 100644 --- a/ReadSharp/ReadSharp.csproj +++ b/ReadSharp/ReadSharp.csproj @@ -97,19 +97,19 @@ ..\packages\HtmlAgilityPack-PCL.1.4.6\lib\HtmlAgilityPack-PCL.dll - ..\packages\Microsoft.Bcl.Async.1.0.166\lib\portable-net40+sl4+win8+wp71+wpa81\Microsoft.Threading.Tasks.dll + ..\packages\Microsoft.Bcl.Async.1.0.168\lib\portable-net45+win8+wp8+wpa81\Microsoft.Threading.Tasks.dll - ..\packages\Microsoft.Bcl.Async.1.0.166\lib\portable-net40+sl4+win8+wp71+wpa81\Microsoft.Threading.Tasks.Extensions.dll + ..\packages\Microsoft.Bcl.Async.1.0.168\lib\portable-net45+win8+wp8+wpa81\Microsoft.Threading.Tasks.Extensions.dll - ..\packages\Microsoft.Net.Http.2.2.19\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.dll + ..\packages\Microsoft.Net.Http.2.2.22\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.dll - ..\packages\Microsoft.Net.Http.2.2.19\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.Extensions.dll + ..\packages\Microsoft.Net.Http.2.2.22\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.Extensions.dll - ..\packages\Microsoft.Net.Http.2.2.19\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.Primitives.dll + ..\packages\Microsoft.Net.Http.2.2.22\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.Primitives.dll diff --git a/ReadSharp/Reader.cs b/ReadSharp/Reader.cs index a8ded5c..65dffab 100644 --- a/ReadSharp/Reader.cs +++ b/ReadSharp/Reader.cs @@ -147,19 +147,23 @@ namespace ReadSharp // get images from article int id = 1; - List images = response.TranscodingResult.Images.Select(image => - { - Uri imageUri = null; - Uri.TryCreate(image.GetAttributeValue("src", null), UriKind.Absolute, out imageUri); - - return new ArticleImage() + IEnumerable images = response.TranscodingResult.Images + .Select(image => { - ID = (id++).ToString(), - Uri = imageUri, - Title = image.GetAttributeValue("title", null), - AlternativeText = image.GetAttributeValue("alt", null) - }; - }).GroupBy(image => image.Uri).Select(g => g.First()).Where(image => image.Uri != null).ToList(); + Uri imageUri = null; + Uri.TryCreate(image.GetAttributeValue("src", null), UriKind.Absolute, out imageUri); + + return new ArticleImage() + { + ID = (id++).ToString(), + Uri = imageUri, + Title = image.GetAttributeValue("title", null), + AlternativeText = image.GetAttributeValue("alt", null) + }; + }) + .GroupBy(image => image.Uri) + .Select(g => g.First()) + .Where(image => image.Uri != null); // get word count and plain text string plainContent; diff --git a/ReadSharp/packages.config b/ReadSharp/packages.config index 93929d4..5eb4830 100644 --- a/ReadSharp/packages.config +++ b/ReadSharp/packages.config @@ -1,8 +1,8 @@  - - + + - + \ No newline at end of file