From 8a3fe0f14e9792773f8ae5a25e8e935637af8ae3 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Mon, 4 Apr 2011 22:30:13 -0700 Subject: [PATCH] added more tests for seriesprovider --- NzbDrone.Core.Test/SeriesProviderTest.cs | 72 +++++++++++++++---- NzbDrone.Core/NzbDrone.Core.csproj | 2 +- NzbDrone.Core/Providers/Core/HttpProvider.cs | 17 +++-- NzbDrone.Core/Providers/Core/IHttpProvider.cs | 9 ++- .../Providers/Feed/FeedProviderBase.cs | 7 +- .../Providers/Feed/NzbsOrgFeedProvider.cs | 3 +- NzbDrone.Core/Providers/SeriesProvider.cs | 2 +- .../Repository/Quality/QualityProfile.cs | 2 + .../Controllers/AddSeriesController.cs | 2 +- .../Views/AddSeries/AddSeriesItem.cshtml | 2 +- 10 files changed, 87 insertions(+), 31 deletions(-) diff --git a/NzbDrone.Core.Test/SeriesProviderTest.cs b/NzbDrone.Core.Test/SeriesProviderTest.cs index f0a338062..81a0b1a19 100644 --- a/NzbDrone.Core.Test/SeriesProviderTest.cs +++ b/NzbDrone.Core.Test/SeriesProviderTest.cs @@ -12,6 +12,7 @@ using Ninject; using Ninject.Moq; using NzbDrone.Core.Providers; using NzbDrone.Core.Repository; +using NzbDrone.Core.Repository.Quality; using SubSonic.Repository; using TvdbLib.Data; using System.Linq; @@ -96,26 +97,69 @@ namespace NzbDrone.Core.Test //Assert.AreEqual(title, result, postTitle); } - //[Test] - //public void get_unmapped() - //{ - // //Setup - // var kernel = new MockingKernel(); + [Test] + public void Test_is_monitored() + { + var kernel = new MockingKernel(); + var repo = MockLib.GetEmptyRepository(); + kernel.Bind().ToConstant(repo); + kernel.Bind().To(); + repo.Add(Builder.CreateNew() + .With(c => c.Monitored = true) + .With(c => c.SeriesId = 12) + .Build()); - // kernel.Bind().To(); - // kernel.Bind().ToConstant(MockLib.GetStandardDisk(0, 0)); - // kernel.Bind().ToConstant(MockLib.StandardConfig); + repo.Add(Builder.CreateNew() + .With(c => c.Monitored = false) + .With(c => c.SeriesId = 11) + .Build()); - // var seriesController = kernel.Get(); - // //Act - // var unmappedFolder = seriesController.GetUnmappedFolders(); + //Act, Assert + var provider = kernel.Get(); + Assert.IsTrue(provider.IsMonitored(12)); + Assert.IsFalse(provider.IsMonitored(11)); + Assert.IsFalse(provider.IsMonitored(1)); + } - // //Assert - // Assert.AreElementsEqualIgnoringOrder(MockLib.StandardSeries, unmappedFolder.Values); - //} + [Test] + [Row(12, QualityTypes.TV, true)] + [Row(12, QualityTypes.Unknown, false)] + [Row(12, QualityTypes.Bluray1080, false)] + [Row(12, QualityTypes.Bluray720, false)] + [Row(12, QualityTypes.HDTV, false)] + [Row(12, QualityTypes.WEBDL, false)] + public void QualityWanted(int seriesId, QualityTypes qualityTypes, Boolean result) + { + var kernel = new MockingKernel(); + var repo = MockLib.GetEmptyRepository(); + kernel.Bind().ToConstant(repo); + kernel.Bind().To(); + + var quality = Builder.CreateNew() + .With(q => q.Allowed = new List() { QualityTypes.BDRip, QualityTypes.DVD, QualityTypes.TV }) + .With(q => q.Cutoff = QualityTypes.DVD) + .Build(); + + var qualityProviderMock = new Mock(); + qualityProviderMock.Setup(c => c.Find(quality.QualityProfileId)).Returns(quality).Verifiable(); + kernel.Bind().ToConstant(qualityProviderMock.Object); + + + repo.Add(Builder.CreateNew() + .With(c => c.SeriesId = 12) + .With(c => c.QualityProfileId = quality.QualityProfileId) + .Build()); + + //Act + var needed = kernel.Get().QualityWanted(seriesId, qualityTypes); + + Assert.AreEqual(result, needed); + + + } } } diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index a50fd16ce..856d95c98 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -91,7 +91,7 @@ bin\Debug\ DEBUG;TRACE full - x86 + AnyCPU bin\Debug\SABSync.exe.CodeAnalysisLog.xml true GlobalSuppressions.cs diff --git a/NzbDrone.Core/Providers/Core/HttpProvider.cs b/NzbDrone.Core/Providers/Core/HttpProvider.cs index b07c18071..9480729de 100644 --- a/NzbDrone.Core/Providers/Core/HttpProvider.cs +++ b/NzbDrone.Core/Providers/Core/HttpProvider.cs @@ -1,5 +1,6 @@ using System; using System.Net; +using System.Xml; using NLog; namespace NzbDrone.Core.Providers.Core @@ -40,39 +41,43 @@ namespace NzbDrone.Core.Providers.Core return String.Empty; } - public bool DownloadFile(string request, string filename) + public void DownloadFile(string request, string filename) { try { var webClient = new WebClient(); webClient.DownloadFile(request, filename); - return true; + } catch (Exception ex) { Logger.Warn("Failed to get response from: {0}", request); Logger.TraceException(ex.Message, ex); + throw; } - return false; + } - public bool DownloadFile(string request, string filename, string username, string password) + public void DownloadFile(string request, string filename, string username, string password) { try { var webClient = new WebClient(); webClient.Credentials = new NetworkCredential(username, password); webClient.DownloadFile(request, filename); - return true; } catch (Exception ex) { Logger.Warn("Failed to get response from: {0}", request); Logger.TraceException(ex.Message, ex); + throw; } + } - return false; + public XmlReader DownloadXml(string url) + { + return XmlReader.Create(url); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/Core/IHttpProvider.cs b/NzbDrone.Core/Providers/Core/IHttpProvider.cs index e10a6849a..dad240ec3 100644 --- a/NzbDrone.Core/Providers/Core/IHttpProvider.cs +++ b/NzbDrone.Core/Providers/Core/IHttpProvider.cs @@ -1,10 +1,13 @@ -namespace NzbDrone.Core.Providers.Core +using System.Xml; + +namespace NzbDrone.Core.Providers.Core { public interface IHttpProvider { string DownloadString(string request); string DownloadString(string request, string username, string password); - bool DownloadFile(string request, string filename); - bool DownloadFile(string request, string filename, string username, string password); + void DownloadFile(string request, string filename); + void DownloadFile(string request, string filename, string username, string password); + XmlReader DownloadXml(string url); } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/Feed/FeedProviderBase.cs b/NzbDrone.Core/Providers/Feed/FeedProviderBase.cs index 1d826901c..2b1b09669 100644 --- a/NzbDrone.Core/Providers/Feed/FeedProviderBase.cs +++ b/NzbDrone.Core/Providers/Feed/FeedProviderBase.cs @@ -12,14 +12,17 @@ namespace NzbDrone.Core.Providers.Feed protected readonly ISeasonProvider _seasonProvider; protected readonly IEpisodeProvider _episodeProvider; protected readonly IConfigProvider _configProvider; + private readonly IHttpProvider _httpProvider; protected static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - protected FeedProviderBase(ISeriesProvider seriesProvider, ISeasonProvider seasonProvider, IEpisodeProvider episodeProvider, IConfigProvider configProvider) + protected FeedProviderBase(ISeriesProvider seriesProvider, ISeasonProvider seasonProvider, + IEpisodeProvider episodeProvider, IConfigProvider configProvider, IHttpProvider httpProvider) { _seriesProvider = seriesProvider; _seasonProvider = seasonProvider; _episodeProvider = episodeProvider; _configProvider = configProvider; + _httpProvider = httpProvider; } @@ -76,7 +79,7 @@ namespace NzbDrone.Core.Providers.Feed foreach (var url in URL) { Logger.Debug("Downloading RSS " + url); - var feed = SyndicationFeed.Load(XmlReader.Create(url)).Items; + var feed = SyndicationFeed.Load(_httpProvider.DownloadXml(url)).Items; foreach (var item in feed) { diff --git a/NzbDrone.Core/Providers/Feed/NzbsOrgFeedProvider.cs b/NzbDrone.Core/Providers/Feed/NzbsOrgFeedProvider.cs index 74ace542f..bc51d09aa 100644 --- a/NzbDrone.Core/Providers/Feed/NzbsOrgFeedProvider.cs +++ b/NzbDrone.Core/Providers/Feed/NzbsOrgFeedProvider.cs @@ -9,8 +9,7 @@ namespace NzbDrone.Core.Providers.Feed { class NzbsOrgFeedProvider : FeedProviderBase { - public NzbsOrgFeedProvider(ISeriesProvider seriesProvider, ISeasonProvider seasonProvider, IEpisodeProvider episodeProvider, IConfigProvider configProvider) - : base(seriesProvider, seasonProvider, episodeProvider, configProvider) + public NzbsOrgFeedProvider(ISeriesProvider seriesProvider, ISeasonProvider seasonProvider, IEpisodeProvider episodeProvider, IConfigProvider configProvider, IHttpProvider httpProvider) : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider) { } diff --git a/NzbDrone.Core/Providers/SeriesProvider.cs b/NzbDrone.Core/Providers/SeriesProvider.cs index 364b2b66b..aba30b58f 100644 --- a/NzbDrone.Core/Providers/SeriesProvider.cs +++ b/NzbDrone.Core/Providers/SeriesProvider.cs @@ -59,8 +59,8 @@ namespace NzbDrone.Core.Providers public bool QualityWanted(int seriesId, QualityTypes quality) { var series = _sonioRepo.Single(seriesId); - var profile = _quality.Find(series.QualityProfileId); + var profile = _quality.Find(series.QualityProfileId); return profile.Allowed.Contains(quality); } diff --git a/NzbDrone.Core/Repository/Quality/QualityProfile.cs b/NzbDrone.Core/Repository/Quality/QualityProfile.cs index c8f7fe832..672a80073 100644 --- a/NzbDrone.Core/Repository/Quality/QualityProfile.cs +++ b/NzbDrone.Core/Repository/Quality/QualityProfile.cs @@ -36,6 +36,8 @@ namespace NzbDrone.Core.Repository.Quality get { string result = String.Empty; + if (Allowed == null) return result; + foreach (var q in Allowed) { result += (int)q + "|"; diff --git a/NzbDrone.Web/Controllers/AddSeriesController.cs b/NzbDrone.Web/Controllers/AddSeriesController.cs index d20e2ef26..043f379c7 100644 --- a/NzbDrone.Web/Controllers/AddSeriesController.cs +++ b/NzbDrone.Web/Controllers/AddSeriesController.cs @@ -121,7 +121,7 @@ namespace NzbDrone.Web.Controllers var dataVal = _tvDbProvider.SearchSeries(searchString); var bestResult = _tvDbProvider.GetBestMatch(dataVal.ToList(), searchString); - return new SelectList(dataVal, "Id", "SeriesName", bestResult); + return new SelectList(dataVal, "Id", "SeriesName", dataVal[0].Id); } } diff --git a/NzbDrone.Web/Views/AddSeries/AddSeriesItem.cshtml b/NzbDrone.Web/Views/AddSeries/AddSeriesItem.cshtml index 09458c69f..9aa0b9c27 100644 --- a/NzbDrone.Web/Views/AddSeries/AddSeriesItem.cshtml +++ b/NzbDrone.Web/Views/AddSeries/AddSeriesItem.cshtml @@ -12,7 +12,7 @@ .HighlightFirstMatch(true) .HtmlAttributes(new { style = "width: 300px;" }) .Render();} - @Html.Telerik().DropDownList().Name("qualityList_" + ViewData["guid"].ToString()).BindTo((SelectList)ViewData["quality"]).HtmlAttributes(new { style = "width: 100px;" }) + @Html.Telerik().DropDownList().Name("qualityList_" + ViewData["guid"].ToString()).BindTo((SelectList)ViewData["quality"]).HtmlAttributes(new { style = "width: 100px;" }).SelectedIndex(0)