diff --git a/NzbDrone.Core.Test/ProviderTests/ReferenceDataProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/ReferenceDataProviderTest.cs index d61b52d7c..22b71b9e0 100644 --- a/NzbDrone.Core.Test/ProviderTests/ReferenceDataProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/ReferenceDataProviderTest.cs @@ -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().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv")) + Mocker.GetMock().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().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv")) + Mocker.GetMock().Setup(s => s.DownloadString(url)) .Returns(invalidSeriesIds); //Act var result = Mocker.Resolve().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().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv")) + Mocker.GetMock().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().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv")) + Mocker.GetMock().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().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv")) + Mocker.GetMock().Setup(s => s.DownloadString(url)) .Returns(validSeriesIds); //Act @@ -107,7 +110,7 @@ namespace NzbDrone.Core.Test.ProviderTests Db.InsertMany(fakeSeries); //Setup - Mocker.GetMock().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv")) + Mocker.GetMock().Setup(s => s.DownloadString(url)) .Returns(validSeriesIds); //Act @@ -138,7 +141,7 @@ namespace NzbDrone.Core.Test.ProviderTests Db.InsertMany(fakeSeries); //Setup - Mocker.GetMock().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv")) + Mocker.GetMock().Setup(s => s.DownloadString(url)) .Returns(validSeriesIds); //Act @@ -171,7 +174,7 @@ namespace NzbDrone.Core.Test.ProviderTests Db.InsertMany(fakeSeries); //Setup - Mocker.GetMock().Setup(s => s.DownloadString("http://www.nzbdrone.com/DailySeries.csv")) + Mocker.GetMock().Setup(s => s.DownloadString(url)) .Returns(validSeriesIds); //Act diff --git a/NzbDrone.Core/Providers/ReferenceDataProvider.cs b/NzbDrone.Core/Providers/ReferenceDataProvider.cs index 42889e228..a3cfb9a29 100644 --- a/NzbDrone.Core/Providers/ReferenceDataProvider.cs +++ b/NzbDrone.Core/Providers/ReferenceDataProvider.cs @@ -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(); - - 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>(dailySeriesIds); return seriesIds; }