mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Validation and integration test for SeriesFolderFormat
This commit is contained in:
parent
43a2f39106
commit
7bb8a9db5f
@ -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)
|
||||
|
@ -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(@"(?<token>\{(?:Series)(?<separator>\s|\.|-|_)Title\})",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public FileNameBuilder(INamingConfigService namingConfigService,
|
||||
ICacheManger cacheManger,
|
||||
Logger logger)
|
||||
|
@ -17,6 +17,12 @@ public static IRuleBuilderOptions<T, string> ValidDailyEpisodeFormat<T>(this IRu
|
||||
ruleBuilder.SetValidator(new NotEmptyValidator(null));
|
||||
return ruleBuilder.SetValidator(new ValidDailyEpisodeFormatValidator());
|
||||
}
|
||||
|
||||
public static IRuleBuilderOptions<T, string> ValidSeriesFolderFormat<T>(this IRuleBuilder<T, string> ruleBuilder)
|
||||
{
|
||||
ruleBuilder.SetValidator(new NotEmptyValidator(null));
|
||||
return ruleBuilder.SetValidator(new RegularExpressionValidator(FileNameBuilder.SeriesTitleRegex)).WithMessage("Must contain series title");
|
||||
}
|
||||
}
|
||||
|
||||
public class ValidDailyEpisodeFormatValidator : PropertyValidator
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user