DailySeries now use the JSON API instead of the CSV file.
This commit is contained in:
parent
afb8305c00
commit
ad4afbcb6d
|
@ -20,14 +20,16 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
public class ReferenceDataProviderTest : CoreTest
|
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 const string validSeriesIds = "[1,2,3,4,5]";
|
||||||
private string invalidSeriesIds = String.Format("1,Test{0}2,Test{0}NaN,Test{0}4,Test{0}5,Test", Environment.NewLine);
|
private const string invalidSeriesIds = "[1,2,NaN,4,5]";
|
||||||
|
|
||||||
|
private const string url = "http://services.nzbdrone.com/DailySeries/AllIds";
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void GetDailySeriesIds_should_return_list_of_int_when_all_are_valid()
|
public void GetDailySeriesIds_should_return_list_of_int_when_all_are_valid()
|
||||||
{
|
{
|
||||||
//Setup
|
//Setup
|
||||||
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv"))
|
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
|
||||||
.Returns(validSeriesIds);
|
.Returns(validSeriesIds);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
|
@ -38,24 +40,25 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[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
|
//Setup
|
||||||
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv"))
|
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
|
||||||
.Returns(invalidSeriesIds);
|
.Returns(invalidSeriesIds);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var result = Mocker.Resolve<ReferenceDataProvider>().GetDailySeriesIds();
|
var result = Mocker.Resolve<ReferenceDataProvider>().GetDailySeriesIds();
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
result.Should().HaveCount(4);
|
result.Should().BeEmpty();
|
||||||
|
ExceptionVerification.ExpectedWarns(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void GetDailySeriesIds_should_return_empty_list_of_int_when_server_is_unavailable()
|
public void GetDailySeriesIds_should_return_empty_list_of_int_when_server_is_unavailable()
|
||||||
{
|
{
|
||||||
//Setup
|
//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());
|
.Throws(new Exception());
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
|
@ -70,7 +73,7 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
public void IsDailySeries_should_return_true()
|
public void IsDailySeries_should_return_true()
|
||||||
{
|
{
|
||||||
//Setup
|
//Setup
|
||||||
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv"))
|
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
|
||||||
.Returns(validSeriesIds);
|
.Returns(validSeriesIds);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
|
@ -84,7 +87,7 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
public void IsDailySeries_should_return_false()
|
public void IsDailySeries_should_return_false()
|
||||||
{
|
{
|
||||||
//Setup
|
//Setup
|
||||||
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv"))
|
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
|
||||||
.Returns(validSeriesIds);
|
.Returns(validSeriesIds);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
|
@ -107,7 +110,7 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
Db.InsertMany(fakeSeries);
|
Db.InsertMany(fakeSeries);
|
||||||
|
|
||||||
//Setup
|
//Setup
|
||||||
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv"))
|
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
|
||||||
.Returns(validSeriesIds);
|
.Returns(validSeriesIds);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
|
@ -138,7 +141,7 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
Db.InsertMany(fakeSeries);
|
Db.InsertMany(fakeSeries);
|
||||||
|
|
||||||
//Setup
|
//Setup
|
||||||
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv"))
|
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
|
||||||
.Returns(validSeriesIds);
|
.Returns(validSeriesIds);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
|
@ -171,7 +174,7 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
Db.InsertMany(fakeSeries);
|
Db.InsertMany(fakeSeries);
|
||||||
|
|
||||||
//Setup
|
//Setup
|
||||||
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv"))
|
Mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(url))
|
||||||
.Returns(validSeriesIds);
|
.Returns(validSeriesIds);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
|
|
|
@ -4,7 +4,9 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using NzbDrone.Core.Providers.Core;
|
using NzbDrone.Core.Providers.Core;
|
||||||
|
using NzbDrone.Core.Repository;
|
||||||
using PetaPoco;
|
using PetaPoco;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Providers
|
namespace NzbDrone.Core.Providers
|
||||||
|
@ -44,24 +46,9 @@ namespace NzbDrone.Core.Providers
|
||||||
{
|
{
|
||||||
try
|
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>();
|
var seriesIds = JsonConvert.DeserializeObject<List<int>>(dailySeriesIds);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return seriesIds;
|
return seriesIds;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue