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

Information
Class: ZhEaIsNsAaBn.Utilities.LayerResponse<T>
Assembly: ZhEaIsNsAaBn.Utilities.LayerResponse
File(s): /home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/UtilitiesPackages/ZhEaIsNsAaBn.Utilities.LayerResponse/LayerResponseOfTResult.cs
Line coverage
76%
Covered lines: 13
Uncovered lines: 4
Coverable lines: 17
Total lines: 109
Line coverage: 76.4%
Branch coverage
41%
Covered branches: 5
Total branches: 12
Branch coverage: 41.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.ctor(...)100%11100%
get_IsFailureOrEmpty()83.33%66100%
Failure(...)100%11100%
Failure(...)100%11100%
Failure(...)100%11100%
Failure(...)100%11100%
Success(...)100%11100%
ToLayerResponse(...)0%620%
ToLayerResponse(...)0%620%
op_Implicit(...)100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)100%11100%
op_Implicit(...)0%620%
op_Implicit(...)100%210%

File(s)

/home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/UtilitiesPackages/ZhEaIsNsAaBn.Utilities.LayerResponse/LayerResponseOfTResult.cs

#LineLine coverage
 1#region Usings
 2using System.Collections;
 3#endregion
 4
 5namespace ZhEaIsNsAaBn.Utilities;
 6
 7/// <summary>
 8/// The result of a fallible operation that returns a value: success with <see cref="Result"/>, or failure with
 9/// <see cref="LayerResponse.Errors"/>. <c>return value;</c>, <c>return error;</c> and <c>return ex;</c> all convert imp
 10/// </summary>
 11/// <typeparam name="TResult">The value type.</typeparam>
 12public class LayerResponse< TResult > : LayerResponse
 13{
 14    /// <summary>Creates a response from one error.</summary>
 15    /// <param name="isSuccess">Whether the operation succeeded.</param>
 16    /// <param name="error"><see cref="Error.None"/> on success; a real error on failure.</param>
 17    /// <param name="result">The value, if any.</param>
 18    /// <exception cref="InvalidOperationException">Success with a real error, or failure with <see cref="Error.None"/>.
 7057619    protected LayerResponse( bool isSuccess, Error error, TResult? result = default ) : base( isSuccess, error ) => Resu
 20
 21    /// <summary>Creates a response from a list of errors.</summary>
 22    /// <param name="isSuccess">Whether the operation succeeded.</param>
 23    /// <param name="errors">Empty or <see langword="null"/> on success; at least one real error on failure.</param>
 24    /// <param name="result">The value, if any.</param>
 25    /// <exception cref="InvalidOperationException">Success with errors, or failure with no real error.</exception>
 39626    protected LayerResponse( bool isSuccess, List<Error>? errors, TResult? result = default ) : base( isSuccess, errors 
 27
 28
 29    /// <summary>The value. <see langword="default"/> on failure unless one was supplied.</summary>
 30    public TResult? Result { get; }
 31
 32    /// <summary>Whether the operation failed, or succeeded with a <see langword="default"/> value or an empty collectio
 1233    public bool IsFailureOrEmpty => IsFailure || Equals( Result, default( TResult ) ) || Result is ICollection { Count: 
 34
 35
 36    /// <summary>Creates a failed response.</summary>
 37    /// <param name="error">The error.</param>
 38    /// <param name="result">An optional value to return with the failure.</param>
 39    /// <returns>A failed response.</returns>
 32740    public static LayerResponse<TResult> Failure( Error error, TResult? result = default ) => new( false, error, result 
 41
 42    /// <summary>Creates a failed response.</summary>
 43    /// <param name="errors">The errors; at least one.</param>
 44    /// <param name="result">An optional value to return with the failure.</param>
 45    /// <returns>A failed response.</returns>
 2746    public static LayerResponse<TResult> Failure( List<Error> errors, TResult? result = default ) => new( false, errors,
 47
 48    /// <summary>Creates a failed response with the errors of another response.</summary>
 49    /// <param name="layerResponse">The failed response to copy errors from.</param>
 50    /// <param name="result">An optional value to return with the failure.</param>
 51    /// <returns>A failed response.</returns>
 52    public static LayerResponse<TResult> Failure( LayerResponse layerResponse, TResult? result = default )
 2053        => new( false, layerResponse.Errors, result );
 54
 55    /// <summary>Creates a failed response with the errors of another typed response.</summary>
 56    /// <typeparam name="TOtherResult">The value type of the source response.</typeparam>
 57    /// <param name="layerResponse">The failed response to copy errors from.</param>
 58    /// <param name="result">An optional value to return with the failure.</param>
 59    /// <returns>A failed response.</returns>
 60    public static LayerResponse<TResult> Failure< TOtherResult >( LayerResponse<TOtherResult> layerResponse, TResult? re
 13961        => new( false, layerResponse.Errors, result );
 62
 63    /// <summary>Creates a successful response.</summary>
 64    /// <param name="result">The value.</param>
 65    /// <returns>A successful response.</returns>
 3496166    public static LayerResponse<TResult> Success( TResult? result = default ) => new( true, Error.None, result );
 67
 68    /// <summary>Copies the outcome into a <see cref="LayerResponse{TResult}"/> of another type, with no value.</summary
 69    /// <typeparam name="TResult2">The value type of the new response.</typeparam>
 70    /// <param name="result">The response to copy.</param>
 71    /// <returns>Success, or failure with the same errors.</returns>
 72    public static new LayerResponse<TResult2> ToLayerResponse< TResult2 >( LayerResponse result )
 073        => result.IsSuccess ? LayerResponse<TResult2>.Success() : LayerResponse<TResult2>.Failure( result.Errors );
 74
 75    /// <summary>Copies the outcome into a plain <see cref="LayerResponse"/>.</summary>
 76    /// <param name="result">The response to copy.</param>
 77    /// <returns>Success, or failure with the same errors.</returns>
 78    public static LayerResponse ToLayerResponse( LayerResponse result )
 079        => result.IsSuccess ? LayerResponse.Success() : LayerResponse.Failure( result.Errors );
 80
 81
 82    /// <summary>Wraps a value as a successful response.</summary>
 83    /// <param name="result">The value.</param>
 2525284    public static implicit operator LayerResponse<TResult>( TResult? result ) => Success( result );
 85
 86    /// <summary>Gets the value.</summary>
 87    /// <param name="result">The response.</param>
 488    public static implicit operator TResult( LayerResponse<TResult> result ) => result.Result!;
 89
 90    /// <summary>Wraps an error as a failed response.</summary>
 91    /// <param name="error">The error.</param>
 27592    public static implicit operator LayerResponse<TResult>( Error error ) => Failure( error );
 93
 94    /// <summary>Wraps errors as a failed response.</summary>
 95    /// <param name="errors">The errors; at least one.</param>
 1196    public static implicit operator LayerResponse<TResult>( List<Error> errors ) => Failure( errors );
 97
 98    /// <summary>Wraps an exception as a failed response with <see cref="Error.Unknown"/>.</summary>
 99    /// <param name="exception">The exception.</param>
 4100    public static implicit operator LayerResponse<TResult>( Exception exception ) => Failure( Error.Unknown( exception )
 101
 102    /// <summary>Gets the first error, or <see cref="Error.None"/> on success.</summary>
 103    /// <param name="response">The response.</param>
 0104    public static implicit operator Error( LayerResponse<TResult> response ) => response.Errors.FirstOrDefault() ?? Erro
 105
 106    /// <summary>Gets the errors.</summary>
 107    /// <param name="response">The response.</param>
 0108    public static implicit operator List<Error>( LayerResponse<TResult> response ) => response.Errors;
 109}