From e074164a478dc0a4a41f285d596103664170869d Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Fri, 22 Apr 2011 13:14:02 -0700 Subject: [PATCH] more tests and bug fixes --- NzbDrone.Core.Test/EpisodeProviderTest.cs | 29 +++++++++++++++++++ NzbDrone.Core.Test/HistoryProviderTest.cs | 25 ++++++++++++++++ NzbDrone.Core.Test/MockLib.cs | 9 ++++++ NzbDrone.Core.Test/SeriesProviderTest.cs | 2 +- NzbDrone.Core/Providers/EpisodeProvider.cs | 10 ++++--- NzbDrone.Core/Providers/HistoryProvider.cs | 6 ++-- .../Providers/Indexer/IndexerProviderBase.cs | 18 ++++++++---- 7 files changed, 86 insertions(+), 13 deletions(-) diff --git a/NzbDrone.Core.Test/EpisodeProviderTest.cs b/NzbDrone.Core.Test/EpisodeProviderTest.cs index d1e14ded1..b9da6abba 100644 --- a/NzbDrone.Core.Test/EpisodeProviderTest.cs +++ b/NzbDrone.Core.Test/EpisodeProviderTest.cs @@ -116,6 +116,35 @@ public void Is_Needed_Tv_Dvd_BluRay_BluRay720_Is_Cutoff(QualityTypes reportQuali Assert.AreEqual(excpected, result); } + [Test] + public void get_episode_by_parse_result() + { + var mocker = new AutoMoqer(); + var repo = MockLib.GetEmptyRepository(); + var fakeEpisodes = MockLib.GetFakeEpisodes(2); + repo.AddMany(fakeEpisodes); + mocker.SetConstant(repo); + + var targetEpisode = fakeEpisodes[4]; + + var parseResult1 = new EpisodeParseResult + { + SeriesId = targetEpisode.SeriesId, + SeasonNumber = targetEpisode.SeasonNumber, + Episodes = new List { targetEpisode.EpisodeNumber }, + Quality = QualityTypes.DVD + }; + + var result = mocker.Resolve().GetEpisodeByParseResult(parseResult1); + + + Assert.Count(1, result); + Assert.AreEqual(targetEpisode.EpisodeId, result.First().EpisodeId); + Assert.AreEqual(targetEpisode.EpisodeNumber, result.First().EpisodeNumber); + Assert.AreEqual(targetEpisode.SeasonNumber, result.First().SeasonNumber); + Assert.AreEqual(targetEpisode.SeriesId, result.First().SeriesId); + } + [Test] public void Missing_episode_should_be_added() { diff --git a/NzbDrone.Core.Test/HistoryProviderTest.cs b/NzbDrone.Core.Test/HistoryProviderTest.cs index d7cabdc34..71828312b 100644 --- a/NzbDrone.Core.Test/HistoryProviderTest.cs +++ b/NzbDrone.Core.Test/HistoryProviderTest.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using AutoMoq; using MbUnit.Framework; using Moq; using NzbDrone.Core.Providers; @@ -63,6 +64,30 @@ public void AllItems() Assert.AreEqual(result.Count(), 1); } + + [Test] + public void add_item() + { + var mocker = new AutoMoqer(); + var repo = MockLib.GetEmptyRepository(); + + mocker.SetConstant(repo); + + var episodes = MockLib.GetFakeEpisodes(1); + repo.AddMany(episodes); + + var episode = episodes[5]; + + var history = new History + { + Date = DateTime.Now, + EpisodeId = episode.EpisodeId, + NzbTitle = "my title" + }; + + mocker.Resolve().Add(history); + } + [Test] [Ignore] public void Exists_True() diff --git a/NzbDrone.Core.Test/MockLib.cs b/NzbDrone.Core.Test/MockLib.cs index fa74f4822..d2ddd35d6 100644 --- a/NzbDrone.Core.Test/MockLib.cs +++ b/NzbDrone.Core.Test/MockLib.cs @@ -82,5 +82,14 @@ public static Series GetFakeSeries(int id, string title) .With(c => c.CleanTitle = Parser.NormalizeTitle(title)) .Build(); } + + public static IList GetFakeEpisodes(int seriesId) + { + var epNumber = new SequentialGenerator(); + return Builder.CreateListOfSize(10) + .WhereAll().Have(c => c.SeriesId = seriesId) + .WhereAll().Have(c => c.EpisodeNumber = epNumber.Generate()) + .Build(); + } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/SeriesProviderTest.cs b/NzbDrone.Core.Test/SeriesProviderTest.cs index 06a8d448b..d1c781523 100644 --- a/NzbDrone.Core.Test/SeriesProviderTest.cs +++ b/NzbDrone.Core.Test/SeriesProviderTest.cs @@ -113,7 +113,7 @@ public void find_series_empty_match() [Test] [Row("The Test", "Test")] - [Row("The Test Title", "test title")] + [Row("Through the Wormhole", "Through.the.Wormhole")] public void find_series_match(string title, string searchTitle) { var mocker = new AutoMoqer(); diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index 5396499b4..be16000e6 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -57,10 +57,12 @@ public virtual IList GetEpisodeBySeason(long seasonId) public virtual IList GetEpisodeByParseResult(EpisodeParseResult parseResult) { - return _sonicRepo.Find(e => - e.SeriesId == parseResult.SeriesId && - e.SeasonNumber == parseResult.SeasonNumber && - parseResult.Episodes.Contains(e.EpisodeNumber)); + var seasonEpisodes = _sonicRepo.All().Where(e => + e.SeriesId == parseResult.SeriesId && + e.SeasonNumber == parseResult.SeasonNumber).ToList(); + + //Has to be done separately since subsonic doesn't support contain method + return seasonEpisodes.Where(c => parseResult.Episodes.Contains(c.EpisodeNumber)).ToList(); } diff --git a/NzbDrone.Core/Providers/HistoryProvider.cs b/NzbDrone.Core/Providers/HistoryProvider.cs index 8dba22e29..5b473a754 100644 --- a/NzbDrone.Core/Providers/HistoryProvider.cs +++ b/NzbDrone.Core/Providers/HistoryProvider.cs @@ -40,10 +40,10 @@ public virtual void Trim() Logger.Info("History has been trimmed, items older than 30 days have been removed"); } - public virtual void Insert(History item) + public virtual void Add(History item) { _sonicRepo.Add(item); - Logger.Debug("Item added to history: {0} - {1}x{2:00}", item.Episode.Series.Title, item.Episode.SeasonNumber, item.Episode.EpisodeNumber); + Logger.Debug("Item added to history: {0}", item.NzbTitle); } public virtual bool Exists(int episodeId, QualityTypes quality, bool proper) @@ -52,7 +52,7 @@ public virtual bool Exists(int episodeId, QualityTypes quality, bool proper) if (_sonicRepo.Exists(h => h.EpisodeId == episodeId && h.Quality == quality && h.IsProper == proper)) return true; - Logger.Debug("Episode not in History. ID:{0} Q:{1} Proper:{2}", episodeId , quality, proper); + Logger.Debug("Episode not in History. ID:{0} Q:{1} Proper:{2}", episodeId, quality, proper); return false; } } diff --git a/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs b/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs index d08d37537..ff591d4da 100644 --- a/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs +++ b/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs @@ -68,12 +68,20 @@ public void Fetch() foreach (var item in feed) { - ProcessItem(item); + try + { + ProcessItem(item); + } + catch (Exception itemEx) + { + _logger.ErrorException("An error occurred while processing feed item", itemEx); + } + } } - catch (Exception e) + catch (Exception feedEx) { - _logger.ErrorException("An error occurred while processing feed", e); + _logger.ErrorException("An error occurred while processing feed", feedEx); } } @@ -82,7 +90,7 @@ public void Fetch() internal void ProcessItem(SyndicationItem feedItem) { - _logger.Info("Processing RSS feed item " + feedItem.Title.Text); + _logger.Debug("Processing RSS feed item " + feedItem.Title.Text); var parseResult = ParseFeed(feedItem); @@ -124,7 +132,7 @@ internal void ProcessItem(SyndicationItem feedItem) //TODO: Add episode to sab - _historyProvider.Insert(new History + _historyProvider.Add(new History { Date = DateTime.Now, EpisodeId = episode.EpisodeId,