< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Tasks.ProgressiveKestrunTaskState
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Tasks/ProgressiveKestrunTaskState.cs
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
88%
Covered lines: 24
Uncovered lines: 3
Coverable lines: 27
Total lines: 108
Line coverage: 88.8%
Branch coverage
62%
Covered branches: 5
Total branches: 8
Branch coverage: 62.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 10/15/2025 - 01:01:18 Line coverage: 100% (24/24) Branch coverage: 100% (8/8) Total lines: 98 Tag: Kestrun/Kestrun@7c4ce528870211ad6c2d2398c31ec13097fc584010/15/2025 - 21:27:26 Line coverage: 88.8% (24/27) Branch coverage: 62.5% (5/8) Total lines: 108 Tag: Kestrun/Kestrun@c33ec02a85e4f8d6061aeaab5a5e8c3a8b665594 10/15/2025 - 01:01:18 Line coverage: 100% (24/24) Branch coverage: 100% (8/8) Total lines: 98 Tag: Kestrun/Kestrun@7c4ce528870211ad6c2d2398c31ec13097fc584010/15/2025 - 21:27:26 Line coverage: 88.8% (24/27) Branch coverage: 62.5% (5/8) Total lines: 108 Tag: Kestrun/Kestrun@c33ec02a85e4f8d6061aeaab5a5e8c3a8b665594

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
get_PercentComplete()100%11100%
set_PercentComplete(...)100%11100%
get_StatusMessage()100%11100%
set_StatusMessage(...)100%22100%
ToString()100%11100%
Reset(...)100%11100%
Complete(...)100%11100%
Fail(...)100%11100%
Cancel(...)100%11100%
SetState(...)50%7670%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Tasks/ProgressiveKestrunTaskState.cs

#LineLine coverage
 1
 2namespace Kestrun.Tasks;
 3
 4/// <summary>
 5/// Represents the progress state of a task.
 6/// </summary>
 7public class ProgressiveKestrunTaskState
 8{
 9    // Synchronizes concurrent updates coming from different runspaces.
 10#if NET9_0_OR_GREATER
 3711    private readonly Lock _syncRoot = new();
 12#else
 13    private readonly object _syncRoot = new();
 14#endif
 15    private int _percentComplete = 0;
 3716    private string _statusMessage = "Not started";
 17
 18    /// <summary>
 19    /// Percentage of task completed (0-100).
 20    /// </summary>
 21    public int PercentComplete
 22    {
 23        get
 2824        {
 25            lock (_syncRoot)
 26            {
 2827                return _percentComplete;
 28            }
 2829        }
 30
 331        set => SetState(value, StatusMessage, nameof(value));
 32    }
 33
 34    /// <summary>
 35    /// Optional status message for the current progress.
 36    /// </summary>
 37    public string StatusMessage
 38    {
 39        get
 1540        {
 41            lock (_syncRoot)
 42            {
 1543                return _statusMessage;
 44            }
 1545        }
 1646        set => SetState(PercentComplete, value ?? throw new ArgumentNullException(nameof(value)));
 47    }
 48    /// <summary>
 49    /// Returns a string representation of the progress state.
 50    /// </summary>
 51    /// <returns> A string representation of the progress state. </returns>
 52    public override string ToString()
 253    {
 54        lock (_syncRoot)
 55        {
 256            return $"{_percentComplete}% - {_statusMessage}";
 57        }
 258    }
 59
 60    /// <summary>
 61    /// Resets the progress state to initial values.
 62    /// </summary>
 63    /// <param name="message"> Optional message to include with the reset status.</param>
 564    public void Reset(string message = "Not started") => SetState(0, message);
 65    /// <summary>
 66    /// Marks the progress as complete with an optional message.
 67    /// </summary>
 68    /// <param name="message"> Optional message to include with the completion status.</param>
 1069    public void Complete(string message = "Completed") => SetState(100, message);
 70
 71    /// <summary>
 72    /// Marks the progress as failed with an optional message.
 73    /// </summary>
 74    /// <param name="message"> Optional message to include with the failure status.</param>
 275    public void Fail(string message = "Failed") => SetState(100, message);
 76
 77    /// <summary>
 78    /// Marks the progress as cancelled with an optional message.
 79    /// </summary>
 80    /// <param name="message"> Optional message to include with the cancellation status.</param>
 681    public void Cancel(string message = "Cancelled") => SetState(100, message);
 82
 83#pragma warning disable IDE0060 // Remove unused parameter
 84    private void SetState(int percentComplete, string statusMessage, string percentParameterName = nameof(PercentComplet
 85#pragma warning restore IDE0060 // Remove unused parameter
 86    {
 4187        if (string.IsNullOrWhiteSpace(statusMessage))
 88        {
 089            throw new ArgumentNullException(nameof(statusMessage));
 90        }
 91
 4192        if (percentComplete < 0)
 93        {
 094            percentComplete = 0;
 95        }
 4196        else if (percentComplete > 100)
 97        {
 098            percentComplete = 100;
 99        }
 100
 101
 102        lock (_syncRoot)
 103        {
 41104            _percentComplete = percentComplete;
 41105            _statusMessage = statusMessage;
 41106        }
 41107    }
 108}