< Summary

Information
Class: Allyaria.Abstractions.Results.AryResult
Assembly: Allyaria.Abstractions
File(s): /home/runner/work/allyaria/allyaria/src/Allyaria.Abstractions/Results/AryResult.cs
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 52
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Error()100%11100%
get_IsFailure()100%11100%
get_IsSuccess()100%11100%
Failure(...)100%22100%
Success()100%11100%
ToFailure()100%22100%

File(s)

/home/runner/work/allyaria/allyaria/src/Allyaria.Abstractions/Results/AryResult.cs

#LineLine coverage
 1namespace Allyaria.Abstractions.Results;
 2
 3/// <summary>
 4/// Represents the outcome of an operation that can either succeed or fail, encapsulating success state, error details, 
 5/// associated metadata.
 6/// </summary>
 7public sealed class AryResult
 8{
 9    /// <summary>Initializes a new instance of the <see cref="AryResult" /> class.</summary>
 10    /// <param name="isSuccess">Indicates whether the operation succeeded.</param>
 11    /// <param name="error">The associated <see cref="Exception" />, if any.</param>
 1612    private AryResult(bool isSuccess, Exception? error = null)
 13    {
 1614        IsSuccess = isSuccess;
 1615        Error = error;
 1616    }
 17
 18    /// <summary>Gets the <see cref="Exception" /> associated with the result, if any.</summary>
 19    /// <value>
 20    /// The exception describing the failure cause, or <see langword="null" /> if the result represents success.
 21    /// </value>
 1422    public Exception? Error { get; }
 23
 24    /// <summary>Gets a value indicating whether the operation failed.</summary>
 25    /// <value><see langword="true" /> if the operation failed; otherwise, <see langword="false" />.</value>
 1226    public bool IsFailure => !IsSuccess;
 27
 28    /// <summary>Gets a value indicating whether the operation succeeded.</summary>
 29    /// <value><see langword="true" /> if the operation succeeded; otherwise, <see langword="false" />.</value>
 2430    public bool IsSuccess { get; }
 31
 32    /// <summary>Creates a failure <see cref="AryResult" /> with the specified error information.</summary>
 33    /// <param name="error">The <see cref="Exception" /> representing the failure cause.</param>
 34    /// <returns>An <see cref="AryResult" /> representing a failed operation.</returns>
 35    public static AryResult Failure(Exception? error)
 1036        => new(isSuccess: false, error: error ?? new AryException(message: "Unknown error"));
 37
 38    /// <summary>Creates a successful <see cref="AryResult" />.</summary>
 39    /// <returns>An <see cref="AryResult" /> representing a successful operation.</returns>
 640    public static AryResult Success() => new(isSuccess: true);
 41
 42    /// <summary>Converts this <see cref="AryResult" /> to a failed <see cref="AryResult{T}" /> instance.</summary>
 43    /// <typeparam name="T">The result type of the target <see cref="AryResult{T}" />.</typeparam>
 44    /// <returns>A failed <see cref="AryResult{T}" /> with the same error details as this result.</returns>
 45    /// <exception cref="AryInvalidOperationException">Thrown when attempting to convert a successful result into a fail
 46    public AryResult<T> ToFailure<T>()
 447        => IsSuccess
 448            ? throw new AryInvalidOperationException(
 449                message: "Cannot convert a successful AryResult to AryResult<T> failure."
 450            )
 451            : AryResult<T>.Failure(error: Error);
 52}