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

VSTest and WebApplicationFactory fails when using RunOaktonCommands #88

Open
schmitch opened this issue Apr 10, 2024 · 2 comments
Open

Comments

@schmitch
Copy link

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
Copy link
Member

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

@esond
Copy link

esond commented Oct 31, 2024

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

Thanks!

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