1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-29 23:12:39 +01:00

Updated FluentValidation to 8.4.0

This commit is contained in:
Taloth Saldono 2019-08-16 20:46:16 +02:00
parent 7a94725808
commit 896e824ca1
12 changed files with 22 additions and 32 deletions

View File

@ -28,14 +28,12 @@ namespace NzbDrone.Api.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,4 +1,5 @@
using System.Collections.Generic;
using FluentValidation;
using FluentValidation.Results;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Profiles.Releases;
@ -22,14 +23,12 @@ namespace NzbDrone.Api.Restrictions
UpdateResource = UpdateRestriction;
DeleteResource = DeleteRestriction;
SharedValidator.Custom(restriction =>
SharedValidator.RuleFor(r => r).Custom((restriction, context) =>
{
if (restriction.Ignored.IsNullOrWhiteSpace() && restriction.Required.IsNullOrWhiteSpace())
{
return new ValidationFailure("", "Either 'Must contain' or 'Must not contain' 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.0" />
<PackageReference Include="FluentValidation" Version="8.4.0" />
<PackageReference Include="Ical.Net" Version="2.2.32" />
<PackageReference Include="Nancy" Version="1.4.4" />
<PackageReference Include="Nancy.Authentication.Basic" Version="1.4.1" />

View File

@ -37,14 +37,12 @@ namespace NzbDrone.Core.Indexers.Newznab
public NewznabSettingsValidator()
{
Custom(newznab =>
RuleFor(c => c).Custom((c, context) =>
{
if (newznab.Categories.Empty() && newznab.AnimeCategories.Empty())
if (c.Categories.Empty() && c.AnimeCategories.Empty())
{
return new ValidationFailure("", "Either 'Categories' or 'Anime Categories' must be provided");
context.AddFailure("Either 'Categories' or 'Anime 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() && newznab.AnimeCategories.Empty())
if (c.Categories.Empty() && c.AnimeCategories.Empty())
{
return new ValidationFailure("", "Either 'Categories' or 'Anime Categories' must be provided");
context.AddFailure("Either 'Categories' or 'Anime 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.0" />
<PackageReference Include="FluentValidation" Version="8.4.0" />
<PackageReference Include="ImageResizer" Version="3.4.3" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="NLog" Version="4.5.3" />

View File

@ -6,7 +6,7 @@
<ItemGroup>
<PackageReference Include="CommonServiceLocator" Version="1.3" />
<PackageReference Include="FluentAssertions" Version="4.19.0" />
<PackageReference Include="FluentValidation" Version="6.2.1.0" />
<PackageReference Include="FluentValidation" Version="8.4.0" />
<PackageReference Include="Moq" Version="4.0.10827" />
<PackageReference Include="NLog" Version="4.5.3" />
<PackageReference Include="NUnit" Version="3.6.0" />

View File

@ -32,14 +32,12 @@ namespace Sonarr.Api.V3.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,4 +1,5 @@
using System.Collections.Generic;
using FluentValidation;
using FluentValidation.Results;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Profiles.Releases;
@ -21,14 +22,12 @@ namespace Sonarr.Api.V3.Profiles.Release
UpdateResource = Update;
DeleteResource = DeleteReleaseProfile;
SharedValidator.Custom(restriction =>
SharedValidator.RuleFor(d => d).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("'Must contain', 'Must not contain' or 'Preferred' is required");
}
return null;
});
}

View File

@ -4,7 +4,7 @@
<Platforms>x86</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentValidation" Version="6.2.1.0" />
<PackageReference Include="FluentValidation" Version="8.4.0" />
<PackageReference Include="Ical.Net" Version="2.2.32" />
<PackageReference Include="Nancy" Version="1.4.4" />
<PackageReference Include="Nancy.Authentication.Basic" Version="1.4.1" />

View File

@ -18,7 +18,7 @@ namespace Sonarr.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

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