Skip to content

Commit

Permalink
Handle empty Hit'n'Run torrent list
Browse files Browse the repository at this point in the history
  • Loading branch information
PoLaKoSz committed Nov 16, 2020
1 parent 027c6f9 commit 9a3a0f8
Show file tree
Hide file tree
Showing 5 changed files with 377 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/PoLaKoSz.Ncore/Parsers/HitAndRunParser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AngleSharp;
using AngleSharp.Dom;
Expand Down Expand Up @@ -32,6 +33,11 @@ internal async Task<IEnumerable<HitAndRunTorrent>> ExtractResultsFromAsync(strin
throw new DeprecatedWrapperException("Couldn't find the Hit-And-Run torrent nodes!", container);
}

if (NoHitAndRun(torrentNodes))
{
return torrents;
}

DateTime currentTime = DateTime.Now;
foreach (IElement torrentNode in torrentNodes)
{
Expand All @@ -48,6 +54,12 @@ internal async Task<IEnumerable<HitAndRunTorrent>> ExtractResultsFromAsync(strin
return torrents;
}

private bool NoHitAndRun(IHtmlCollection<IElement> torrentNodes)
{
return torrentNodes.Count() == 1
&& torrentNodes.First().TextContent == "Az általad letöltött anyagokat a szabályoknak megfelelően visszaosztottad, a listád ennek köszönhetően üres.";
}

private HitAndRunTorrent ParseAsTorrent(IElement torrentNode, DateTime currentTime)
{
IElement nameNode = torrentNode.QuerySelector("div.hnr_tname a nobr");
Expand Down
4 changes: 2 additions & 2 deletions src/PoLaKoSz.Ncore/PoLaKoSz.Ncore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<PackageLicenseUrl>https://github.com/PoLaKoSz/nCore/LICENSE</PackageLicenseUrl>
<PackageId>PoLaKoSz.Ncore</PackageId>
<Product>nCore</Product>
<PackageReleaseNotes>First stable release. The enty point to the library is the PoLaKoSz.Ncore.NcoreClient class.</PackageReleaseNotes>
<PackageReleaseNotes>Handle empty Hit'n'Run list. The enty point to the library is the PoLaKoSz.Ncore.NcoreClient class.</PackageReleaseNotes>
<Description>nCore.cc is the largest hungarian torrent side. This .NET Core 2.1 library helps to access its content (Torrent details, user Hit'n'Runs, Search for Torrent).</Description>
<Version>1.0.1</Version>
<Version>1.1.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
10 changes: 10 additions & 0 deletions tests/Integration/EndPoints/HitAndRunEndPointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,15 @@ public async Task ListFirstTorrentRatioParsedCorrectly()

Assert.That(firstTorrent.Ratio, Is.EqualTo(0.013f));
}

[Test]
public async Task ListReturnsEmptyResultWhenNoHitAndRun()
{
SetServerResponse("no-torrent");

IEnumerable<HitAndRunTorrent> torrents = await endPoint.List();

Assert.That(torrents.Count(), Is.EqualTo(0));
}
}
}
3 changes: 3 additions & 0 deletions tests/Integration/Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<None Update="StaticResources\HitAndRunEndPoint\multiple-torrents.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="StaticResources\HitAndRunEndPoint\no-torrent.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="StaticResources\TorrentEndPoint\movie.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Loading

0 comments on commit 9a3a0f8

Please sign in to comment.