From c37544d4ce9b303df9e90a7409f574d9948f259b Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 3 Jul 2011 16:04:57 -0700 Subject: [PATCH] Episode is now marked as grabbed on download --- NzbDrone.Core.Test/DownloadProviderTest.cs | 9 ++++++- NzbDrone.Core.Test/EpisodeProviderTest.cs | 25 +++++++++++++++++++ NzbDrone.Core.Test/IndexerTests.cs | 2 +- NzbDrone.Core/Parser.cs | 1 - NzbDrone.Core/Providers/DownloadProvider.cs | 1 + NzbDrone.Core/Providers/EpisodeProvider.cs | 7 ++++++ .../Providers/Indexer/IndexerBase.cs | 1 - NzbDrone.Core/Providers/InventoryProvider.cs | 2 +- 8 files changed, 43 insertions(+), 5 deletions(-) diff --git a/NzbDrone.Core.Test/DownloadProviderTest.cs b/NzbDrone.Core.Test/DownloadProviderTest.cs index 492f7c347..e0d956236 100644 --- a/NzbDrone.Core.Test/DownloadProviderTest.cs +++ b/NzbDrone.Core.Test/DownloadProviderTest.cs @@ -17,7 +17,7 @@ namespace NzbDrone.Core.Test public class DownloadProviderTest : TestBase { [Test] - public void Download_report_should_send_to_sab_and_add_to_history() + public void Download_report_should_send_to_sab_add_to_history_mark_as_grabbed() { var mocker = new AutoMoqer(MockBehavior.Strict); var parseResult = Builder.CreateNew() @@ -52,6 +52,13 @@ namespace NzbDrone.Core.Test mocker.GetMock() .Setup(c => c.GetEpisodesByParseResult(It.IsAny(), false)).Returns(episodes); + mocker.GetMock() + .Setup(c => c.MarkEpisodeAsFetched(12)); + + + mocker.GetMock() + .Setup(c => c.MarkEpisodeAsFetched(99)); + mocker.Resolve().DownloadReport(parseResult); mocker.VerifyAllMocks(); diff --git a/NzbDrone.Core.Test/EpisodeProviderTest.cs b/NzbDrone.Core.Test/EpisodeProviderTest.cs index 6b6da3c27..2a0398fba 100644 --- a/NzbDrone.Core.Test/EpisodeProviderTest.cs +++ b/NzbDrone.Core.Test/EpisodeProviderTest.cs @@ -757,6 +757,31 @@ namespace NzbDrone.Core.Test episode.EpisodeFile.Should().BeNull(); } + [Test] + public void MarkEpisodeAsFetched() + { + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + var fakeEpisodes = Builder.CreateListOfSize(5) + .WhereAll().Have(e => e.GrabDate = null) + .Build(); + + db.InsertMany(fakeEpisodes); + + //Act + mocker.Resolve().MarkEpisodeAsFetched(2); + var episodes = db.Fetch(); + + //Assert + episodes.Where(e => e.EpisodeId == 2).Single().GrabDate.Should().BeWithin(TimeSpan.FromSeconds(5)).Before( + DateTime.Now); + + episodes.Where(e => e.GrabDate == null).Should().HaveCount(4); + } + + } diff --git a/NzbDrone.Core.Test/IndexerTests.cs b/NzbDrone.Core.Test/IndexerTests.cs index 27320ed5e..92448807c 100644 --- a/NzbDrone.Core.Test/IndexerTests.cs +++ b/NzbDrone.Core.Test/IndexerTests.cs @@ -185,7 +185,7 @@ namespace NzbDrone.Core.Test } [TestCase("simpsons", 21, 23)] - [TestCase("Hawaii Five-0 (2010)", 1, 5)] + [TestCase("Hawaii Five-0 (2010)", 1, 1)] public void newzbin_search_returns_valid_results(string title, int season, int episode) { var mocker = new AutoMoqer(); diff --git a/NzbDrone.Core/Parser.cs b/NzbDrone.Core/Parser.cs index e969ceae2..7780fefb9 100644 --- a/NzbDrone.Core/Parser.cs +++ b/NzbDrone.Core/Parser.cs @@ -300,7 +300,6 @@ namespace NzbDrone.Core return result; } - Logger.Trace("Quality Parsed:{0} Title:", result, name); return result; } diff --git a/NzbDrone.Core/Providers/DownloadProvider.cs b/NzbDrone.Core/Providers/DownloadProvider.cs index 710ac20ad..9a32b609f 100644 --- a/NzbDrone.Core/Providers/DownloadProvider.cs +++ b/NzbDrone.Core/Providers/DownloadProvider.cs @@ -51,6 +51,7 @@ namespace NzbDrone.Core.Providers history.SeriesId = episode.SeriesId; _historyProvider.Add(history); + _episodeProvider.MarkEpisodeAsFetched(episode.EpisodeId); } } diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index 3296cb16b..8759d6c2e 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -106,6 +106,13 @@ namespace NzbDrone.Core.Providers } + public virtual void MarkEpisodeAsFetched(int episodeId) + { + Logger.Trace("Marking episode {0} as fetched.", episodeId); + _database.Execute("UPDATE Episodes SET GrabDate=@0 WHERE EpisodeId=@1", DateTime.Now, episodeId); + } + + public virtual IList GetEpisodesByParseResult(EpisodeParseResult parseResult, Boolean autoAddNew = false) { var result = new List(); diff --git a/NzbDrone.Core/Providers/Indexer/IndexerBase.cs b/NzbDrone.Core/Providers/Indexer/IndexerBase.cs index 2f298f49b..225ed5cbe 100644 --- a/NzbDrone.Core/Providers/Indexer/IndexerBase.cs +++ b/NzbDrone.Core/Providers/Indexer/IndexerBase.cs @@ -61,7 +61,6 @@ namespace NzbDrone.Core.Providers.Indexer /// The episode number. /// protected abstract IList GetSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber); - public abstract IList GetSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber); /// /// This method can be overwritten to provide indexer specific info parsing diff --git a/NzbDrone.Core/Providers/InventoryProvider.cs b/NzbDrone.Core/Providers/InventoryProvider.cs index 202f0a9c7..fd9ada11b 100644 --- a/NzbDrone.Core/Providers/InventoryProvider.cs +++ b/NzbDrone.Core/Providers/InventoryProvider.cs @@ -110,7 +110,7 @@ namespace NzbDrone.Core.Providers { if (currentQuality.QualityType >= cutOff) { - Logger.Trace("Existing file meets cut-off. skipping."); + Logger.Trace("Existing item meets cut-off. skipping."); return false; }