This is why we write unit tests...

#ND-93 fixed - for real this time
Fixed: Option to have older episodes added to SABnzbd queue at a
different priority
pull/2/head
Mark McDowall 12 years ago
parent 5af06c1332
commit 02e21c7d7e

@ -144,6 +144,7 @@
<Compile Include="ProviderTests\DecisionEngineTests\LanguageSpecificationFixture.cs" /> <Compile Include="ProviderTests\DecisionEngineTests\LanguageSpecificationFixture.cs" />
<Compile Include="ProviderTests\DownloadClientTests\NzbgetProviderTests\DownloadNzbFixture.cs" /> <Compile Include="ProviderTests\DownloadClientTests\NzbgetProviderTests\DownloadNzbFixture.cs" />
<Compile Include="ProviderTests\DownloadClientTests\NzbgetProviderTests\QueueFixture.cs" /> <Compile Include="ProviderTests\DownloadClientTests\NzbgetProviderTests\QueueFixture.cs" />
<Compile Include="ProviderTests\DownloadProviderTests\ContainsRecentEpisode.cs" />
<Compile Include="ProviderTests\RootDirProviderTests\FreeSpaceOnDrivesFixture.cs" /> <Compile Include="ProviderTests\RootDirProviderTests\FreeSpaceOnDrivesFixture.cs" />
<Compile Include="ProviderTests\SearchTests\ProcessResultsFixture.cs" /> <Compile Include="ProviderTests\SearchTests\ProcessResultsFixture.cs" />
<Compile Include="ProviderTests\SearchTests\DailyEpisodeSearchTests\CheckReportFixture.cs" /> <Compile Include="ProviderTests\SearchTests\DailyEpisodeSearchTests\CheckReportFixture.cs" />
@ -237,7 +238,7 @@
<Compile Include="dbBenchmark.cs" /> <Compile Include="dbBenchmark.cs" />
<Compile Include="Framework\CoreTest.cs" /> <Compile Include="Framework\CoreTest.cs" />
<Compile Include="ProviderTests\DecisionEngineTests\MonitoredEpisodeSpecificationFixture.cs" /> <Compile Include="ProviderTests\DecisionEngineTests\MonitoredEpisodeSpecificationFixture.cs" />
<Compile Include="ProviderTests\DownloadProviderFixture.cs" /> <Compile Include="ProviderTests\DownloadProviderTests\DownloadProviderFixture.cs" />
<Compile Include="EpisodeStatusTest.cs" /> <Compile Include="EpisodeStatusTest.cs" />
<Compile Include="JobTests\ImportNewSeriesJobTest.cs" /> <Compile Include="JobTests\ImportNewSeriesJobTest.cs" />
<Compile Include="JobTests\DiskScanJobTest.cs" /> <Compile Include="JobTests\DiskScanJobTest.cs" />

@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.ProviderTests.DownloadProviderTests
{
[TestFixture]
public class ContainsRecentEpisode : CoreTest
{
private Episode _recentEpisode;
private Episode _oldEpisode;
[SetUp]
public void Setup()
{
_recentEpisode = Builder<Episode>
.CreateNew()
.With(e => e.AirDate = DateTime.Today)
.Build();
_oldEpisode = Builder<Episode>
.CreateNew()
.With(e => e.AirDate = DateTime.Today.AddDays(-365))
.Build();
}
[Test]
public void should_return_true_if_episode_aired_recently()
{
var epr = Builder<EpisodeParseResult>
.CreateNew()
.With(p => p.Episodes = new List<Episode>
{
_recentEpisode
})
.Build();
Mocker.Resolve<DownloadProvider>().ContainsRecentEpisode(epr).Should().BeTrue();
}
[Test]
public void should_return_true_if_one_episode_aired_recently()
{
var epr = Builder<EpisodeParseResult>
.CreateNew()
.With(p => p.Episodes = new List<Episode>
{
_recentEpisode,
_oldEpisode
})
.Build();
Mocker.Resolve<DownloadProvider>().ContainsRecentEpisode(epr).Should().BeTrue();
}
[Test]
public void should_return_false_if_episode_did_not_air_recently()
{
var epr = Builder<EpisodeParseResult>
.CreateNew()
.With(p => p.Episodes = new List<Episode>
{
_oldEpisode
})
.Build();
Mocker.Resolve<DownloadProvider>().ContainsRecentEpisode(epr).Should().BeFalse();
}
[Test]
public void should_return_false_if_no_episode_aired_recently()
{
var epr = Builder<EpisodeParseResult>
.CreateNew()
.With(p => p.Episodes = new List<Episode>
{
_oldEpisode,
_oldEpisode
})
.Build();
Mocker.Resolve<DownloadProvider>().ContainsRecentEpisode(epr).Should().BeFalse();
}
}
}

@ -15,7 +15,7 @@ using NzbDrone.Core.Test.Framework;
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
namespace NzbDrone.Core.Test.ProviderTests namespace NzbDrone.Core.Test.ProviderTests.DownloadProviderTests
{ {
[TestFixture] [TestFixture]
public class DownloadProviderFixture : CoreTest public class DownloadProviderFixture : CoreTest

@ -26,7 +26,6 @@ namespace NzbDrone.Core.Providers.DownloadClients
_httpProvider = httpProvider; _httpProvider = httpProvider;
} }
public SabProvider() public SabProvider()
{ {
} }
@ -41,7 +40,6 @@ namespace NzbDrone.Core.Providers.DownloadClients
var matchingTitleWithQuality = matchigTitle.Where(q => q.ParseResult.Quality >= newParseResult.Quality); var matchingTitleWithQuality = matchigTitle.Where(q => q.ParseResult.Quality >= newParseResult.Quality);
if (newParseResult.Series.IsDaily) if (newParseResult.Series.IsDaily)
{ {
return matchingTitleWithQuality.Any(q => q.ParseResult.AirDate.Value.Date == newParseResult.AirDate.Value.Date); return matchingTitleWithQuality.Any(q => q.ParseResult.AirDate.Value.Date == newParseResult.AirDate.Value.Date);

@ -48,7 +48,7 @@ namespace NzbDrone.Core.Providers
{ {
var downloadTitle = GetDownloadTitle(parseResult); var downloadTitle = GetDownloadTitle(parseResult);
var provider = GetActiveDownloadClient(); var provider = GetActiveDownloadClient();
var recentEpisode = CheckIfRecentEpisode(parseResult); var recentEpisode = ContainsRecentEpisode(parseResult);
bool success = provider.DownloadNzb(parseResult.NzbUrl, downloadTitle, recentEpisode); bool success = provider.DownloadNzb(parseResult.NzbUrl, downloadTitle, recentEpisode);
@ -165,13 +165,9 @@ namespace NzbDrone.Core.Providers
return result; return result;
} }
public virtual bool CheckIfRecentEpisode(EpisodeParseResult parseResult) public virtual bool ContainsRecentEpisode(EpisodeParseResult parseResult)
{ {
return parseResult.Episodes return parseResult.Episodes.Any(e => e.AirDate >= DateTime.Today.AddDays(-7));
.Where(e => e.AirDate.HasValue)
.Select(e => e.AirDate)
.OrderBy(e => e.Value)
.First().Value <= DateTime.Today.AddDays(7);
} }
} }
} }
Loading…
Cancel
Save