From dd37713a10bc21d9697e579ceac63d2b39ecf8e6 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 27 Aug 2013 17:16:24 -0700 Subject: [PATCH] Naming config fixed, with integration tests --- NzbDrone.Api/Config/NamingModule.cs | 10 ++++-- NzbDrone.Api/NzbDroneRestModule.cs | 2 -- .../Client/ClientBase.cs | 6 ++++ .../CommandIntegerationTests.cs | 2 -- NzbDrone.Integration.Test/IntegrationTest.cs | 7 ++-- .../NamingConfigTests.cs | 35 +++++++++++++++++++ .../NzbDrone.Integration.Test.csproj | 1 + 7 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 NzbDrone.Integration.Test/NamingConfigTests.cs 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 @@ namespace NzbDrone.Api.Config _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 @@ namespace NzbDrone.Api.Config private void UpdateNamingConfig(NamingConfigResource resource) { - GetNewId(_namingConfigService.Save, resource); + _namingConfigService.Save(resource.InjectTo()); } private NamingConfigResource GetNamingConfig() @@ -43,6 +42,11 @@ namespace NzbDrone.Api.Config 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 @@ namespace NzbDrone.Api 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 @@ namespace NzbDrone.Api 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 @@ namespace NzbDrone.Integration.Test.Client 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 @@ namespace NzbDrone.Integration.Test { 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.Config; 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 @@ namespace NzbDrone.Integration.Test protected IndexerClient Indexers; protected EpisodeClient Episodes; protected SeasonClient Seasons; + protected ClientBase NamingConfig; private NzbDroneRunner _runner; - public IntegrationTest() { new StartupArguments(); @@ -42,7 +42,6 @@ namespace NzbDrone.Integration.Test [SetUp] public void SmokeTestSetup() { - _runner = new NzbDroneRunner(); _runner.KillAll(); @@ -51,7 +50,6 @@ namespace NzbDrone.Integration.Test _runner.Start(); } - private void InitRestClients() { RestClient = new RestClient("http://localhost:8989/api"); @@ -62,6 +60,7 @@ namespace NzbDrone.Integration.Test 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 @@ +