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

Information
Class: FluentValidation.FluentValidationHelpers
Assembly: ZhEaIsNsAaBn.Utilities.FluentValidation
File(s): /home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/UtilitiesPackages/ZhEaIsNsAaBn.Utilities.FluentValidation/FluentValidationHelpers.cs
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 58
Line coverage: 100%
Branch coverage
33%
Covered branches: 2
Total branches: 6
Branch coverage: 33.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
NotEmptyGuid(...)100%11100%
NotEmptyIf(...)100%11100%
NotEmptyStringIf(...)100%11100%
IsValidWebsite(...)100%11100%
IsValidEmail(...)100%11100%
IsEmpty(...)33.33%66100%

File(s)

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

#LineLine coverage
 1// ReSharper disable once CheckNamespace
 2namespace FluentValidation;
 3
 4/// <summary>General rules: GUID, conditional required values, website and e-mail text.</summary>
 5public static class FluentValidationHelpers
 6{
 37    private static readonly Regex _website = new( @"(?i)^(https?://)(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-z]{2,6}\b
 8
 39    private static readonly Regex _email =
 310        new( @"^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|""(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\
 311             RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant );
 12
 13
 14    /// <summary>The GUID must not be <see cref="Guid.Empty"/>.</summary>
 15    /// <typeparam name="T">The validated type.</typeparam>
 16    /// <param name="ruleBuilder">The rule builder.</param>
 17    /// <returns>The rule builder options.</returns>
 618    public static IRuleBuilderOptions<T, Guid> NotEmptyGuid< T >( this IRuleBuilder<T, Guid> ruleBuilder ) => ruleBuilde
 19
 20    /// <summary>
 21    /// The value must be set (not <see langword="null"/>, not the type's default, not blank text) unless <paramref name
 22    /// returns <see langword="true"/> (a <see langword="null"/> <paramref name="nullable"/> allows empty).
 23    /// </summary>
 24    /// <typeparam name="T">The validated type.</typeparam>
 25    /// <typeparam name="TProperty">The property type.</typeparam>
 26    /// <param name="ruleBuilder">The rule builder.</param>
 27    /// <param name="nullable">Decides, per instance and value, whether an empty value is allowed.</param>
 28    /// <returns>The rule builder options.</returns>
 29    public static IRuleBuilderOptions<T, TProperty> NotEmptyIf< T, TProperty >( this IRuleBuilder<T, TProperty> ruleBuil
 1230        => ruleBuilder.Must( ( entity, value ) => ( nullable?.Invoke( entity, value ) ?? true ) || !IsEmpty( value ) ).W
 31
 32    /// <summary>
 33    /// The text must not be blank unless <paramref name="nullable"/> returns <see langword="true"/> (a <see langword="n
 34    /// <paramref name="nullable"/> allows empty).
 35    /// </summary>
 36    /// <typeparam name="T">The validated type.</typeparam>
 37    /// <param name="ruleBuilder">The rule builder.</param>
 38    /// <param name="nullable">Decides, per instance and value, whether an empty value is allowed.</param>
 39    /// <returns>The rule builder options.</returns>
 40    public static IRuleBuilderOptions<T, string> NotEmptyStringIf< T >( this IRuleBuilder<T, string> ruleBuilder, Func<T
 1841        => ruleBuilder.Must( ( entity, value ) => ( nullable?.Invoke( entity, value ) ?? true ) || !string.IsNullOrWhite
 42
 43    /// <summary>The text must be an <c>http</c>/<c>https</c> URL.</summary>
 44    /// <typeparam name="T">The validated type.</typeparam>
 45    /// <param name="ruleBuilder">The rule builder.</param>
 46    /// <returns>The rule builder options.</returns>
 947    public static IRuleBuilderOptions<T, string> IsValidWebsite< T >( this IRuleBuilder<T, string> ruleBuilder ) => rule
 48
 49    /// <summary>The whole text must be one e-mail address (RFC 5322 style, case-insensitive).</summary>
 50    /// <typeparam name="T">The validated type.</typeparam>
 51    /// <param name="ruleBuilder">The rule builder.</param>
 52    /// <returns>The rule builder options.</returns>
 2153    public static IRuleBuilderOptions<T, string> IsValidEmail< T >( this IRuleBuilder<T, string> ruleBuilder ) => ruleBu
 54
 55
 56    private static bool IsEmpty< TProperty >( TProperty value )
 957        => value is null || value is string text && string.IsNullOrWhiteSpace( text ) || EqualityComparer<TProperty>.Def
 58}