-
Notifications
You must be signed in to change notification settings - Fork 10.4k
React to WebHostBuilderFactory changes #6585
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
Conversation
webHostBuilder.ConfigureServices( | ||
s => s.AddSingleton<IStartupConfigureServicesFilter>( | ||
new ConfigureTestServicesStartupConfigureServicesFilter(servicesConfiguration))); | ||
if (webHostBuilder.GetType().Name.Equals("GenericWebHostBuilder")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hacky, I like it 😄
src/Mvc/src/Microsoft.AspNetCore.Mvc.Testing/WebApplicationFactory.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall the PR looks good, but there are some changes we need to address before we move forward to ensure backwards compat and that the same user experience is preserved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor project-file things.
src/Mvc/src/Microsoft.AspNetCore.Mvc.Testing/Microsoft.AspNetCore.Mvc.Testing.csproj
Outdated
Show resolved
Hide resolved
src/Mvc/test/WebSites/GenericHostWebSite/GenericHostWebSite.csproj
Outdated
Show resolved
Hide resolved
639ccdf
to
e6576d5
Compare
@javiercn I added a protected method for CreateHostBuilder. CreateTestServer wasn't salvageable. I tried changing it to |
Co-Authored-By: Tratcher <[email protected]>
…ore.Mvc.Testing.csproj Co-Authored-By: Tratcher <[email protected]>
8fe2013
to
6ee1615
Compare
@javiercn I suggest we merge this for preview2 and follow up on further improvements. Ack? |
@Tratcher let me take a look first |
@Tratcher I imagine that's because of the side effect of assigning the host. Is that the case?
How much of the DelegatedWebApplicationFactoryModel broke? Everything, or only the CreateServer part? You could fix the Build() part by passing the WAF as a parameter and adding a protected method to set it that check is null or throws before setting it. That way if someone customizes it, we can still call their implementation and they can set it in a safe way. public virtual void CreateServer(WebApplicationFactory<TEntryPoint>waf, IHostBuilder builder) On our implementation CreateServer(this, builder); On a derived implementation ...something,
waf.SetInitializedHost(host);
... or ...something,
base.CreateServer(this,builder);
...something
... Another alternative is to break it into two public virtual IHost CreateHost(IHostBuilder builder) and We can clean it up after preview2, but I rather keep this working. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, just the feedback about CreateServer. If we change it to CreateHost(hostBuilder) and get rid of _server so that we can preserve the delegation model, we should be fine.
Approving from a project file/targets perspective only. I'll let others review the c# changes more carefully. |
Hmm, what if I split CreateServer like I did for CreateWebHostBuilder? E.g. I add a new |
Updated. CreateHost got everything working. |
Looks great! |
Question: are there plans to update the documentation for this here (https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-3.0)? Or is the change supposed to be backwards compatible such that there shouldn't be any changes to the docs? I'm on the latest preview build of .net core 3.0 and while converting our app from 2.2 to 3.0, all of our component tests which rely on WebApplicationFactory are now failing. It appears they're not honoring the mock services we try to inject into the TestServer before creating the client. Setup:
Usage in failed test:
Results in:
(##### replaces company-specific non-relevant namespace names). Please let me know if I should open a new issue but this seems directly related to the refactoring done on this ticket. |
@BlacKCaT27 Hi, thanks for contacting us. Could you file a new issue with your problem so that we can track this separately? We most likely will have to update the documentation for this. |
#6460, #5960 The shared sources packages was moved to Extensions and refactored to support the new generic host templates pattern. This change:
Note to make WebApplicationFactory work I needed to skip calling two protected methods: CreateWebHostBuilder and CreateTestServer. Also, ConfigureTestServices isn't needed anymore since there's only one container.