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" />
</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="Nancy" 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.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;
});
}

View File

@ -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;
});
}

View File

@ -4,7 +4,7 @@
<Platforms>x86</Platforms>
</PropertyGroup>
<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.Authentication.Basic" 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);
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)

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -5,7 +5,7 @@
</PropertyGroup>
<ItemGroup>
<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="NLog" Version="4.5.4" />
<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>
<ItemGroup>
<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="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="NLog" Version="4.5.4" />