how to test a project for useing ShellProgressBar?
I create a project using CommandLineUtils
and I use ShellProgressBar for my command ,when I use dotnet tool command,the ShellProgressBar works well.
But there are some bugs in my project,I want to fix them by UnitTest
then,I test my command like this
[Fact]
public void DownloadFileFromFtp()
{
var content=new CommandLineApplication<DownloadFtp>();
var services = new ServiceCollection()
.AddLogging()
.AddSingleton(Program.Configuration)
.AddSingleton(Program.Configuration.Get<APPConfig>())
.BuildServiceProvider();
content.Conventions
.UseDefaultConventions()
.UseConstructorInjection(services);
content.Parse();
var result = content.Execute(@"--path=/CUSTDB/1901-0048.rar", "--taskid=1907-7777");//run the command
result.Should().Be(0);
}
and then I will get System.IO.IOException: 句柄无效 error
the Stack Trace like this
Stack Trace:
ConsolePal.GetBufferInfo(Boolean throwOnNoConsole, Boolean& succeeded)
Console.get_CursorTop()
ProgressBar.ctor(Int32 maxTicks, String message, ProgressBarOptions options)
DownloadFtp.SaveFileFromFtp(CommandLineApplication app, String remoteFilePath, String taskId) line 134
if I debug the UnitTest ,it will not get the error.
I think,the reason is UnitTest do not run in a shell
so,how can I solve this problem?
or,what is the right way to UnitTest ShellProgressBar?
same issue with xunit here, as with xunit there's no console that ShellProgressBar can attach.
Having similar issues, but differant stack trace when running an NUnit test:
System.IO.IOException : The handle is invalid.
at System.ConsolePal.GetBufferInfo(Boolean throwOnNoConsole, Boolean& succeeded)
at System.ConsolePal.GetCursorPosition()
at System.Console.get_CursorTop()
at ShellProgressBar.ProgressBar..ctor(Int32 maxTicks, String message, ProgressBarOptions options)```