< Summary

Information
Class: Elsa.Expressions.Models.Result
Assembly: Elsa.Expressions
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions/Models/Result.cs
Line coverage
92%
Covered lines: 13
Uncovered lines: 1
Coverable lines: 14
Total lines: 51
Line coverage: 92.8%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
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_Success()100%11100%
get_Value()100%11100%
get_Exception()100%11100%
OnSuccess(...)100%22100%
OnFailure(...)50%2266.66%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions/Models/Result.cs

#LineLine coverage
 1namespace Elsa.Expressions.Models;
 2
 3/// <summary>
 4/// A simple monad that runs either the <see cref="OnSuccess"/> or <see cref="OnFailure"/> lambda, depending on whether 
 5/// </summary>
 6public class Result
 7{
 163638    internal Result(bool success, object? value, Exception? exception)
 9    {
 1636310        Success = success;
 1636311        Value = value;
 1636312        Exception = exception;
 1636313    }
 14
 15    /// <summary>
 16    /// True if the conversaion succeeded, false otherwise.
 17    /// </summary>
 3237218    public bool Success { get; }
 19
 20    /// <summary>
 21    /// The result value.
 22    /// </summary>
 1636323    public object? Value { get; }
 24
 25    /// <summary>
 26    /// Any exception that may have occurred during the operation.
 27    /// </summary>
 33928    public Exception? Exception { get; }
 29
 30    /// <summary>
 31    /// Runs the provided delegate if the result is successful.
 32    /// </summary>
 33    public Result OnSuccess(Action<object?> successHandler)
 34    {
 33935        if (Success)
 33936            successHandler(Value);
 37
 33938        return this;
 39    }
 40
 41    /// <summary>
 42    /// Runs the provided delegate if the result is unsuccessful.
 43    /// </summary>
 44    public Result OnFailure(Action<Exception> failureHandler)
 45    {
 33946        if (Exception != null)
 047            failureHandler(Exception);
 48
 33949        return this;
 50    }
 51}