shellprogressbar icon indicating copy to clipboard operation
shellprogressbar copied to clipboard

how to test a project for useing ShellProgressBar?

Open wangshuai-007 opened this issue 5 years ago • 2 comments

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?

wangshuai-007 avatar Apr 02 '20 06:04 wangshuai-007

same issue with xunit here, as with xunit there's no console that ShellProgressBar can attach.

bonesoul avatar Aug 14 '20 22:08 bonesoul

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)```

Bencargs avatar Feb 12 '21 06:02 Bencargs