< Summary - ZhEaIsNsAaBn.Libraries coverage (affected: 23 packages)

Information
Class: FluentValidation.FluentValidationEnumHelpers
Assembly: ZhEaIsNsAaBn.Utilities.FluentValidation
File(s): /home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/UtilitiesPackages/ZhEaIsNsAaBn.Utilities.FluentValidation/FluentValidationEnumHelpers.cs
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 32
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
NotEmptyEnum(...)100%11100%
NotEmptyEnumIf(...)100%11100%

File(s)

/home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/UtilitiesPackages/ZhEaIsNsAaBn.Utilities.FluentValidation/FluentValidationEnumHelpers.cs

#LineLine coverage
 1// ReSharper disable once CheckNamespace
 2namespace FluentValidation;
 3
 4/// <summary>Rules for enum properties.</summary>
 5public static class FluentValidationEnumHelpers
 6{
 7    /// <summary>The value must be set and be a defined member of its enum.</summary>
 8    /// <typeparam name="T">The validated type.</typeparam>
 9    /// <typeparam name="TProperty">The enum (or nullable enum) type.</typeparam>
 10    /// <param name="ruleBuilder">The rule builder.</param>
 11    /// <returns>The rule builder options.</returns>
 12    public static IRuleBuilderOptions<T, TProperty> NotEmptyEnum< T, TProperty >( this IRuleBuilder<T, TProperty> ruleBu
 313        => ruleBuilder.Must( ( _, value, context ) => value is not null && new EnumValidator<T, TProperty>().IsValid( co
 14
 15    /// <summary>
 16    /// The value must be a defined member of its enum (or empty); when <paramref name="nullable"/> returns <see langwor
 17    /// it must also be set (a <see langword="null"/> <paramref name="nullable"/> allows empty).
 18    /// </summary>
 19    /// <typeparam name="T">The validated type.</typeparam>
 20    /// <typeparam name="TProperty">The enum (or nullable enum) type.</typeparam>
 21    /// <param name="ruleBuilder">The rule builder.</param>
 22    /// <param name="nullable">Decides, per instance and value, whether an empty value is allowed.</param>
 23    /// <returns>The rule builder options.</returns>
 24    public static IRuleBuilderOptions<T, TProperty> NotEmptyEnumIf< T, TProperty >( this IRuleBuilder<T, TProperty> rule
 325        => ruleBuilder.Must( ( entity, value, context ) =>
 326                             {
 327                                 var allowsEmpty = nullable?.Invoke( entity, value ) ?? true;
 328
 329
 330                                 return ( allowsEmpty || value is not null ) && new EnumValidator<T, TProperty>().IsVali
 331                             } ).WithErrorCode( nameof( NotEmptyEnumIf ) );
 32}