Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

No easy way to change ASPNETCORE_ENVIRONMENT or get UserSecrets with WebApplicationTestFixture #7587

Closed
shanselman opened this issue Apr 1, 2018 · 8 comments
Assignees
Labels
3 - Done cost: XS Will take up to half a day to complete enhancement
Milestone

Comments

@shanselman
Copy link

Trying to follow https://blogs.msdn.microsoft.com/webdev/2018/03/05/asp-net-core-2-1-0-preview1-functional-testing-of-mvc-applications/

The defaults are not sensible. I should not have to do this, to just use Development, or use User Secrets:

public class MyOwnTextFixture<TStartup> : WebApplicationTestFixture<Startup> where TStartup : class
  {
          public MyOwnTextFixture() { }

          protected override void ConfigureWebHost(IWebHostBuilder builder)
          {
              builder.UseEnvironment("Development");
          }
  }

@davidfowl

@shanselman shanselman changed the title No easy way to change ASPNETCORE_ENVIRONMENT or get User Secrets with WebApplicationTextFixture No easy way to change ASPNETCORE_ENVIRONMENT or get UserSecrets with WebApplicationTestFixture Apr 1, 2018
@davidfowl
Copy link
Member

@javiercn

@shanselman
Copy link
Author

The secrets are coming out null, and the Config object that's injected into my pages are not the same one I made before.

@mkArtakMSFT
Copy link
Member

Adding @rynowak, just in case he may have some ideas, as @javiercn is out.

@rynowak
Copy link
Member

rynowak commented Apr 9, 2018

I think the proposed fix here is to use the Development environment rather than creating something new for tests. Is there anything else that was needed?

We want to also make sure that it's reasonable to set the environment as well, and add a code sample to the docs.

@shanselman
Copy link
Author

@rynowak There's still (I think) an underlying issue...even if I change the Environment, I can't seem to access "WebProject1"'s UserSecrets from "TestProject1." There is something there, unrelated to Environment.

@javiercn
Copy link
Member

We are discussing this. Will update shortly. Regarding user secrets, can it be that is looking for the user secrets for your test assembly instead of for your app assembly? I will have to look into it in more detail

@javiercn javiercn added the cost: S Will take up to 2 days to complete label Apr 10, 2018
@shanselman
Copy link
Author

shanselman commented Apr 10, 2018 via email

@mkArtakMSFT mkArtakMSFT added cost: XS Will take up to half a day to complete and removed cost: S Will take up to 2 days to complete labels Apr 10, 2018
@javiercn
Copy link
Member

@shanselman Hey Scott, I was able to get the user secrets once I set the environment to development on my test. (I'm using preview2 for the repro).

Can you tell me more about how you were setting the environment/ping me to take a look at your app with you? It won't take us long.

javiercn added a commit that referenced this issue Apr 13, 2018
javiercn added a commit that referenced this issue Apr 14, 2018
* No easy way to change ASPNETCORE_ENVIRONMENT
* Provide a way to configure clients in WebApplicationFactory
javiercn added a commit that referenced this issue Apr 16, 2018
* No easy way to change ASPNETCORE_ENVIRONMENT
* Provide a way to configure clients in WebApplicationFactory
@javiercn javiercn reopened this Apr 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3 - Done cost: XS Will take up to half a day to complete enhancement
Projects
None yet
Development

No branches or pull requests

5 participants