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

how to test a project for useing ShellProgressBar? #61

Open
wangshuai-007 opened this issue Apr 2, 2020 · 2 comments
Open

how to test a project for useing ShellProgressBar? #61

wangshuai-007 opened this issue Apr 2, 2020 · 2 comments

Comments

@wangshuai-007
Copy link

wangshuai-007 commented Apr 2, 2020

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?

@bonesoul
Copy link

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

@Bencargs
Copy link

Bencargs commented Feb 12, 2021

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

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