Open bonesoul opened 4 years ago
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.
Maybe you could implement/mock IProgressBar and use dependency injection in parts that will be unit tested?
right now with in my unit tests getting invalid handle error;