In the section "Customize WebApplicationFactory", it says:
> The SUT's database context is registered in its Startup.ConfigureServices method. The test app's builder.ConfigureServices callback is executed after the app's Startup.ConfigureServices code is executed.
This is incorrect. If you follow the guide with breakpoints, you can see that it's the other way around and the test app's builder.ConfigureServices is run before the real Startup class's method. It's a quite dangerous guidance as well since the "real" services could end up being used for tests rather than the test versions.
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Hello @SaebAmini ... Are you using ASP.NET Core 2.2 (or earlier) or 3.0 or later? We made some changes to the topic recently regarding order there, which changed with the 3.0 release. If you set the doc version selector back to 2.2, you'll see that line disappear.
I am using ASP.NET Core 2.2, and you're correct that it does disappear. So is this a breaking change between 2.2 and 3.0? if so, what's the reason for this breaking change?
Stand-by ... I'll see if I can track it down.
Might be explained here where Javier speaks about the new Generic Host (at 3.0) and old Web Host (prior to 3.0) :point_right: https://github.com/aspnet/AspNetCore/issues/13918#issuecomment-532162945
I'll see if there was an announcement on it next.
I don't see a formal announcement ... it was brought to my attention by a member (or two) of the community who were having trouble getting service replacements to work and by Javier who explained it out and assisted with the topic updates. The work was done here :point_right: https://github.com/aspnet/AspNetCore.Docs/pull/15096. If you flip that over to its diff, you can see exactly what the changes were, including the lines that you're asking about here.
Your best bet is to work from the 2.2 version of the topic and the 2.x sample app if you're not upgrading to 3.1 (released today :tada:). That 2.2 content and 2.x sample app should apply to your scenario, and ordering should be as you expect.
I'll close as answered, but ping me back here for further discussion if needed.
Oh ... and the closest that I could find on the _two containers_ to _one_ is the remark on this announcement :point_right: https://github.com/aspnet/Announcements/issues/353; but as you can see, it doesn't get into the weeds like Javier's answer on that issue does.
Wow, thanks so much for your amazingly quick response and great info @guardrex! if it wasn't for your detailed and relevant responses I would have suspected I'm getting automated answers! 😄
Back to the point, while the explanation and links make it clearer, I find this change super confusing, and I think it should be called out clearly in the docs that this has been a breaking change compared to previous versions because it totally flips the flow which could be dangerous.
What's more confusing to me is now I'm not sure whether in 2.2 it is actually _meant_ for this to run _before_, because there's no mention of the order in the 2.2 version of the official docs, and looking back at other unofficial information, e.g. https://andrewlock.net/converting-integration-tests-to-net-core-3/, there is no mention of this order change, and the sample code is relying on the overriden method to run _after_ (like 3.0).
I can take a look, but there will be a delay. The 🎁 holidays ⛄️ are here, and I'm out for three weeks ... _in two weeks_ WOOT! :smile: I'll schedule this for January.
This issue is closely related to https://github.com/aspnet/AspNetCore.Docs/issues/14973
Moved to #16341: Integration tests MASTER issue
Most helpful comment
This issue is closely related to https://github.com/aspnet/AspNetCore.Docs/issues/14973