JasperFx / oakton

Parsing and Utilities for Command Line Tools in .Net
http://jasperfx.github.io/oakton
Apache License 2.0
308 stars 40 forks source link

VSTest and WebApplicationFactory fails when using RunOaktonCommands #88

Open schmitch opened 7 months ago

schmitch commented 7 months ago

hello, i'm not sure if that counts as a bug/issue, so feel free to close it. but i stumbled upon it while integrating oakton (we use martendb and I really really like how oakton makes it easy to add one of commands)

so anyway we use vstest (dotnet test) and xunit to run unit tests: https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-8.0 however when using them while also using oakton some test fails, because we do something like that:

    protected override void ConfigureWebHost(IWebHostBuilder builder)
    {
        builder
            .UseSetting("Sentry:Dsn", string.Empty)
            .UseSetting("IsTesting", "true")
   }

however somehow it will than append that as args when running the program á la dotnet run -- --Sentry= this is something we have no control of so the test of course will fail.

at the moment we "fixed" it somewhat by using it like that:

if (app.Configuration.GetValue<bool>("IsTesting"))
{
    await app.RunAsync();
    return 0;
}

return await app.RunOaktonCommands(args);

but that feels a little bit less integrated so I wondered if there is a better solution?

I also removed both settings and it fails with another one

jeremydmiller commented 1 month ago

@schmitch Sorry for the very, very slow response. In your tests, try OaktonEnvironment.AutoStart = true; before bootstrapping

esond commented 6 days ago

@jeremydmiller This worked for me, but the property is (now) called OaktonEnvironment.AutoStartHost.

Thanks!