Naming config fixed, with integration tests

pull/3113/head
Mark McDowall 11 years ago
parent 1e3a308917
commit dd37713a10

@ -22,10 +22,9 @@ namespace NzbDrone.Api.Config
_namingConfigService = namingConfigService; _namingConfigService = namingConfigService;
_buildFileNames = buildFileNames; _buildFileNames = buildFileNames;
GetResourceSingle = GetNamingConfig; GetResourceSingle = GetNamingConfig;
GetResourceById = GetNamingConfig;
UpdateResource = UpdateNamingConfig; UpdateResource = UpdateNamingConfig;
Get["/samples"] = x => GetExamples(this.Bind<NamingConfigResource>()); Get["/samples"] = x => GetExamples(this.Bind<NamingConfigResource>());
SharedValidator.RuleFor(c => c.MultiEpisodeStyle).InclusiveBetween(0, 3); SharedValidator.RuleFor(c => c.MultiEpisodeStyle).InclusiveBetween(0, 3);
@ -35,7 +34,7 @@ namespace NzbDrone.Api.Config
private void UpdateNamingConfig(NamingConfigResource resource) private void UpdateNamingConfig(NamingConfigResource resource)
{ {
GetNewId<NamingConfig>(_namingConfigService.Save, resource); _namingConfigService.Save(resource.InjectTo<NamingConfig>());
} }
private NamingConfigResource GetNamingConfig() private NamingConfigResource GetNamingConfig()
@ -43,6 +42,11 @@ namespace NzbDrone.Api.Config
return _namingConfigService.GetConfig().InjectTo<NamingConfigResource>(); return _namingConfigService.GetConfig().InjectTo<NamingConfigResource>();
} }
private NamingConfigResource GetNamingConfig(int id)
{
return GetNamingConfig();
}
private JsonResponse<NamingSampleResource> GetExamples(NamingConfigResource config) private JsonResponse<NamingSampleResource> GetExamples(NamingConfigResource config)
{ {
var nameSpec = config.InjectTo<NamingConfig>(); var nameSpec = config.InjectTo<NamingConfig>();

@ -21,7 +21,6 @@ namespace NzbDrone.Api
PutValidator.RuleFor(r => r.Id).ValidId(); PutValidator.RuleFor(r => r.Id).ValidId();
} }
protected int GetNewId<TModel>(Func<TModel, TModel> function, TResource resource) where TModel : ModelBase, new() protected int GetNewId<TModel>(Func<TModel, TModel> function, TResource resource) where TModel : ModelBase, new()
{ {
var model = resource.InjectTo<TModel>(); var model = resource.InjectTo<TModel>();
@ -35,7 +34,6 @@ namespace NzbDrone.Api
return modelList.InjectTo<List<TResource>>(); return modelList.InjectTo<List<TResource>>();
} }
protected PagingResource<TResource> ApplyToPage<TModel>(Func<PagingSpec<TModel>, PagingSpec<TModel>> function, PagingSpec<TModel> pagingSpec) where TModel : ModelBase, new() protected PagingResource<TResource> ApplyToPage<TModel>(Func<PagingSpec<TModel>, PagingSpec<TModel>> function, PagingSpec<TModel> pagingSpec) where TModel : ModelBase, new()
{ {
pagingSpec = function(pagingSpec); pagingSpec = function(pagingSpec);

@ -55,6 +55,12 @@ namespace NzbDrone.Integration.Test.Client
return Get<TResource>(request, statusCode); return Get<TResource>(request, statusCode);
} }
public TResource GetSingle(HttpStatusCode statusCode = HttpStatusCode.OK)
{
var request = BuildRequest();
return Get<TResource>(request, statusCode);
}
public void Delete(int id) public void Delete(int id)
{ {
var request = BuildRequest(id.ToString()); var request = BuildRequest(id.ToString());

@ -11,7 +11,5 @@ namespace NzbDrone.Integration.Test
{ {
Commands.Post(new CommandResource {Command = "rsssync"}); Commands.Post(new CommandResource {Command = "rsssync"});
} }
} }
} }

@ -3,7 +3,7 @@ using NLog.Config;
using NLog.Targets; using NLog.Targets;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Api.Commands; using NzbDrone.Api.Commands;
using NzbDrone.Api.Episodes; using NzbDrone.Api.Config;
using NzbDrone.Api.RootFolders; using NzbDrone.Api.RootFolders;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Integration.Test.Client; using NzbDrone.Integration.Test.Client;
@ -25,10 +25,10 @@ namespace NzbDrone.Integration.Test
protected IndexerClient Indexers; protected IndexerClient Indexers;
protected EpisodeClient Episodes; protected EpisodeClient Episodes;
protected SeasonClient Seasons; protected SeasonClient Seasons;
protected ClientBase<NamingConfigResource> NamingConfig;
private NzbDroneRunner _runner; private NzbDroneRunner _runner;
public IntegrationTest() public IntegrationTest()
{ {
new StartupArguments(); new StartupArguments();
@ -42,7 +42,6 @@ namespace NzbDrone.Integration.Test
[SetUp] [SetUp]
public void SmokeTestSetup() public void SmokeTestSetup()
{ {
_runner = new NzbDroneRunner(); _runner = new NzbDroneRunner();
_runner.KillAll(); _runner.KillAll();
@ -51,7 +50,6 @@ namespace NzbDrone.Integration.Test
_runner.Start(); _runner.Start();
} }
private void InitRestClients() private void InitRestClients()
{ {
RestClient = new RestClient("http://localhost:8989/api"); RestClient = new RestClient("http://localhost:8989/api");
@ -62,6 +60,7 @@ namespace NzbDrone.Integration.Test
Indexers = new IndexerClient(RestClient); Indexers = new IndexerClient(RestClient);
Episodes = new EpisodeClient(RestClient); Episodes = new EpisodeClient(RestClient);
Seasons = new SeasonClient(RestClient); Seasons = new SeasonClient(RestClient);
NamingConfig = new ClientBase<NamingConfigResource>(RestClient, "config/naming");
} }
[TearDown] [TearDown]

@ -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();
}
}
}

@ -99,6 +99,7 @@
<Compile Include="Client\ReleaseClient.cs" /> <Compile Include="Client\ReleaseClient.cs" />
<Compile Include="Client\SeriesClient.cs" /> <Compile Include="Client\SeriesClient.cs" />
<Compile Include="CommandIntegerationTests.cs" /> <Compile Include="CommandIntegerationTests.cs" />
<Compile Include="NamingConfigTests.cs" />
<Compile Include="SeasonIntegrationTests.cs" /> <Compile Include="SeasonIntegrationTests.cs" />
<Compile Include="EpisodeIntegrationTests.cs" /> <Compile Include="EpisodeIntegrationTests.cs" />
<Compile Include="IndexerIntegrationFixture.cs" /> <Compile Include="IndexerIntegrationFixture.cs" />

Loading…
Cancel
Save