From 7bb8a9db5fb0d190a0ef32abf76e23b2c6574c78 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 17 Jan 2014 10:43:15 -0800 Subject: [PATCH] Validation and integration test for SeriesFolderFormat --- src/NzbDrone.Api/Config/NamingModule.cs | 2 +- src/NzbDrone.Core/Organizer/FileNameBuilder.cs | 3 +++ src/NzbDrone.Core/Organizer/FileNameValidation.cs | 6 ++++++ src/NzbDrone.Integration.Test/NamingConfigTests.cs | 11 +++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Api/Config/NamingModule.cs b/src/NzbDrone.Api/Config/NamingModule.cs index 1f0b39fac..f340f5ab9 100644 --- a/src/NzbDrone.Api/Config/NamingModule.cs +++ b/src/NzbDrone.Api/Config/NamingModule.cs @@ -4,7 +4,6 @@ using FluentValidation; using FluentValidation.Results; using Nancy.Responses; -using NzbDrone.Api.REST; using NzbDrone.Core.Organizer; using Nancy.ModelBinding; using NzbDrone.Api.Mapping; @@ -39,6 +38,7 @@ public NamingModule(INamingConfigService namingConfigService, SharedValidator.RuleFor(c => c.MultiEpisodeStyle).InclusiveBetween(0, 3); SharedValidator.RuleFor(c => c.StandardEpisodeFormat).ValidEpisodeFormat(); SharedValidator.RuleFor(c => c.DailyEpisodeFormat).ValidDailyEpisodeFormat(); + SharedValidator.RuleFor(c => c.SeriesFolderFormat).ValidSeriesFolderFormat(); } private void UpdateNamingConfig(NamingConfigResource resource) diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index 905b73456..fa156552a 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -39,6 +39,9 @@ public class FileNameBuilder : IBuildFileNames public static readonly Regex AirDateRegex = new Regex(@"\{Air(\s|\W|_)Date\}", RegexOptions.Compiled | RegexOptions.IgnoreCase); + public static readonly Regex SeriesTitleRegex = new Regex(@"(?\{(?:Series)(?\s|\.|-|_)Title\})", + RegexOptions.Compiled | RegexOptions.IgnoreCase); + public FileNameBuilder(INamingConfigService namingConfigService, ICacheManger cacheManger, Logger logger) diff --git a/src/NzbDrone.Core/Organizer/FileNameValidation.cs b/src/NzbDrone.Core/Organizer/FileNameValidation.cs index 0eceb9564..9a291e05c 100644 --- a/src/NzbDrone.Core/Organizer/FileNameValidation.cs +++ b/src/NzbDrone.Core/Organizer/FileNameValidation.cs @@ -17,6 +17,12 @@ public static IRuleBuilderOptions ValidDailyEpisodeFormat(this IRu ruleBuilder.SetValidator(new NotEmptyValidator(null)); return ruleBuilder.SetValidator(new ValidDailyEpisodeFormatValidator()); } + + public static IRuleBuilderOptions ValidSeriesFolderFormat(this IRuleBuilder ruleBuilder) + { + ruleBuilder.SetValidator(new NotEmptyValidator(null)); + return ruleBuilder.SetValidator(new RegularExpressionValidator(FileNameBuilder.SeriesTitleRegex)).WithMessage("Must contain series title"); + } } public class ValidDailyEpisodeFormatValidator : PropertyValidator diff --git a/src/NzbDrone.Integration.Test/NamingConfigTests.cs b/src/NzbDrone.Integration.Test/NamingConfigTests.cs index 3f351bb68..5dc9a2fb0 100644 --- a/src/NzbDrone.Integration.Test/NamingConfigTests.cs +++ b/src/NzbDrone.Integration.Test/NamingConfigTests.cs @@ -96,5 +96,16 @@ public void should_require_format_when_rename_episodes_is_true() var errors = NamingConfig.InvalidPut(config); errors.Should().NotBeEmpty(); } + + [Test] + public void should_get_bad_request_if_series_folder_format_does_not_contain_series_title() + { + var config = NamingConfig.GetSingle(); + config.RenameEpisodes = true; + config.SeriesFolderFormat = "This and That"; + + var errors = NamingConfig.InvalidPut(config); + errors.Should().NotBeEmpty(); + } } } \ No newline at end of file