diff --git a/src/NzbDrone.Core.Test/Datastore/Migration/106_update_btn_urlFixture.cs b/src/NzbDrone.Core.Test/Datastore/Migration/106_update_btn_urlFixture.cs new file mode 100644 index 000000000..3b719d42e --- /dev/null +++ b/src/NzbDrone.Core.Test/Datastore/Migration/106_update_btn_urlFixture.cs @@ -0,0 +1,62 @@ +using System.Linq; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Common.Serializer; +using NzbDrone.Core.Datastore.Migration; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.Datastore.Migration +{ + [TestFixture] + public class update_btn_url_migration_fixture : MigrationTest + { + [TestCase("http://api.btnapps.net")] + [TestCase("https://api.btnapps.net")] + [TestCase("http://api.btnapps.net/")] + [TestCase("https://api.btnapps.net/")] + public void should_replace_old_url(string oldUrl) + { + var db = WithMigrationTestDb(c => + { + c.Insert.IntoTable("Indexers").Row(new + { + Name = "btn_old_url", + Implementation = "BroadcastheNet", + Settings = new BroadcastheNetSettings106 + { + BaseUrl = oldUrl + }.ToJson(), + ConfigContract = "BroadcastheNetSettings" + }); + }); + + var items = db.Query("SELECT * FROM Indexers"); + + items.Should().HaveCount(1); + items.First().Settings.ToObject().BaseUrl.Should().Contain("api.broadcasthe.net"); + } + + [Test] + public void should_not_replace_other_indexers() + { + var db = WithMigrationTestDb(c => + { + c.Insert.IntoTable("Indexers").Row(new + { + Name = "not_btn", + Implementation = "NotBroadcastheNet", + Settings = new BroadcastheNetSettings106 + { + BaseUrl = "http://api.btnapps.net", + }.ToJson(), + ConfigContract = "BroadcastheNetSettings" + }); + }); + + var items = db.Query("SELECT * FROM Indexers"); + + items.Should().HaveCount(1); + items.First().Settings.ToObject().BaseUrl.Should().Be("http://api.btnapps.net"); + } + } +} diff --git a/src/NzbDrone.Core.Test/IndexerTests/BroadcastheNetTests/BroadcastheNetFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/BroadcastheNetTests/BroadcastheNetFixture.cs index a22ba44e3..e1b43d988 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/BroadcastheNetTests/BroadcastheNetFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/BroadcastheNetTests/BroadcastheNetFixture.cs @@ -21,7 +21,7 @@ public void Setup() Subject.Definition = new IndexerDefinition() { Name = "BroadcastheNet", - Settings = new BroadcastheNetSettings() { ApiKey = "abc", BaseUrl = "https://api.btnapps.net/" } + Settings = new BroadcastheNetSettings() { ApiKey = "abc", BaseUrl = "https://api.broadcasthe.net/" } }; } @@ -139,7 +139,7 @@ public void should_replace_https_http_as_needed() { var recentFeed = ReadAllText(@"Files/Indexers/BroadcastheNet/RecentFeed.json"); - (Subject.Definition.Settings as BroadcastheNetSettings).BaseUrl = "http://api.btnapps.net/"; + (Subject.Definition.Settings as BroadcastheNetSettings).BaseUrl = "http://api.broadcasthe.net/"; recentFeed = recentFeed.Replace("http:", "https:"); diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 0526f7826..12a21d6b3 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -124,6 +124,7 @@ + diff --git a/src/NzbDrone.Core/Datastore/Migration/106_update_btn_url.cs b/src/NzbDrone.Core/Datastore/Migration/106_update_btn_url.cs new file mode 100644 index 000000000..f2989a2c8 --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/106_update_btn_url.cs @@ -0,0 +1,22 @@ +using FluentMigrator; +using Newtonsoft.Json.Linq; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(106)] + public class update_btn_url : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Execute.Sql("UPDATE Indexers SET Settings = Replace(Settings, 'api.btnapps.net', 'api.broadcasthe.net') WHERE Implementation = 'BroadcastheNet';"); + } + } + + public class BroadcastheNetSettings106 + { + public string BaseUrl { get; set; } + + public string ApiKey { get; set; } + } +} diff --git a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetSettings.cs b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetSettings.cs index ba3d2f969..620ce9887 100644 --- a/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetSettings.cs +++ b/src/NzbDrone.Core/Indexers/BroadcastheNet/BroadcastheNetSettings.cs @@ -20,7 +20,7 @@ public class BroadcastheNetSettings : IProviderConfig public BroadcastheNetSettings() { - BaseUrl = "http://api.btnapps.net/"; + BaseUrl = "http://api.broadcasthe.net/"; } [FieldDefinition(0, Label = "API URL", Advanced = true, HelpText = "Do not change this unless you know what you're doing. Since your API key will be sent to that host.")] @@ -34,4 +34,4 @@ public NzbDroneValidationResult Validate() return new NzbDroneValidationResult(Validator.Validate(this)); } } -} \ No newline at end of file +} diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index d057bb822..489e4d528 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -249,6 +249,7 @@ +