Die Konfiguration kann bei Integrationstests in ASP.NET CORE, AddInMemoryCollection () nicht funktioniert, nicht übergeb

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Die Konfiguration kann bei Integrationstests in ASP.NET CORE, AddInMemoryCollection () nicht funktioniert, nicht übergeb

by Anonymous » 17 Aug 2025, 17:08

Ich habe diesen Code in meinem Integrationstest: < /p>

Code: Select all

public AuthControllerTests(
WebApplicationFactory factory,
AuthPgsqlContainerFixture authPgsqlContainerFixture,
MaterialsPgsqlContainerFixture materialsPgsqlContainerFixture
)
{
_authDbFixture = authPgsqlContainerFixture;
_materialsDbFixture = materialsPgsqlContainerFixture;

var customFactory = factory.WithWebHostBuilder(builder =>
{
builder.UseEnvironment("Development");

builder.ConfigureAppConfiguration((context, config) =>
{
var overrides = new Dictionary
{
{ "ConnectionStrings:AuthConnection", _authDbFixture.ConnectionString },
{ "ConnectionStrings:MaterialsConnection", _materialsDbFixture.ConnectionString }
};

//config.AddInMemoryCollection(overrides); // this did not work so I tried the below line, but that didn't work either
config = config.AddInMemoryCollection(overrides);
});
});

_client = customFactory.CreateClient();
}
< /code>
Die Vorrichtungen stammen von TestContainern. Ich versuche, die Verbindungszeichenfolgen aus meinen Testcontainern für die Tests zu übergeben.
In meinem Programmvar builder = WebApplication.CreateBuilder(args);
var connstring = builder.Configuration.GetConnectionString("AuthConnection");
Es wird immer noch die Verbindungszeichenfolgen von appsettings.development.json abgerufen, nicht die von den Leuchten zurückgegeben. Was mache ich falsch? Nach dem Entfernen der Werte von JSON gibt GetConnectionString () null zurück und beweist, dass AddInmemoryCollection () nichts tut.
Danke im Voraus

Top