< Summary

Information
Class: ArturRios.Output.ProcessOutput
Assembly: ArturRios.Output
File(s): D:\Repositories\dotnet-output\src\ProcessOutput.cs
Line coverage
100%
Covered lines: 39
Uncovered lines: 0
Coverable lines: 39
Total lines: 139
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage
100%
Covered methods: 16
Fully covered methods: 10
Total methods: 16
Method coverage: 100%
Full method coverage: 62.5%

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%11100%
AddMessage(...)100%22100%
AddMessages(...)100%11100%
WithError(...)100%11100%
WithErrors(...)100%11100%
WithMessage(...)100%11100%
WithMessages(...)100%11100%

File(s)

D:\Repositories\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{
 599    private List<string> _messages = [];
 5910    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    {
 6119        get => _messages;
 720        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    {
 8030        get => _errors;
 831        set => _errors = value ?? [];
 32    }
 33
 34    /// <summary>
 35    /// UTC timestamp representing when this output instance was created.
 36    /// </summary>
 10037    public DateTime Timestamp { get; set; } = DateTime.UtcNow;
 38
 39    /// <summary>
 40    /// Indicates whether the process completed successfully (no errors were added).
 41    /// </summary>
 3042    public bool Success => Errors.Count == 0;
 43
 44    /// <summary>
 45    /// Creates a new <see cref="ProcessOutput"/> instance.
 46    /// </summary>
 1247    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)
 1354    {
 1355        if (string.IsNullOrWhiteSpace(error))
 556        {
 557            return;
 58        }
 59
 860        Errors.Add(error);
 1361    }
 62
 63    /// <summary>
 64    /// Adds multiple error messages to the output, ignoring empty or whitespace entries.
 65    /// </summary>
 66    /// <param name="errors">The collection of errors to add.</param>
 67    public void AddErrors(IEnumerable<string> errors) =>
 2068        Errors.AddRange(errors.Where(e => !string.IsNullOrWhiteSpace(e)).ToList());
 69
 70
 71    /// <summary>
 72    /// Adds a non-empty informational message to the output.
 73    /// </summary>
 74    /// <param name="message">The message to add.</param>
 75    public void AddMessage(string message)
 1776    {
 1777        if (string.IsNullOrWhiteSpace(message))
 678        {
 679            return;
 80        }
 81
 1182        Messages.Add(message);
 1783    }
 84
 85    /// <summary>
 86    /// Adds multiple informational messages to the output, ignoring empty or whitespace entries.
 87    /// </summary>
 88    /// <param name="messages">The collection of messages to add.</param>
 89    public void AddMessages(IEnumerable<string> messages) =>
 1990        Messages.AddRange(messages.Where(e => !string.IsNullOrWhiteSpace(e)).ToList());
 91
 92    /// <summary>
 93    /// Fluent helper to add a single error and return the same instance.
 94    /// </summary>
 95    /// <param name="error">The error to add.</param>
 96    /// <returns>The same <see cref="ProcessOutput"/> instance for chaining.</returns>
 97    public ProcessOutput WithError(string error)
 298    {
 299        AddError(error);
 100
 2101        return this;
 2102    }
 103
 104    /// <summary>
 105    /// Fluent helper to add multiple errors and return the same instance.
 106    /// </summary>
 107    /// <param name="errors">The errors to add.</param>
 108    /// <returns>The same <see cref="ProcessOutput"/> instance for chaining.</returns>
 109    public ProcessOutput WithErrors(IEnumerable<string> errors)
 1110    {
 1111        AddErrors(errors);
 112
 1113        return this;
 1114    }
 115
 116    /// <summary>
 117    /// Fluent helper to add a single informational message and return the same instance.
 118    /// </summary>
 119    /// <param name="message">The message to add.</param>
 120    /// <returns>The same <see cref="ProcessOutput"/> instance for chaining.</returns>
 121    public ProcessOutput WithMessage(string message)
 2122    {
 2123        AddMessage(message);
 124
 2125        return this;
 2126    }
 127
 128    /// <summary>
 129    /// Fluent helper to add multiple informational messages and return the same instance.
 130    /// </summary>
 131    /// <param name="messages">The messages to add.</param>
 132    /// <returns>The same <see cref="ProcessOutput"/> instance for chaining.</returns>
 133    public ProcessOutput WithMessages(IEnumerable<string> messages)
 1134    {
 1135        AddMessages(messages);
 136
 1137        return this;
 1138    }
 139}