mirror of
https://github.com/Sonarr/Sonarr
synced 2025-01-02 21:24:56 +00:00
Fixed issue with validation when rename episodes is false
This commit is contained in:
parent
fbf91fe8f5
commit
7a5cee5b8e
3 changed files with 40 additions and 12 deletions
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using FluentValidation.Results;
|
using FluentValidation.Results;
|
||||||
using Nancy.Responses;
|
using Nancy.Responses;
|
||||||
|
@ -31,8 +32,12 @@ namespace NzbDrone.Api.Config
|
||||||
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);
|
||||||
SharedValidator.RuleFor(c => c.StandardEpisodeFormat).ValidEpisodeFormat();
|
|
||||||
SharedValidator.RuleFor(c => c.DailyEpisodeFormat).ValidDailyEpisodeFormat();
|
SharedValidator.When(spec => spec.RenameEpisodes, () =>
|
||||||
|
{
|
||||||
|
SharedValidator.RuleFor(c => c.StandardEpisodeFormat).ValidEpisodeFormat();
|
||||||
|
SharedValidator.RuleFor(c => c.DailyEpisodeFormat).ValidDailyEpisodeFormat();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateNamingConfig(NamingConfigResource resource)
|
private void UpdateNamingConfig(NamingConfigResource resource)
|
||||||
|
@ -104,7 +109,10 @@ namespace NzbDrone.Api.Config
|
||||||
validationFailures.Add(dailyEpisodeValidationResult);
|
validationFailures.Add(dailyEpisodeValidationResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ValidationException(validationFailures.ToArray());
|
if (validationFailures.Any())
|
||||||
|
{
|
||||||
|
throw new ValidationException(validationFailures.ToArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace NzbDrone.Integration.Test
|
||||||
public void should_get_bad_request_if_standard_format_is_empty()
|
public void should_get_bad_request_if_standard_format_is_empty()
|
||||||
{
|
{
|
||||||
var config = NamingConfig.GetSingle();
|
var config = NamingConfig.GetSingle();
|
||||||
config.RenameEpisodes = false;
|
config.RenameEpisodes = true;
|
||||||
config.StandardEpisodeFormat = "";
|
config.StandardEpisodeFormat = "";
|
||||||
config.DailyEpisodeFormat = "{Series Title} - {Air-Date} - {Episode Title}";
|
config.DailyEpisodeFormat = "{Series Title} - {Air-Date} - {Episode Title}";
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ namespace NzbDrone.Integration.Test
|
||||||
public void should_get_bad_request_if_standard_format_doesnt_contain_season_and_episode()
|
public void should_get_bad_request_if_standard_format_doesnt_contain_season_and_episode()
|
||||||
{
|
{
|
||||||
var config = NamingConfig.GetSingle();
|
var config = NamingConfig.GetSingle();
|
||||||
config.RenameEpisodes = false;
|
config.RenameEpisodes = true;
|
||||||
config.StandardEpisodeFormat = "{season}";
|
config.StandardEpisodeFormat = "{season}";
|
||||||
config.DailyEpisodeFormat = "{Series Title} - {Air-Date} - {Episode Title}";
|
config.DailyEpisodeFormat = "{Series Title} - {Air-Date} - {Episode Title}";
|
||||||
|
|
||||||
|
@ -65,12 +65,38 @@ namespace NzbDrone.Integration.Test
|
||||||
public void should_get_bad_request_if_daily_format_doesnt_contain_season_and_episode_or_air_date()
|
public void should_get_bad_request_if_daily_format_doesnt_contain_season_and_episode_or_air_date()
|
||||||
{
|
{
|
||||||
var config = NamingConfig.GetSingle();
|
var config = NamingConfig.GetSingle();
|
||||||
config.RenameEpisodes = false;
|
config.RenameEpisodes = true;
|
||||||
config.StandardEpisodeFormat = "{Series Title} - {season}x{episode:00} - {Episode Title}";
|
config.StandardEpisodeFormat = "{Series Title} - {season}x{episode:00} - {Episode Title}";
|
||||||
config.DailyEpisodeFormat = "{Series Title} - {season} - {Episode Title}";
|
config.DailyEpisodeFormat = "{Series Title} - {season} - {Episode Title}";
|
||||||
|
|
||||||
var errors = NamingConfig.InvalidPut(config);
|
var errors = NamingConfig.InvalidPut(config);
|
||||||
errors.Should().NotBeEmpty();
|
errors.Should().NotBeEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_require_format_when_rename_episodes_is_false()
|
||||||
|
{
|
||||||
|
var config = NamingConfig.GetSingle();
|
||||||
|
config.RenameEpisodes = false;
|
||||||
|
config.StandardEpisodeFormat = "";
|
||||||
|
config.DailyEpisodeFormat = "";
|
||||||
|
|
||||||
|
var result = NamingConfig.Put(config);
|
||||||
|
result.RenameEpisodes.Should().BeFalse();
|
||||||
|
result.StandardEpisodeFormat.Should().Be(config.StandardEpisodeFormat);
|
||||||
|
result.DailyEpisodeFormat.Should().Be(config.DailyEpisodeFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_require_format_when_rename_episodes_is_true()
|
||||||
|
{
|
||||||
|
var config = NamingConfig.GetSingle();
|
||||||
|
config.RenameEpisodes = true;
|
||||||
|
config.StandardEpisodeFormat = "";
|
||||||
|
config.DailyEpisodeFormat = "";
|
||||||
|
|
||||||
|
var errors = NamingConfig.InvalidPut(config);
|
||||||
|
errors.Should().NotBeEmpty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,9 +8,6 @@ namespace NzbDrone.Integration.Test
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class RootFolderIntegrationTest : IntegrationTest
|
public class RootFolderIntegrationTest : IntegrationTest
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void should_have_no_root_folder_initially()
|
public void should_have_no_root_folder_initially()
|
||||||
{
|
{
|
||||||
|
@ -20,7 +17,6 @@ namespace NzbDrone.Integration.Test
|
||||||
[Test]
|
[Test]
|
||||||
public void should_add_and_delete_root_folders()
|
public void should_add_and_delete_root_folders()
|
||||||
{
|
{
|
||||||
|
|
||||||
ConnectSignalR();
|
ConnectSignalR();
|
||||||
|
|
||||||
var rootFolder = new RootFolderResource
|
var rootFolder = new RootFolderResource
|
||||||
|
@ -42,8 +38,6 @@ namespace NzbDrone.Integration.Test
|
||||||
|
|
||||||
|
|
||||||
SignalRMessages.Should().Contain(c => c.Name == "rootfolder");
|
SignalRMessages.Should().Contain(c => c.Name == "rootfolder");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
Loading…
Reference in a new issue