diff --git a/NzbDrone.Api/Config/NamingModule.cs b/NzbDrone.Api/Config/NamingModule.cs index 65f674b49..726a268b5 100644 --- a/NzbDrone.Api/Config/NamingModule.cs +++ b/NzbDrone.Api/Config/NamingModule.cs @@ -22,10 +22,9 @@ public NamingModule(INamingConfigService namingConfigService, IBuildFileNames bu _namingConfigService = namingConfigService; _buildFileNames = buildFileNames; GetResourceSingle = GetNamingConfig; - + GetResourceById = GetNamingConfig; UpdateResource = UpdateNamingConfig; - Get["/samples"] = x => GetExamples(this.Bind()); SharedValidator.RuleFor(c => c.MultiEpisodeStyle).InclusiveBetween(0, 3); @@ -35,7 +34,7 @@ public NamingModule(INamingConfigService namingConfigService, IBuildFileNames bu private void UpdateNamingConfig(NamingConfigResource resource) { - GetNewId(_namingConfigService.Save, resource); + _namingConfigService.Save(resource.InjectTo()); } private NamingConfigResource GetNamingConfig() @@ -43,6 +42,11 @@ private NamingConfigResource GetNamingConfig() return _namingConfigService.GetConfig().InjectTo(); } + private NamingConfigResource GetNamingConfig(int id) + { + return GetNamingConfig(); + } + private JsonResponse GetExamples(NamingConfigResource config) { var nameSpec = config.InjectTo(); diff --git a/NzbDrone.Api/NzbDroneRestModule.cs b/NzbDrone.Api/NzbDroneRestModule.cs index d8072c4b2..b4b01aee5 100644 --- a/NzbDrone.Api/NzbDroneRestModule.cs +++ b/NzbDrone.Api/NzbDroneRestModule.cs @@ -21,7 +21,6 @@ protected NzbDroneRestModule(string resource) PutValidator.RuleFor(r => r.Id).ValidId(); } - protected int GetNewId(Func function, TResource resource) where TModel : ModelBase, new() { var model = resource.InjectTo(); @@ -35,7 +34,6 @@ protected NzbDroneRestModule(string resource) return modelList.InjectTo>(); } - protected PagingResource ApplyToPage(Func, PagingSpec> function, PagingSpec pagingSpec) where TModel : ModelBase, new() { pagingSpec = function(pagingSpec); diff --git a/NzbDrone.Integration.Test/Client/ClientBase.cs b/NzbDrone.Integration.Test/Client/ClientBase.cs index 1483f9ad4..05ca16711 100644 --- a/NzbDrone.Integration.Test/Client/ClientBase.cs +++ b/NzbDrone.Integration.Test/Client/ClientBase.cs @@ -55,6 +55,12 @@ public TResource Get(int id, HttpStatusCode statusCode = HttpStatusCode.OK) return Get(request, statusCode); } + public TResource GetSingle(HttpStatusCode statusCode = HttpStatusCode.OK) + { + var request = BuildRequest(); + return Get(request, statusCode); + } + public void Delete(int id) { var request = BuildRequest(id.ToString()); diff --git a/NzbDrone.Integration.Test/CommandIntegerationTests.cs b/NzbDrone.Integration.Test/CommandIntegerationTests.cs index 7899393d8..c1e06bac1 100644 --- a/NzbDrone.Integration.Test/CommandIntegerationTests.cs +++ b/NzbDrone.Integration.Test/CommandIntegerationTests.cs @@ -11,7 +11,5 @@ public void should_be_able_to_run_rss_sync() { Commands.Post(new CommandResource {Command = "rsssync"}); } - - } } \ No newline at end of file diff --git a/NzbDrone.Integration.Test/IntegrationTest.cs b/NzbDrone.Integration.Test/IntegrationTest.cs index b705146b6..3ef126a98 100644 --- a/NzbDrone.Integration.Test/IntegrationTest.cs +++ b/NzbDrone.Integration.Test/IntegrationTest.cs @@ -3,7 +3,7 @@ using NLog.Targets; using NUnit.Framework; using NzbDrone.Api.Commands; -using NzbDrone.Api.Episodes; +using NzbDrone.Api.Config; using NzbDrone.Api.RootFolders; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Integration.Test.Client; @@ -25,10 +25,10 @@ public abstract class IntegrationTest protected IndexerClient Indexers; protected EpisodeClient Episodes; protected SeasonClient Seasons; + protected ClientBase NamingConfig; private NzbDroneRunner _runner; - public IntegrationTest() { new StartupArguments(); @@ -42,7 +42,6 @@ public IntegrationTest() [SetUp] public void SmokeTestSetup() { - _runner = new NzbDroneRunner(); _runner.KillAll(); @@ -51,7 +50,6 @@ public void SmokeTestSetup() _runner.Start(); } - private void InitRestClients() { RestClient = new RestClient("http://localhost:8989/api"); @@ -62,6 +60,7 @@ private void InitRestClients() Indexers = new IndexerClient(RestClient); Episodes = new EpisodeClient(RestClient); Seasons = new SeasonClient(RestClient); + NamingConfig = new ClientBase(RestClient, "config/naming"); } [TearDown] diff --git a/NzbDrone.Integration.Test/NamingConfigTests.cs b/NzbDrone.Integration.Test/NamingConfigTests.cs new file mode 100644 index 000000000..573eaf2ed --- /dev/null +++ b/NzbDrone.Integration.Test/NamingConfigTests.cs @@ -0,0 +1,35 @@ +using System; +using System.IO; +using FluentAssertions; +using NUnit.Framework; + +namespace NzbDrone.Integration.Test +{ + [TestFixture] + public class NamingConfigTests : IntegrationTest + { + + [Test] + public void should_be_able_to_get() + { + NamingConfig.GetSingle().Should().NotBeNull(); + } + + [Test] + public void should_be_able_to_get_by_id() + { + var config = NamingConfig.GetSingle(); + NamingConfig.Get(config.Id).Should().NotBeNull(); + NamingConfig.Get(config.Id).Id.Should().Be(config.Id); + } + + [Test] + public void should_be_able_to_update() + { + var config = NamingConfig.GetSingle(); + config.RenameEpisodes = false; + + NamingConfig.Put(config).RenameEpisodes.Should().BeFalse(); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Integration.Test/NzbDrone.Integration.Test.csproj b/NzbDrone.Integration.Test/NzbDrone.Integration.Test.csproj index 04ce2753c..2ffdbc7a9 100644 --- a/NzbDrone.Integration.Test/NzbDrone.Integration.Test.csproj +++ b/NzbDrone.Integration.Test/NzbDrone.Integration.Test.csproj @@ -99,6 +99,7 @@ +