< Summary

Information
Class: ArturRios.Output.ProcessOutput
Assembly: ArturRios.Output
File(s): /home/runner/work/dotnet-output/dotnet-output/src/ProcessOutput.cs
Line coverage
100%
Covered lines: 33
Uncovered lines: 0
Coverable lines: 33
Total lines: 155
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage
100%
Covered methods: 16
Fully covered methods: 16
Total methods: 16
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
get_Messages()100%11100%
set_Messages(...)100%22100%
get_Errors()100%11100%
set_Errors(...)100%22100%
get_Timestamp()100%11100%
get_Success()100%11100%
get_New()100%11100%
AddError(...)100%22100%
AddErrors(...)100%22100%
AddMessage(...)100%22100%
AddMessages(...)100%22100%
WithError(...)100%11100%
WithErrors(...)100%11100%
WithMessage(...)100%11100%
WithMessages(...)100%11100%

File(s)

/home/runner/work/dotnet-output/dotnet-output/src/ProcessOutput.cs

#LineLine coverage
 1namespace ArturRios.Output;
 2
 3/// <summary>
 4/// Represents the outcome of an operation and provides a standardized way to
 5/// collect messages, errors and a timestamp.
 6/// </summary>
 7public class ProcessOutput
 8{
 2299    private List<string> _messages = [];
 22910    private List<string> _errors = [];
 11
 12    /// <summary>
 13    /// Collection of informational messages produced during the process. Never <c>null</c>:
 14    /// assigning <c>null</c> — as a deserializer does for an explicit JSON <c>null</c> —
 15    /// resets it to an empty list.
 16    /// </summary>
 17    public List<string> Messages
 18    {
 6819        get => _messages;
 820        set => _messages = value ?? [];
 21    }
 22
 23    /// <summary>
 24    /// Collection of error messages produced during the process. If this list
 25    /// is empty the <see cref="Success"/> property evaluates to <c>true</c>.
 26    /// Never <c>null</c>, on the same terms as <see cref="Messages"/>.
 27    /// </summary>
 28    public List<string> Errors
 29    {
 26330        get => _errors;
 931        set => _errors = value ?? [];
 32    }
 33
 34    /// <summary>
 35    /// UTC timestamp representing when this output instance was created.
 36    /// </summary>
 27837    public DateTime Timestamp { get; set; } = DateTime.UtcNow;
 38
 39    /// <summary>
 40    /// Indicates whether the process completed successfully (no errors were added).
 41    /// </summary>
 12142    public bool Success => Errors.Count == 0;
 43
 44    /// <summary>
 45    /// Creates a new <see cref="ProcessOutput"/> instance.
 46    /// </summary>
 1947    public static ProcessOutput New => new();
 48
 49    /// <summary>
 50    /// Adds a non-empty error message to the output.
 51    /// </summary>
 52    /// <param name="error">The error message to add.</param>
 53    public void AddError(string error)
 54    {
 2355        if (string.IsNullOrWhiteSpace(error))
 56        {
 557            return;
 58        }
 59
 1860        Errors.Add(error);
 1861    }
 62
 63    /// <summary>
 64    /// Adds multiple error messages to the output, ignoring empty or whitespace entries.
 65    /// A <c>null</c> collection is ignored.
 66    /// </summary>
 67    /// <param name="errors">The collection of errors to add.</param>
 68    public void AddErrors(IEnumerable<string>? errors)
 69    {
 770        if (errors is null)
 71        {
 272            return;
 73        }
 74
 2075        Errors.AddRange(errors.Where(e => !string.IsNullOrWhiteSpace(e)));
 576    }
 77
 78
 79    /// <summary>
 80    /// Adds a non-empty informational message to the output.
 81    /// </summary>
 82    /// <param name="message">The message to add.</param>
 83    public void AddMessage(string message)
 84    {
 1785        if (string.IsNullOrWhiteSpace(message))
 86        {
 687            return;
 88        }
 89
 1190        Messages.Add(message);
 1191    }
 92
 93    /// <summary>
 94    /// Adds multiple informational messages to the output, ignoring empty or whitespace entries.
 95    /// A <c>null</c> collection is ignored.
 96    /// </summary>
 97    /// <param name="messages">The collection of messages to add.</param>
 98    public void AddMessages(IEnumerable<string>? messages)
 99    {
 7100        if (messages is null)
 101        {
 2102            return;
 103        }
 104
 19105        Messages.AddRange(messages.Where(e => !string.IsNullOrWhiteSpace(e)));
 5106    }
 107
 108    /// <summary>
 109    /// Fluent helper to add a single error and return the same instance.
 110    /// </summary>
 111    /// <param name="error">The error to add.</param>
 112    /// <returns>The same <see cref="ProcessOutput"/> instance for chaining.</returns>
 113    public ProcessOutput WithError(string error)
 114    {
 2115        AddError(error);
 116
 2117        return this;
 118    }
 119
 120    /// <summary>
 121    /// Fluent helper to add multiple errors and return the same instance.
 122    /// </summary>
 123    /// <param name="errors">The errors to add.</param>
 124    /// <returns>The same <see cref="ProcessOutput"/> instance for chaining.</returns>
 125    public ProcessOutput WithErrors(IEnumerable<string>? errors)
 126    {
 2127        AddErrors(errors);
 128
 2129        return this;
 130    }
 131
 132    /// <summary>
 133    /// Fluent helper to add a single informational message and return the same instance.
 134    /// </summary>
 135    /// <param name="message">The message to add.</param>
 136    /// <returns>The same <see cref="ProcessOutput"/> instance for chaining.</returns>
 137    public ProcessOutput WithMessage(string message)
 138    {
 2139        AddMessage(message);
 140
 2141        return this;
 142    }
 143
 144    /// <summary>
 145    /// Fluent helper to add multiple informational messages and return the same instance.
 146    /// </summary>
 147    /// <param name="messages">The messages to add.</param>
 148    /// <returns>The same <see cref="ProcessOutput"/> instance for chaining.</returns>
 149    public ProcessOutput WithMessages(IEnumerable<string>? messages)
 150    {
 2151        AddMessages(messages);
 152
 2153        return this;
 154    }
 155}