diff --git a/src/Lidarr.Api.V1/Lidarr.Api.V1.csproj b/src/Lidarr.Api.V1/Lidarr.Api.V1.csproj index a486c9a37..b4f0ed018 100644 --- a/src/Lidarr.Api.V1/Lidarr.Api.V1.csproj +++ b/src/Lidarr.Api.V1/Lidarr.Api.V1.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Lidarr.Api.V1/Profiles/Delay/DelayProfileModule.cs b/src/Lidarr.Api.V1/Profiles/Delay/DelayProfileModule.cs index 8435c3b70..c00f7ed26 100644 --- a/src/Lidarr.Api.V1/Profiles/Delay/DelayProfileModule.cs +++ b/src/Lidarr.Api.V1/Profiles/Delay/DelayProfileModule.cs @@ -32,14 +32,12 @@ namespace Lidarr.Api.V1.Profiles.Delay SharedValidator.RuleFor(d => d.UsenetDelay).GreaterThanOrEqualTo(0); SharedValidator.RuleFor(d => d.TorrentDelay).GreaterThanOrEqualTo(0); - SharedValidator.Custom(delayProfile => + SharedValidator.RuleFor(d => d).Custom((delayProfile, context) => { if (!delayProfile.EnableUsenet && !delayProfile.EnableTorrent) { - return new ValidationFailure("", "Either Usenet or Torrent should be enabled"); + context.AddFailure("Either Usenet or Torrent should be enabled"); } - - return null; }); } diff --git a/src/Lidarr.Api.V1/Profiles/Release/ReleaseProfileModule.cs b/src/Lidarr.Api.V1/Profiles/Release/ReleaseProfileModule.cs index ae3433e41..83cbbe8ac 100644 --- a/src/Lidarr.Api.V1/Profiles/Release/ReleaseProfileModule.cs +++ b/src/Lidarr.Api.V1/Profiles/Release/ReleaseProfileModule.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using FluentValidation.Results; +using FluentValidation; using NzbDrone.Common.Extensions; using NzbDrone.Core.Profiles.Releases; using Lidarr.Http; @@ -21,14 +21,12 @@ namespace Lidarr.Api.V1.Profiles.Release UpdateResource = Update; DeleteResource = Delete; - SharedValidator.Custom(restriction => + SharedValidator.RuleFor(r => r).Custom((restriction, context) => { if (restriction.Ignored.IsNullOrWhiteSpace() && restriction.Required.IsNullOrWhiteSpace() && restriction.Preferred.Empty()) { - return new ValidationFailure("", "'Must contain', 'Must not contain' or 'Preferred' is required"); + context.AddFailure("Either 'Must contain' or 'Must not contain' is required"); } - - return null; }); } diff --git a/src/Lidarr.Http/Lidarr.Http.csproj b/src/Lidarr.Http/Lidarr.Http.csproj index de51bf2ff..3ae353562 100644 --- a/src/Lidarr.Http/Lidarr.Http.csproj +++ b/src/Lidarr.Http/Lidarr.Http.csproj @@ -4,7 +4,7 @@ x86 - + diff --git a/src/Lidarr.Http/REST/ResourceValidator.cs b/src/Lidarr.Http/REST/ResourceValidator.cs index e052470d1..c97caed28 100644 --- a/src/Lidarr.Http/REST/ResourceValidator.cs +++ b/src/Lidarr.Http/REST/ResourceValidator.cs @@ -18,7 +18,7 @@ namespace Lidarr.Http.REST rule.DisplayName = new StaticStringSource(fieldName); AddRule(rule); - return new RuleBuilder(rule); + return new RuleBuilder(rule, this); } private static object GetValue(object container, Func> fieldListAccessor, string fieldName) diff --git a/src/NzbDrone.Core/Indexers/Headphones/HeadphonesSettings.cs b/src/NzbDrone.Core/Indexers/Headphones/HeadphonesSettings.cs index 85bc604ce..be9fae97b 100644 --- a/src/NzbDrone.Core/Indexers/Headphones/HeadphonesSettings.cs +++ b/src/NzbDrone.Core/Indexers/Headphones/HeadphonesSettings.cs @@ -11,14 +11,12 @@ namespace NzbDrone.Core.Indexers.Headphones { public HeadphonesSettingsValidator() { - Custom(newznab => + RuleFor(c => c).Custom((c, context) => { - if (newznab.Categories.Empty()) + if (c.Categories.Empty()) { - return new ValidationFailure("", "'Categories' must be provided"); + context.AddFailure("'Categories' must be provided"); } - - return null; }); RuleFor(c => c.Username).NotEmpty(); diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs index ce3d3a59c..ee6149801 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs @@ -36,14 +36,12 @@ namespace NzbDrone.Core.Indexers.Newznab public NewznabSettingsValidator() { - Custom(newznab => + RuleFor(c => c).Custom((c, context) => { - if (newznab.Categories.Empty()) + if (c.Categories.Empty()) { - return new ValidationFailure("", "'Categories' must be provided"); + context.AddFailure("'Categories' must be provided"); } - - return null; }); RuleFor(c => c.BaseUrl).ValidRootUrl(); diff --git a/src/NzbDrone.Core/Indexers/Torznab/TorznabSettings.cs b/src/NzbDrone.Core/Indexers/Torznab/TorznabSettings.cs index d59fd23de..4051bdb5b 100644 --- a/src/NzbDrone.Core/Indexers/Torznab/TorznabSettings.cs +++ b/src/NzbDrone.Core/Indexers/Torznab/TorznabSettings.cs @@ -30,14 +30,12 @@ namespace NzbDrone.Core.Indexers.Torznab public TorznabSettingsValidator() { - Custom(newznab => + RuleFor(c => c).Custom((c, context) => { - if (newznab.Categories.Empty()) + if (c.Categories.Empty()) { - return new ValidationFailure("", "'Categories' must be provided"); + context.AddFailure("'Categories' must be provided"); } - - return null; }); RuleFor(c => c.BaseUrl).ValidRootUrl(); diff --git a/src/NzbDrone.Core/Lidarr.Core.csproj b/src/NzbDrone.Core/Lidarr.Core.csproj index a8317fe85..739e1583c 100644 --- a/src/NzbDrone.Core/Lidarr.Core.csproj +++ b/src/NzbDrone.Core/Lidarr.Core.csproj @@ -5,7 +5,7 @@ - + diff --git a/src/NzbDrone.Core/Validation/NzbDroneValidator.cs b/src/NzbDrone.Core/Validation/NzbDroneValidator.cs deleted file mode 100644 index 40e6348ae..000000000 --- a/src/NzbDrone.Core/Validation/NzbDroneValidator.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using FluentValidation; -using FluentValidation.Results; - -namespace NzbDrone.Core.Validation -{ - public abstract class NzbDroneValidator : AbstractValidator - { - public override ValidationResult Validate(T instance) - { - return new NzbDroneValidationResult(base.Validate(instance).Errors); - } - } -} diff --git a/src/NzbDrone.Test.Common/Lidarr.Test.Common.csproj b/src/NzbDrone.Test.Common/Lidarr.Test.Common.csproj index b2327aa32..183d4eaa8 100644 --- a/src/NzbDrone.Test.Common/Lidarr.Test.Common.csproj +++ b/src/NzbDrone.Test.Common/Lidarr.Test.Common.csproj @@ -5,7 +5,7 @@ - +