AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

CreateHostBuilder / configuration to a specific environement

Open FredCni opened this issue 3 years ago • 2 comments

In the "Set the environment" section, the doc refers to setting the value of env variables w/o showing how to do it. But the goal can be achieved that way. I suggest you add this code snippet:

protected override IHostBuilder CreateHostBuilder() =>
        base.CreateHostBuilder().ConfigureWebHost(x => x.UseEnvironment("integration"));

The derived WebApplicationFactory will therefore create the SUT with a specific environment, which allows for example to use a specific appsetting.ENV.json defined in the API project (as you'd have an appsetting.Development.json, etc...)


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

FredCni avatar Jun 08 '22 06:06 FredCni

@javiercn can I add the following tip?

Rick-Anderson avatar Jun 08 '22 18:06 Rick-Anderson

@Rick-Anderson sounds fine with me.

/cc: @captainsafia

javiercn avatar Jun 09 '22 12:06 javiercn

Is anyone working on this issue? Otherwise, I'd like to try it out, I'm new to open-source.

kianiehsan66 avatar Nov 10 '22 10:11 kianiehsan66

Is anyone working on this issue? Otherwise, I'd like to try it out, I'm new to open-source.

@kianiehsan66 help would be appreciated. The first step would be updating https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/test/integration-tests/samples/3.x/IntegrationTestsSample to show how it works.

Rick-Anderson avatar Nov 10 '22 18:11 Rick-Anderson

Looks like it's there now.

Rick-Anderson avatar Jan 26 '23 01:01 Rick-Anderson