< Summary

Information
Class: Allyaria.Abstractions.Results.AryResult<T>
Assembly: Allyaria.Abstractions
File(s): /home/runner/work/allyaria/allyaria/src/Allyaria.Abstractions/Results/AryResultT.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 59
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%
get_Value()100%11100%
Failure(...)100%22100%
Success(...)100%11100%
ToFailure()100%22100%

File(s)

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

#LineLine coverage
 1namespace Allyaria.Abstractions.Results;
 2
 3/// <summary>
 4/// Represents the outcome of an operation that may return a value of type <typeparamref name="T" />. Encapsulates succe
 5/// and failure states, error details, and contextual information.
 6/// </summary>
 7/// <typeparam name="T">The type of the value returned on success.</typeparam>
 8public sealed class AryResult<T>
 9{
 10    /// <summary>Initializes a new instance of the <see cref="AryResult{T}" /> class.</summary>
 11    /// <param name="isSuccess">Indicates whether the operation succeeded.</param>
 12    /// <param name="value">The result value, if successful.</param>
 13    /// <param name="error">The associated <see cref="Exception" />, if any.</param>
 1614    private AryResult(bool isSuccess, T? value = default, Exception? error = null)
 15    {
 1616        IsSuccess = isSuccess;
 1617        Error = error;
 1618        Value = value;
 1619    }
 20
 21    /// <summary>Gets the <see cref="Exception" /> associated with this result, if any.</summary>
 22    /// <value>The exception describing the failure cause, or <see langword="null" /> if the operation succeeded.</value
 1423    public Exception? Error { get; }
 24
 25    /// <summary>Gets a value indicating whether the operation failed.</summary>
 26    /// <value><see langword="true" /> if the operation failed; otherwise, <see langword="false" />.</value>
 1227    public bool IsFailure => !IsSuccess;
 28
 29    /// <summary>Gets a value indicating whether the operation succeeded.</summary>
 30    /// <value><see langword="true" /> if the operation succeeded; otherwise, <see langword="false" />.</value>
 2431    public bool IsSuccess { get; }
 32
 33    /// <summary>Gets the result value of the operation, if successful.</summary>
 34    /// <value>
 35    /// The value produced by the operation. This property is <see langword="null" /> if the operation failed.
 36    /// </value>
 637    public T? Value { get; }
 38
 39    /// <summary>Creates a failed <see cref="AryResult{T}" /> with the specified error information.</summary>
 40    /// <param name="error">The exception representing the failure cause.</param>
 41    /// <returns>A failed <see cref="AryResult{T}" /> containing the provided error details.</returns>
 42    public static AryResult<T> Failure(Exception? error)
 1043        => new(isSuccess: false, error: error ?? new AryException(message: "Unknown error"));
 44
 45    /// <summary>Creates a successful <see cref="AryResult{T}" /> with the specified value.</summary>
 46    /// <param name="value">The result value to encapsulate.</param>
 47    /// <returns>A successful <see cref="AryResult{T}" /> containing the specified value.</returns>
 648    public static AryResult<T> Success(T value) => new(isSuccess: true, value: value);
 49
 50    /// <summary>Converts this <see cref="AryResult{T}" /> to a failed <see cref="AryResult" />.</summary>
 51    /// <returns>A failed <see cref="AryResult" /> with the same error details as this instance.</returns>
 52    /// <exception cref="AryInvalidOperationException">Thrown when attempting to convert a successful result to a failur
 53    public AryResult ToFailure()
 454        => IsSuccess
 455            ? throw new AryInvalidOperationException(
 456                message: "Cannot convert a successful AryResult<T> to AryResult failure."
 457            )
 458            : AryResult.Failure(error: Error);
 59}