New: Updated FluentValidation to 8.4.0

Co-Authored-By: taloth <taloth@users.noreply.github.com>
This commit is contained in:
Qstick 2019-09-11 21:26:54 -04:00
parent 22fb4a1801
commit 40483c1bbb
11 changed files with 19 additions and 46 deletions

View file

@ -11,7 +11,7 @@
<ProjectReference Include="..\NzbDrone.SignalR\Lidarr.SignalR.csproj" /> <ProjectReference Include="..\NzbDrone.SignalR\Lidarr.SignalR.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="FluentValidation" Version="6.2.1" /> <PackageReference Include="FluentValidation" Version="8.4.0" />
<PackageReference Include="Ical.Net" Version="2.2.32" /> <PackageReference Include="Ical.Net" Version="2.2.32" />
<PackageReference Include="Nancy" Version="2.0.0" /> <PackageReference Include="Nancy" Version="2.0.0" />
<PackageReference Include="Nancy.Authentication.Basic" Version="2.0.0" /> <PackageReference Include="Nancy.Authentication.Basic" Version="2.0.0" />

View file

@ -32,14 +32,12 @@ namespace Lidarr.Api.V1.Profiles.Delay
SharedValidator.RuleFor(d => d.UsenetDelay).GreaterThanOrEqualTo(0); SharedValidator.RuleFor(d => d.UsenetDelay).GreaterThanOrEqualTo(0);
SharedValidator.RuleFor(d => d.TorrentDelay).GreaterThanOrEqualTo(0); SharedValidator.RuleFor(d => d.TorrentDelay).GreaterThanOrEqualTo(0);
SharedValidator.Custom(delayProfile => SharedValidator.RuleFor(d => d).Custom((delayProfile, context) =>
{ {
if (!delayProfile.EnableUsenet && !delayProfile.EnableTorrent) 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;
}); });
} }

View file

@ -1,5 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using FluentValidation.Results; using FluentValidation;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Profiles.Releases; using NzbDrone.Core.Profiles.Releases;
using Lidarr.Http; using Lidarr.Http;
@ -21,14 +21,12 @@ namespace Lidarr.Api.V1.Profiles.Release
UpdateResource = Update; UpdateResource = Update;
DeleteResource = Delete; DeleteResource = Delete;
SharedValidator.Custom(restriction => SharedValidator.RuleFor(r => r).Custom((restriction, context) =>
{ {
if (restriction.Ignored.IsNullOrWhiteSpace() && restriction.Required.IsNullOrWhiteSpace() && restriction.Preferred.Empty()) 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;
}); });
} }

View file

@ -4,7 +4,7 @@
<Platforms>x86</Platforms> <Platforms>x86</Platforms>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="FluentValidation" Version="6.2.1" /> <PackageReference Include="FluentValidation" Version="8.4.0" />
<PackageReference Include="Nancy" Version="2.0.0" /> <PackageReference Include="Nancy" Version="2.0.0" />
<PackageReference Include="Nancy.Authentication.Basic" Version="2.0.0" /> <PackageReference Include="Nancy.Authentication.Basic" Version="2.0.0" />
<PackageReference Include="Nancy.Authentication.Forms" Version="2.0.0" /> <PackageReference Include="Nancy.Authentication.Forms" Version="2.0.0" />

View file

@ -18,7 +18,7 @@ namespace Lidarr.Http.REST
rule.DisplayName = new StaticStringSource(fieldName); rule.DisplayName = new StaticStringSource(fieldName);
AddRule(rule); AddRule(rule);
return new RuleBuilder<TResource, TProperty>(rule); return new RuleBuilder<TResource, TProperty>(rule, this);
} }
private static object GetValue(object container, Func<TResource, IEnumerable<Field>> fieldListAccessor, string fieldName) private static object GetValue(object container, Func<TResource, IEnumerable<Field>> fieldListAccessor, string fieldName)

View file

@ -11,14 +11,12 @@ namespace NzbDrone.Core.Indexers.Headphones
{ {
public HeadphonesSettingsValidator() 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(); RuleFor(c => c.Username).NotEmpty();

View file

@ -36,14 +36,12 @@ namespace NzbDrone.Core.Indexers.Newznab
public NewznabSettingsValidator() 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(); RuleFor(c => c.BaseUrl).ValidRootUrl();

View file

@ -30,14 +30,12 @@ namespace NzbDrone.Core.Indexers.Torznab
public TorznabSettingsValidator() 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(); RuleFor(c => c.BaseUrl).ValidRootUrl();

View file

@ -5,7 +5,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="FluentMigrator.Runner" Version="1.6.2" /> <PackageReference Include="FluentMigrator.Runner" Version="1.6.2" />
<PackageReference Include="FluentValidation" Version="6.2.1" /> <PackageReference Include="FluentValidation" Version="8.4.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="NLog" Version="4.5.4" /> <PackageReference Include="NLog" Version="4.5.4" />
<PackageReference Include="OAuth" Version="1.0.3" /> <PackageReference Include="OAuth" Version="1.0.3" />

View file

@ -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<T> : AbstractValidator<T>
{
public override ValidationResult Validate(T instance)
{
return new NzbDroneValidationResult(base.Validate(instance).Errors);
}
}
}

View file

@ -5,7 +5,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="FluentAssertions" Version="4.19.0" /> <PackageReference Include="FluentAssertions" Version="4.19.0" />
<PackageReference Include="FluentValidation" Version="6.2.1" /> <PackageReference Include="FluentValidation" Version="8.4.0" />
<PackageReference Include="Moq" Version="4.12.0" /> <PackageReference Include="Moq" Version="4.12.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="NLog" Version="4.5.4" /> <PackageReference Include="NLog" Version="4.5.4" />