mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-24 16:51:58 +00:00
added more tests for seriesprovider
This commit is contained in:
parent
b21bdbe41f
commit
8a3fe0f14e
10 changed files with 90 additions and 34 deletions
|
@ -12,6 +12,7 @@
|
|||
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 @@ public void Test_Parse_Success(string postTitle, string title)
|
|||
//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<IRepository>().ToConstant(repo);
|
||||
kernel.Bind<ISeriesProvider>().To<SeriesProvider>();
|
||||
|
||||
repo.Add(Builder<Series>.CreateNew()
|
||||
.With(c => c.Monitored = true)
|
||||
.With(c => c.SeriesId = 12)
|
||||
.Build());
|
||||
|
||||
repo.Add(Builder<Series>.CreateNew()
|
||||
.With(c => c.Monitored = false)
|
||||
.With(c => c.SeriesId = 11)
|
||||
.Build());
|
||||
|
||||
|
||||
// kernel.Bind<ISeriesProvider>().To<SeriesProvider>();
|
||||
// kernel.Bind<IDiskProvider>().ToConstant(MockLib.GetStandardDisk(0, 0));
|
||||
// kernel.Bind<IConfigProvider>().ToConstant(MockLib.StandardConfig);
|
||||
|
||||
// var seriesController = kernel.Get<ISeriesProvider>();
|
||||
|
||||
// //Act
|
||||
// var unmappedFolder = seriesController.GetUnmappedFolders();
|
||||
|
||||
// //Assert
|
||||
// Assert.AreElementsEqualIgnoringOrder(MockLib.StandardSeries, unmappedFolder.Values);
|
||||
//}
|
||||
//Act, Assert
|
||||
var provider = kernel.Get<ISeriesProvider>();
|
||||
Assert.IsTrue(provider.IsMonitored(12));
|
||||
Assert.IsFalse(provider.IsMonitored(11));
|
||||
Assert.IsFalse(provider.IsMonitored(1));
|
||||
}
|
||||
|
||||
|
||||
|
||||
[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>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<CodeAnalysisLogFile>bin\Debug\SABSync.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
|
||||
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using System.Xml;
|
||||
using NLog;
|
||||
|
||||
namespace NzbDrone.Core.Providers.Core
|
||||
|
@ -40,39 +41,43 @@ public string DownloadString(string request, string username, string password)
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -12,14 +12,17 @@ abstract class FeedProviderBase
|
|||
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 @@ public void Fetch()
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -59,8 +59,8 @@ public bool IsMonitored(long id)
|
|||
public bool QualityWanted(int seriesId, QualityTypes quality)
|
||||
{
|
||||
var series = _sonioRepo.Single<Series>(seriesId);
|
||||
var profile = _quality.Find(series.QualityProfileId);
|
||||
|
||||
var profile = _quality.Find(series.QualityProfileId);
|
||||
return profile.Allowed.Contains(quality);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,8 @@ public string SonicAllowed
|
|||
get
|
||||
{
|
||||
string result = String.Empty;
|
||||
if (Allowed == null) return result;
|
||||
|
||||
foreach (var q in Allowed)
|
||||
{
|
||||
result += (int)q + "|";
|
||||
|
|
|
@ -121,7 +121,7 @@ public SelectList GetSuggestionList(string searchString)
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
<button class="listButton" onclick="addSeries('@ViewData["guid"]','@ViewData["javaPath"].ToString()' )">
|
||||
Add</button>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue