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

pull/2/head
Mark McDowall 13 years ago
parent afb8305c00
commit ad4afbcb6d

@ -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 @@ namespace NzbDrone.Core.Test.ProviderTests
}
[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 @@ namespace NzbDrone.Core.Test.ProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests
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 @@ namespace NzbDrone.Core.Test.ProviderTests
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

@ -4,7 +4,9 @@ using System.IO;
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 @@ namespace NzbDrone.Core.Providers
{
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;
}

Loading…
Cancel
Save