diff --git a/NzbDrone.Core.Test/Integeration/ServiceIntegerationFixture.cs b/NzbDrone.Core.Test/Integeration/ServiceIntegerationFixture.cs new file mode 100644 index 000000000..f1d9ace6d --- /dev/null +++ b/NzbDrone.Core.Test/Integeration/ServiceIntegerationFixture.cs @@ -0,0 +1,56 @@ +using System.Linq; +using FluentAssertions; +using NUnit.Framework; +using Ninject; +using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Repository; +using NzbDrone.Core.Test.Framework; +using PetaPoco; + +namespace NzbDrone.Core.Test.Integeration +{ + [TestFixture(Category = "ServiceIngeneration")] + [Explicit] + public class ServiceIntegerationFixture : CoreTest + { + private KernelBase _kernel; + + [SetUp] + public void Setup() + { + WithRealDb(); + _kernel = new StandardKernel(); + _kernel.Bind().ToConstant(Db); + + Mocker.GetMock().SetupGet(s => s.ServiceRootUrl) + .Returns("http://stage.services.nzbdrone.com"); + + } + + [Test] + public void should_be_able_to_update_scene_mapping() + { + _kernel.Get().UpdateMappings(); + var mappings = Db.Fetch(); + + mappings.Should().NotBeEmpty(); + + mappings.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.CleanTitle)); + mappings.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.SceneName)); + mappings.Should().OnlyContain(c => c.SeriesId > 0); + } + + [Test] + public void should_be_able_to_get_daily_series_ids() + { + var dailySeries = _kernel.Get().GetDailySeriesIds(); + + dailySeries.Should().NotBeEmpty(); + dailySeries.Should().OnlyContain(c => c > 0); + } + + + + } +} \ No newline at end of file diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 96e638fe3..a8f67f5df 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -104,6 +104,7 @@ + diff --git a/NzbDrone.Core.Test/ProviderTests/ReferenceDataProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/ReferenceDataProviderTest.cs index 22b71b9e0..430afbc65 100644 --- a/NzbDrone.Core.Test/ProviderTests/ReferenceDataProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/ReferenceDataProviderTest.cs @@ -3,16 +3,12 @@ using FizzWare.NBuilder; using FluentAssertions; -using Moq; using NUnit.Framework; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; -using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common; -using NzbDrone.Test.Common.AutoMoq; -using PetaPoco; namespace NzbDrone.Core.Test.ProviderTests { @@ -25,6 +21,14 @@ public class ReferenceDataProviderTest : CoreTest private const string url = "http://services.nzbdrone.com/DailySeries/AllIds"; + [SetUp] + public void Setup() + { + Mocker.GetMock().SetupGet(s => s.ServiceRootUrl) + .Returns("http://services.nzbdrone.com"); + } + + [Test] public void GetDailySeriesIds_should_return_list_of_int_when_all_are_valid() { diff --git a/NzbDrone.Core.Test/ProviderTests/SceneMappingProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/SceneMappingProviderTest.cs index 9a9a37160..e3418e66e 100644 --- a/NzbDrone.Core.Test/ProviderTests/SceneMappingProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/SceneMappingProviderTest.cs @@ -19,6 +19,13 @@ public class SceneMappingProviderTest : CoreTest { private const string SceneMappingUrl = "http://services.nzbdrone.com/SceneMapping/Active"; + [SetUp] + public void Setup() + { + Mocker.GetMock().SetupGet(s => s.ServiceRootUrl) + .Returns("http://services.nzbdrone.com"); + } + private void WithValidJson() { Mocker.GetMock() diff --git a/NzbDrone.Core/Providers/Core/ConfigProvider.cs b/NzbDrone.Core/Providers/Core/ConfigProvider.cs index 95bd04216..1718037e3 100644 --- a/NzbDrone.Core/Providers/Core/ConfigProvider.cs +++ b/NzbDrone.Core/Providers/Core/ConfigProvider.cs @@ -422,6 +422,11 @@ public virtual string BlackholeDirectory set { SetValue("BlackholeDirectory", value); } } + public virtual string ServiceRootUrl + { + get { return "http://services.nzbdrone.com"; } + } + public string UGuid { get { return GetValue("UGuid", Guid.NewGuid().ToString(), persist: true); } diff --git a/NzbDrone.Core/Providers/ReferenceDataProvider.cs b/NzbDrone.Core/Providers/ReferenceDataProvider.cs index a3cfb9a29..814258064 100644 --- a/NzbDrone.Core/Providers/ReferenceDataProvider.cs +++ b/NzbDrone.Core/Providers/ReferenceDataProvider.cs @@ -15,13 +15,15 @@ public class ReferenceDataProvider { private readonly IDatabase _database; private readonly HttpProvider _httpProvider; - + private readonly ConfigProvider _configProvider; + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public ReferenceDataProvider(IDatabase database, HttpProvider httpProvider) + public ReferenceDataProvider(IDatabase database, HttpProvider httpProvider, ConfigProvider configProvider) { _database = database; _httpProvider = httpProvider; + _configProvider = configProvider; } public virtual void UpdateDailySeries() @@ -46,18 +48,18 @@ public List GetDailySeriesIds() { try { - var dailySeriesIds = _httpProvider.DownloadString("http://services.nzbdrone.com/DailySeries/AllIds"); + var dailySeriesIds = _httpProvider.DownloadString(_configProvider.ServiceRootUrl + "/DailySeries/AllIds"); var seriesIds = JsonConvert.DeserializeObject>(dailySeriesIds); return seriesIds; } - catch(Exception ex) + catch (Exception ex) { Logger.WarnException("Failed to get Daily Series", ex); return new List(); } - + } } } diff --git a/NzbDrone.Core/Providers/SceneMappingProvider.cs b/NzbDrone.Core/Providers/SceneMappingProvider.cs index 82ca68809..17074dd23 100644 --- a/NzbDrone.Core/Providers/SceneMappingProvider.cs +++ b/NzbDrone.Core/Providers/SceneMappingProvider.cs @@ -14,11 +14,13 @@ public class SceneMappingProvider private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private readonly IDatabase _database; private readonly HttpProvider _httpProvider; + private readonly ConfigProvider _configProvider; - public SceneMappingProvider(IDatabase database, HttpProvider httpProvider) + public SceneMappingProvider(IDatabase database, HttpProvider httpProvider, ConfigProvider configProvider) { _database = database; _httpProvider = httpProvider; + _configProvider = configProvider; } public SceneMappingProvider() @@ -30,9 +32,7 @@ public virtual bool UpdateMappings() { try { - const string url = "http://services.nzbdrone.com/SceneMapping/Active"; - - var mappingsJson = _httpProvider.DownloadString(url); + var mappingsJson = _httpProvider.DownloadString(_configProvider.ServiceRootUrl + "/SceneMapping/Active"); var mappings = JsonConvert.DeserializeObject>(mappingsJson); Logger.Debug("Deleting all existing Scene Mappings.");