< Summary

Information
Class: ArturRios.Output.ProcessOutput
Assembly: ArturRios.Output
File(s): D:\Repositories\dotnet-output\src\ProcessOutput.cs
Line coverage
100%
Covered lines: 35
Uncovered lines: 0
Coverable lines: 35
Total lines: 125
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage
100%
Covered methods: 13
Fully covered methods: 7
Total methods: 13
Method coverage: 100%
Full method coverage: 53.8%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Messages()100%11100%
get_Errors()100%11100%
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{
 9    /// <summary>
 10    /// Collection of informational messages produced during the process.
 11    /// </summary>
 5412    public List<string> Messages { get; } = [];
 13
 14    /// <summary>
 15    /// Collection of error messages produced during the process. If this list
 16    /// is empty the <see cref="Success"/> property evaluates to <c>true</c>.
 17    /// </summary>
 6618    public List<string> Errors { get; } = [];
 19
 20    /// <summary>
 21    /// UTC timestamp representing when this output instance was created.
 22    /// </summary>
 4023    public DateTime Timestamp { get; } = DateTime.UtcNow;
 24
 25    /// <summary>
 26    /// Indicates whether the process completed successfully (no errors were added).
 27    /// </summary>
 1328    public bool Success => Errors.Count == 0;
 29
 30    /// <summary>
 31    /// Creates a new <see cref="ProcessOutput"/> instance.
 32    /// </summary>
 933    public static ProcessOutput New => new();
 34
 35    /// <summary>
 36    /// Adds a non-empty error message to the output.
 37    /// </summary>
 38    /// <param name="error">The error message to add.</param>
 39    public void AddError(string error)
 940    {
 941        if (string.IsNullOrWhiteSpace(error))
 542        {
 543            return;
 44        }
 45
 446        Errors.Add(error);
 947    }
 48
 49    /// <summary>
 50    /// Adds multiple error messages to the output, ignoring empty or whitespace entries.
 51    /// </summary>
 52    /// <param name="errors">The collection of errors to add.</param>
 53    public void AddErrors(IEnumerable<string> errors) =>
 2054        Errors.AddRange(errors.Where(e => !string.IsNullOrWhiteSpace(e)).ToList());
 55
 56
 57    /// <summary>
 58    /// Adds a non-empty informational message to the output.
 59    /// </summary>
 60    /// <param name="message">The message to add.</param>
 61    public void AddMessage(string message)
 1062    {
 1063        if (string.IsNullOrWhiteSpace(message))
 664        {
 665            return;
 66        }
 67
 468        Messages.Add(message);
 1069    }
 70
 71    /// <summary>
 72    /// Adds multiple informational messages to the output, ignoring empty or whitespace entries.
 73    /// </summary>
 74    /// <param name="messages">The collection of messages to add.</param>
 75    public void AddMessages(IEnumerable<string> messages) =>
 1976        Messages.AddRange(messages.Where(e => !string.IsNullOrWhiteSpace(e)).ToList());
 77
 78    /// <summary>
 79    /// Fluent helper to add a single error and return the same instance.
 80    /// </summary>
 81    /// <param name="error">The error to add.</param>
 82    /// <returns>The same <see cref="ProcessOutput"/> instance for chaining.</returns>
 83    public ProcessOutput WithError(string error)
 184    {
 185        AddError(error);
 86
 187        return this;
 188    }
 89
 90    /// <summary>
 91    /// Fluent helper to add multiple errors and return the same instance.
 92    /// </summary>
 93    /// <param name="errors">The errors to add.</param>
 94    /// <returns>The same <see cref="ProcessOutput"/> instance for chaining.</returns>
 95    public ProcessOutput WithErrors(IEnumerable<string> errors)
 196    {
 197        AddErrors(errors);
 98
 199        return this;
 1100    }
 101
 102    /// <summary>
 103    /// Fluent helper to add a single informational message and return the same instance.
 104    /// </summary>
 105    /// <param name="message">The message to add.</param>
 106    /// <returns>The same <see cref="ProcessOutput"/> instance for chaining.</returns>
 107    public ProcessOutput WithMessage(string message)
 1108    {
 1109        AddMessage(message);
 110
 1111        return this;
 1112    }
 113
 114    /// <summary>
 115    /// Fluent helper to add multiple informational messages and return the same instance.
 116    /// </summary>
 117    /// <param name="messages">The messages to add.</param>
 118    /// <returns>The same <see cref="ProcessOutput"/> instance for chaining.</returns>
 119    public ProcessOutput WithMessages(IEnumerable<string> messages)
 1120    {
 1121        AddMessages(messages);
 122
 1123        return this;
 1124    }
 125}