1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-28 10:37:41 +00:00

DailySeries now use the JSON API instead of the CSV file.

This commit is contained in:
Mark McDowall 2012-01-12 20:08:58 -08:00
parent afb8305c00
commit ad4afbcb6d
2 changed files with 19 additions and 29 deletions

View file

@ -20,14 +20,16 @@ namespace NzbDrone.Core.Test.ProviderTests
// ReSharper disable InconsistentNaming
public class ReferenceDataProviderTest : CoreTest
{
private string validSeriesIds = String.Format("1,Test{0}2,Test{0}3,Test{0}4,Test{0}5,Test", Environment.NewLine);
private string invalidSeriesIds = String.Format("1,Test{0}2,Test{0}NaN,Test{0}4,Test{0}5,Test", Environment.NewLine);
private const string validSeriesIds = "[1,2,3,4,5]";
private const string invalidSeriesIds = "[1,2,NaN,4,5]";
private const string url = "http://services.nzbdrone.com/DailySeries/AllIds";
[Test]
public void GetDailySeriesIds_should_return_list_of_int_when_all_are_valid()
{
//Setup
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv"))
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
.Returns(validSeriesIds);
//Act
@ -38,24 +40,25 @@ public void GetDailySeriesIds_should_return_list_of_int_when_all_are_valid()
}
[Test]
public void GetDailySeriesIds_should_return_list_of_int_when_any_are_valid()
public void GetDailySeriesIds_should_return_empty_list_when_unable_to_parse()
{
//Setup
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv"))
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
.Returns(invalidSeriesIds);
//Act
var result = Mocker.Resolve<ReferenceDataProvider>().GetDailySeriesIds();
//Assert
result.Should().HaveCount(4);
result.Should().BeEmpty();
ExceptionVerification.ExpectedWarns(1);
}
[Test]
public void GetDailySeriesIds_should_return_empty_list_of_int_when_server_is_unavailable()
{
//Setup
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv"))
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
.Throws(new Exception());
//Act
@ -70,7 +73,7 @@ public void GetDailySeriesIds_should_return_empty_list_of_int_when_server_is_una
public void IsDailySeries_should_return_true()
{
//Setup
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv"))
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
.Returns(validSeriesIds);
//Act
@ -84,7 +87,7 @@ public void IsDailySeries_should_return_true()
public void IsDailySeries_should_return_false()
{
//Setup
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv"))
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
.Returns(validSeriesIds);
//Act
@ -107,7 +110,7 @@ public void UpdateDailySeries_should_update_series_that_match_daily_series_list(
Db.InsertMany(fakeSeries);
//Setup
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv"))
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
.Returns(validSeriesIds);
//Act
@ -138,7 +141,7 @@ public void UpdateDailySeries_should_update_series_should_skip_series_that_dont_
Db.InsertMany(fakeSeries);
//Setup
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv"))
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
.Returns(validSeriesIds);
//Act
@ -171,7 +174,7 @@ public void UpdateDailySeries_should_update_series_should_not_overwrite_existing
Db.InsertMany(fakeSeries);
//Setup
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv"))
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
.Returns(validSeriesIds);
//Act

View file

@ -4,7 +4,9 @@
using System.Linq;
using System.Text;
using NLog;
using Newtonsoft.Json;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using PetaPoco;
namespace NzbDrone.Core.Providers
@ -44,24 +46,9 @@ public List<int> GetDailySeriesIds()
{
try
{
var dailySeries = _httpProvider.DownloadString("http://www.nzbdrone.com/DailySeries.csv");
var dailySeriesIds = _httpProvider.DownloadString("http://services.nzbdrone.com/DailySeries/AllIds");
var seriesIds = new List<int>();
using (var reader = new StringReader(dailySeries))
{
string line;
while ((line = reader.ReadLine()) != null)
{
int seriesId;
//Split CSV, first item should be the seriesId
var split = line.Split(',');
if (Int32.TryParse(split[0], out seriesId))
seriesIds.Add(seriesId);
}
}
var seriesIds = JsonConvert.DeserializeObject<List<int>>(dailySeriesIds);
return seriesIds;
}