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

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

Closed
shanselman opened this Issue Apr 1, 2018 · 8 comments

Comments

Projects
None yet
5 participants
@shanselman

shanselman commented Apr 1, 2018

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 from No easy way to change ASPNETCORE_ENVIRONMENT or get User Secrets with WebApplicationTextFixture to No easy way to change ASPNETCORE_ENVIRONMENT or get UserSecrets with WebApplicationTestFixture Apr 1, 2018

@davidfowl

This comment has been minimized.

Member

davidfowl commented Apr 1, 2018

@shanselman

This comment has been minimized.

shanselman commented Apr 1, 2018

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

This comment has been minimized.

Contributor

mkArtakMSFT commented Apr 2, 2018

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

@rynowak

This comment has been minimized.

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

This comment has been minimized.

shanselman commented Apr 10, 2018

@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

This comment has been minimized.

Member

javiercn commented Apr 10, 2018

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 label Apr 10, 2018

@shanselman

This comment has been minimized.

shanselman commented Apr 10, 2018

@mkArtakMSFT mkArtakMSFT added cost: XS and removed cost: S labels Apr 10, 2018

@javiercn

This comment has been minimized.

Member

javiercn commented Apr 13, 2018

@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 javiercn added 2 - Working and removed 1 - Ready labels Apr 13, 2018

@javiercn javiercn closed this in 22510e1 Apr 13, 2018

javiercn added a commit that referenced this issue Apr 13, 2018

javiercn added a commit that referenced this issue Apr 14, 2018

[Fixes #7587, #7635]
* 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

[Fixes #7587, #7635]
* No easy way to change ASPNETCORE_ENVIRONMENT
* Provide a way to configure clients in WebApplicationFactory

@javiercn javiercn reopened this Apr 16, 2018

javiercn added a commit that referenced this issue Apr 16, 2018

javiercn added a commit that referenced this issue Apr 17, 2018

@javiercn javiercn closed this in e0b4c13 Apr 17, 2018

@javiercn javiercn added the 3 - Done label Apr 17, 2018

@javiercn javiercn removed the 2 - Working label Apr 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment