Tests: route Yavsc.Org test host through Testing environment
TestWebApplicationFactory used ASPNETCORE_ENVIRONMENT=Development, which
caused Program.Main's AddConfiguration("org") to load the tracked
appsettings-org.json (the reference file with the
'*** via dotnet user-secrets ou variable d'environnement ***'
placeholder connection string). Npgsql then failed to parse that
placeholder during host startup, failing six integration tests
(observed 2026-07-11: System.ArgumentException on
NpgsqlConnectionStringBuilder.set_Item).
Switching the test host to a dedicated Testing environment makes
AddConfiguration("org") pick up the new optional
appsettings-org.Testing.json file as the last source in the chain
(JSON → env vars), which overrides YavscConnection with the
InMemory marker and the Smtp section with the test stub values.
The .gitignore exception whitelists this file explicitly: it is a
configuration source for the test host, not a secrets file.
The WebServerFixture path is unchanged — it owns its
WebApplicationBuilder and adds the same in-memory override via its
BuildApp hook.
This commit is contained in:
parent
cb7526de9d
commit
7a066707b3
3 changed files with 29 additions and 4 deletions
9
.gitignore
vendored
9
.gitignore
vendored
|
|
@ -24,6 +24,15 @@ data/
|
|||
appsettings.*.json
|
||||
appsettings-*.*.json
|
||||
|
||||
# Exception: the Testing-environment override for Yavsc.Org is a tracked
|
||||
# configuration source, not a secrets file. TestWebApplicationFactory
|
||||
# (Yavsc.Org.Tests) flips ASPNETCORE_ENVIRONMENT to "Testing" so
|
||||
# AddConfiguration("org") in Program.Main loads this file as the
|
||||
# last in the chain (it is optional). It overrides the connection
|
||||
# string and SMTP section for the in-memory test host and contains
|
||||
# no production secrets.
|
||||
!src/Yavsc.Org/appsettings-org.Testing.json
|
||||
|
||||
generated/
|
||||
*.tmp
|
||||
DataDir/
|
||||
|
|
|
|||
|
|
@ -26,10 +26,15 @@ public class TestWebApplicationFactory : WebApplicationFactory<Program>
|
|||
{
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
{
|
||||
// UseDevelopmentEnvironment triggers the dev signing credential
|
||||
// path in the production startup, so we don't need a real cert
|
||||
// to satisfy IdentityServer at boot.
|
||||
builder.UseEnvironment("Development");
|
||||
// UseEnvironment("Testing") puts the host in a dedicated
|
||||
// configuration environment so AddConfiguration("org") in
|
||||
// Program.Main loads the optional appsettings-org.Testing.json
|
||||
// file (which overrides the connection string and SMTP section
|
||||
// for the test host). See that file for the values.
|
||||
// We don't use "Development" because that environment is also
|
||||
// used by the dev launcher and would change the signing
|
||||
// credential path in IdentityServer; "Testing" is unambiguous.
|
||||
builder.UseEnvironment("Testing");
|
||||
|
||||
builder.ConfigureTestServices(services =>
|
||||
{
|
||||
|
|
|
|||
11
src/Yavsc.Org/appsettings-org.Testing.json
Normal file
11
src/Yavsc.Org/appsettings-org.Testing.json
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"ConnectionStrings": {
|
||||
"YavscConnection": "InMemory"
|
||||
},
|
||||
"Smtp": {
|
||||
"Host": "smtp.test.local",
|
||||
"Port": 465,
|
||||
"UserName": "test-user",
|
||||
"Password": "test-pass"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue