added more tests for seriesprovider

pull/2/head
kay.one 14 years ago
parent b21bdbe41f
commit 8a3fe0f14e

@ -12,6 +12,7 @@ using Ninject;
using Ninject.Moq; using Ninject.Moq;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository; using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using SubSonic.Repository; using SubSonic.Repository;
using TvdbLib.Data; using TvdbLib.Data;
using System.Linq; using System.Linq;
@ -96,26 +97,69 @@ namespace NzbDrone.Core.Test
//Assert.AreEqual(title, result, postTitle); //Assert.AreEqual(title, result, postTitle);
} }
//[Test] [Test]
//public void get_unmapped() public void Test_is_monitored()
//{ {
// //Setup var kernel = new MockingKernel();
// var kernel = new MockingKernel(); var repo = MockLib.GetEmptyRepository();
kernel.Bind<IRepository>().ToConstant(repo);
kernel.Bind<ISeriesProvider>().To<SeriesProvider>();
repo.Add(Builder<Series>.CreateNew()
.With(c => c.Monitored = true)
.With(c => c.SeriesId = 12)
.Build());
// kernel.Bind<ISeriesProvider>().To<SeriesProvider>(); repo.Add(Builder<Series>.CreateNew()
// kernel.Bind<IDiskProvider>().ToConstant(MockLib.GetStandardDisk(0, 0)); .With(c => c.Monitored = false)
// kernel.Bind<IConfigProvider>().ToConstant(MockLib.StandardConfig); .With(c => c.SeriesId = 11)
.Build());
// var seriesController = kernel.Get<ISeriesProvider>();
// //Act //Act, Assert
// var unmappedFolder = seriesController.GetUnmappedFolders(); var provider = kernel.Get<ISeriesProvider>();
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<IRepository>().ToConstant(repo);
kernel.Bind<ISeriesProvider>().To<SeriesProvider>();
var quality = Builder<QualityProfile>.CreateNew()
.With(q => q.Allowed = new List<QualityTypes>() { QualityTypes.BDRip, QualityTypes.DVD, QualityTypes.TV })
.With(q => q.Cutoff = QualityTypes.DVD)
.Build();
var qualityProviderMock = new Mock<IQualityProvider>();
qualityProviderMock.Setup(c => c.Find(quality.QualityProfileId)).Returns(quality).Verifiable();
kernel.Bind<IQualityProvider>().ToConstant(qualityProviderMock.Object);
repo.Add(Builder<Series>.CreateNew()
.With(c => c.SeriesId = 12)
.With(c => c.QualityProfileId = quality.QualityProfileId)
.Build());
//Act
var needed = kernel.Get<ISeriesProvider>().QualityWanted(seriesId, qualityTypes);
Assert.AreEqual(result, needed);
}
} }
} }

@ -91,7 +91,7 @@
<OutputPath>bin\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<CodeAnalysisLogFile>bin\Debug\SABSync.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile> <CodeAnalysisLogFile>bin\Debug\SABSync.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression> <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile> <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>

@ -1,5 +1,6 @@
using System; using System;
using System.Net; using System.Net;
using System.Xml;
using NLog; using NLog;
namespace NzbDrone.Core.Providers.Core namespace NzbDrone.Core.Providers.Core
@ -40,39 +41,43 @@ namespace NzbDrone.Core.Providers.Core
return String.Empty; return String.Empty;
} }
public bool DownloadFile(string request, string filename) public void DownloadFile(string request, string filename)
{ {
try try
{ {
var webClient = new WebClient(); var webClient = new WebClient();
webClient.DownloadFile(request, filename); webClient.DownloadFile(request, filename);
return true;
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Warn("Failed to get response from: {0}", request); Logger.Warn("Failed to get response from: {0}", request);
Logger.TraceException(ex.Message, ex); 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 try
{ {
var webClient = new WebClient(); var webClient = new WebClient();
webClient.Credentials = new NetworkCredential(username, password); webClient.Credentials = new NetworkCredential(username, password);
webClient.DownloadFile(request, filename); webClient.DownloadFile(request, filename);
return true;
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Warn("Failed to get response from: {0}", request); Logger.Warn("Failed to get response from: {0}", request);
Logger.TraceException(ex.Message, ex); Logger.TraceException(ex.Message, ex);
throw;
} }
}
return false; public XmlReader DownloadXml(string url)
{
return XmlReader.Create(url);
} }
} }
} }

@ -1,10 +1,13 @@
namespace NzbDrone.Core.Providers.Core using System.Xml;
namespace NzbDrone.Core.Providers.Core
{ {
public interface IHttpProvider public interface IHttpProvider
{ {
string DownloadString(string request); string DownloadString(string request);
string DownloadString(string request, string username, string password); string DownloadString(string request, string username, string password);
bool DownloadFile(string request, string filename); void DownloadFile(string request, string filename);
bool DownloadFile(string request, string filename, string username, string password); void DownloadFile(string request, string filename, string username, string password);
XmlReader DownloadXml(string url);
} }
} }

@ -12,14 +12,17 @@ namespace NzbDrone.Core.Providers.Feed
protected readonly ISeasonProvider _seasonProvider; protected readonly ISeasonProvider _seasonProvider;
protected readonly IEpisodeProvider _episodeProvider; protected readonly IEpisodeProvider _episodeProvider;
protected readonly IConfigProvider _configProvider; protected readonly IConfigProvider _configProvider;
private readonly IHttpProvider _httpProvider;
protected static readonly Logger Logger = LogManager.GetCurrentClassLogger(); 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; _seriesProvider = seriesProvider;
_seasonProvider = seasonProvider; _seasonProvider = seasonProvider;
_episodeProvider = episodeProvider; _episodeProvider = episodeProvider;
_configProvider = configProvider; _configProvider = configProvider;
_httpProvider = httpProvider;
} }
@ -76,7 +79,7 @@ namespace NzbDrone.Core.Providers.Feed
foreach (var url in URL) foreach (var url in URL)
{ {
Logger.Debug("Downloading RSS " + 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) foreach (var item in feed)
{ {

@ -9,8 +9,7 @@ namespace NzbDrone.Core.Providers.Feed
{ {
class NzbsOrgFeedProvider : FeedProviderBase class NzbsOrgFeedProvider : FeedProviderBase
{ {
public NzbsOrgFeedProvider(ISeriesProvider seriesProvider, ISeasonProvider seasonProvider, IEpisodeProvider episodeProvider, IConfigProvider configProvider) public NzbsOrgFeedProvider(ISeriesProvider seriesProvider, ISeasonProvider seasonProvider, IEpisodeProvider episodeProvider, IConfigProvider configProvider, IHttpProvider httpProvider) : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider)
: base(seriesProvider, seasonProvider, episodeProvider, configProvider)
{ {
} }

@ -59,8 +59,8 @@ namespace NzbDrone.Core.Providers
public bool QualityWanted(int seriesId, QualityTypes quality) public bool QualityWanted(int seriesId, QualityTypes quality)
{ {
var series = _sonioRepo.Single<Series>(seriesId); var series = _sonioRepo.Single<Series>(seriesId);
var profile = _quality.Find(series.QualityProfileId);
var profile = _quality.Find(series.QualityProfileId);
return profile.Allowed.Contains(quality); return profile.Allowed.Contains(quality);
} }

@ -36,6 +36,8 @@ namespace NzbDrone.Core.Repository.Quality
get get
{ {
string result = String.Empty; string result = String.Empty;
if (Allowed == null) return result;
foreach (var q in Allowed) foreach (var q in Allowed)
{ {
result += (int)q + "|"; result += (int)q + "|";

@ -121,7 +121,7 @@ namespace NzbDrone.Web.Controllers
var dataVal = _tvDbProvider.SearchSeries(searchString); var dataVal = _tvDbProvider.SearchSeries(searchString);
var bestResult = _tvDbProvider.GetBestMatch(dataVal.ToList(), searchString); var bestResult = _tvDbProvider.GetBestMatch(dataVal.ToList(), searchString);
return new SelectList(dataVal, "Id", "SeriesName", bestResult); return new SelectList(dataVal, "Id", "SeriesName", dataVal[0].Id);
} }
} }

@ -12,7 +12,7 @@
.HighlightFirstMatch(true) .HighlightFirstMatch(true)
.HtmlAttributes(new { style = "width: 300px;" }) .HtmlAttributes(new { style = "width: 300px;" })
.Render();} .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)
<button class="listButton" onclick="addSeries('@ViewData["guid"]','@ViewData["javaPath"].ToString()' )"> <button class="listButton" onclick="addSeries('@ViewData["guid"]','@ViewData["javaPath"].ToString()' )">
Add</button> Add</button>
</div> </div>

Loading…
Cancel
Save