using CliFx.Infrastructure;

namespace ZB.MOM.WW.OtOpcUa.Client.CLI.Tests;

/// <summary>
///     Helper for creating CliFx <see cref="FakeInMemoryConsole" /> instances and reading their output.
/// </summary>
public static class TestConsoleHelper
{
    /// <summary>
    ///     Creates a new <see cref="FakeInMemoryConsole" /> for testing.
    /// </summary>
    public static FakeInMemoryConsole CreateConsole()
    {
        return new FakeInMemoryConsole();
    }

    /// <summary>
    ///     Reads all text written to the console's standard output.
    /// </summary>
    /// <param name="console">The fake console instance.</param>
    /// <returns>The console output text.</returns>
    public static string GetOutput(FakeInMemoryConsole console)
    {
        console.Output.Flush();
        return console.ReadOutputString();
    }

    /// <summary>
    ///     Reads all text written to the console's standard error.
    /// </summary>
    /// <param name="console">The fake console instance.</param>
    /// <returns>The console error text.</returns>
    public static string GetError(FakeInMemoryConsole console)
    {
        console.Error.Flush();
        return console.ReadErrorString();
    }
}