diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
index bcbcad378..837e3d9aa 100644
--- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
+++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
@@ -144,6 +144,7 @@
+
@@ -237,7 +238,7 @@
-
+
diff --git a/NzbDrone.Core.Test/ProviderTests/DownloadProviderTests/ContainsRecentEpisode.cs b/NzbDrone.Core.Test/ProviderTests/DownloadProviderTests/ContainsRecentEpisode.cs
new file mode 100644
index 000000000..1a44301a8
--- /dev/null
+++ b/NzbDrone.Core.Test/ProviderTests/DownloadProviderTests/ContainsRecentEpisode.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
+ .CreateNew()
+ .With(e => e.AirDate = DateTime.Today)
+ .Build();
+
+ _oldEpisode = Builder
+ .CreateNew()
+ .With(e => e.AirDate = DateTime.Today.AddDays(-365))
+ .Build();
+ }
+
+ [Test]
+ public void should_return_true_if_episode_aired_recently()
+ {
+ var epr = Builder
+ .CreateNew()
+ .With(p => p.Episodes = new List
+ {
+ _recentEpisode
+ })
+ .Build();
+
+ Mocker.Resolve().ContainsRecentEpisode(epr).Should().BeTrue();
+ }
+
+ [Test]
+ public void should_return_true_if_one_episode_aired_recently()
+ {
+ var epr = Builder
+ .CreateNew()
+ .With(p => p.Episodes = new List
+ {
+ _recentEpisode,
+ _oldEpisode
+ })
+ .Build();
+
+ Mocker.Resolve().ContainsRecentEpisode(epr).Should().BeTrue();
+ }
+
+ [Test]
+ public void should_return_false_if_episode_did_not_air_recently()
+ {
+ var epr = Builder
+ .CreateNew()
+ .With(p => p.Episodes = new List
+ {
+ _oldEpisode
+ })
+ .Build();
+
+ Mocker.Resolve().ContainsRecentEpisode(epr).Should().BeFalse();
+ }
+
+ [Test]
+ public void should_return_false_if_no_episode_aired_recently()
+ {
+ var epr = Builder
+ .CreateNew()
+ .With(p => p.Episodes = new List
+ {
+ _oldEpisode,
+ _oldEpisode
+ })
+ .Build();
+
+ Mocker.Resolve().ContainsRecentEpisode(epr).Should().BeFalse();
+ }
+ }
+}
diff --git a/NzbDrone.Core.Test/ProviderTests/DownloadProviderFixture.cs b/NzbDrone.Core.Test/ProviderTests/DownloadProviderTests/DownloadProviderFixture.cs
similarity index 99%
rename from NzbDrone.Core.Test/ProviderTests/DownloadProviderFixture.cs
rename to NzbDrone.Core.Test/ProviderTests/DownloadProviderTests/DownloadProviderFixture.cs
index cd5dbdda0..d9d54e2e8 100644
--- a/NzbDrone.Core.Test/ProviderTests/DownloadProviderFixture.cs
+++ b/NzbDrone.Core.Test/ProviderTests/DownloadProviderTests/DownloadProviderFixture.cs
@@ -15,7 +15,7 @@ using NzbDrone.Core.Test.Framework;
// ReSharper disable InconsistentNaming
-namespace NzbDrone.Core.Test.ProviderTests
+namespace NzbDrone.Core.Test.ProviderTests.DownloadProviderTests
{
[TestFixture]
public class DownloadProviderFixture : CoreTest
diff --git a/NzbDrone.Core/Providers/DownloadClients/SabProvider.cs b/NzbDrone.Core/Providers/DownloadClients/SabProvider.cs
index d004a21ec..30d0b392e 100644
--- a/NzbDrone.Core/Providers/DownloadClients/SabProvider.cs
+++ b/NzbDrone.Core/Providers/DownloadClients/SabProvider.cs
@@ -26,7 +26,6 @@ namespace NzbDrone.Core.Providers.DownloadClients
_httpProvider = httpProvider;
}
-
public SabProvider()
{
}
@@ -41,7 +40,6 @@ namespace NzbDrone.Core.Providers.DownloadClients
var matchingTitleWithQuality = matchigTitle.Where(q => q.ParseResult.Quality >= newParseResult.Quality);
-
if (newParseResult.Series.IsDaily)
{
return matchingTitleWithQuality.Any(q => q.ParseResult.AirDate.Value.Date == newParseResult.AirDate.Value.Date);
diff --git a/NzbDrone.Core/Providers/DownloadProvider.cs b/NzbDrone.Core/Providers/DownloadProvider.cs
index aaef0e24f..1e92983de 100644
--- a/NzbDrone.Core/Providers/DownloadProvider.cs
+++ b/NzbDrone.Core/Providers/DownloadProvider.cs
@@ -48,7 +48,7 @@ namespace NzbDrone.Core.Providers
{
var downloadTitle = GetDownloadTitle(parseResult);
var provider = GetActiveDownloadClient();
- var recentEpisode = CheckIfRecentEpisode(parseResult);
+ var recentEpisode = ContainsRecentEpisode(parseResult);
bool success = provider.DownloadNzb(parseResult.NzbUrl, downloadTitle, recentEpisode);
@@ -165,13 +165,9 @@ namespace NzbDrone.Core.Providers
return result;
}
- public virtual bool CheckIfRecentEpisode(EpisodeParseResult parseResult)
+ public virtual bool ContainsRecentEpisode(EpisodeParseResult parseResult)
{
- return parseResult.Episodes
- .Where(e => e.AirDate.HasValue)
- .Select(e => e.AirDate)
- .OrderBy(e => e.Value)
- .First().Value <= DateTime.Today.AddDays(7);
+ return parseResult.Episodes.Any(e => e.AirDate >= DateTime.Today.AddDays(-7));
}
}
}
\ No newline at end of file