Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow option to disable rendering for code that's ran by unit testers. #69

Open
bonesoul opened this issue Aug 14, 2020 · 2 comments
Open

Comments

@bonesoul
Copy link

right now with in my unit tests getting invalid handle error;

"System.IO.IOException: The handle is invalid.
   at System.ConsolePal.GetBufferInfo(Boolean throwOnNoConsole, Boolean& succeeded)
   at System.Console.get_CursorTop()
   at ShellProgressBar.ProgressBar..ctor(Int32 maxTicks, String message, ProgressBarOptions options)
@LevYas
Copy link

LevYas commented Jan 19, 2021

I had exactly the same problem. As a quick fix, I used a "proxy" pattern:

public sealed class ProgressBarProxy : IDisposable
{
    private readonly ProgressBar? _progressBar;

    public ProgressBarProxy(int maxTicks, string message)
        => _progressBar = Console.IsOutputRedirected ? null : new ProgressBar(maxTicks, message);

    public void Tick(string? message = null) => _progressBar?.Tick(message);
    public void Dispose() => _progressBar?.Dispose();
}

But it would be nice if that check will be inside the constructor.

@mrwensveen
Copy link

Maybe you could implement/mock IProgressBar and use dependency injection in parts that will be unit tested?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants