Skip to content

Unable to load/reference appsettings.json when integration testing an ASP.NET Core WebApi app using MVC.Testing #9275

@PureKrome

Description

@PureKrome

Hi there 👋

I'm trying to do a basic integration test for a very simple ASP.NET Core WebApi project.

I'm leveraging the WebApplicationFactory class and when I do this, my appsettings.json file located in my test project is not getting used. The appsettings.development.json file in the WebApi project (the SUT) is getting used.

I've tried to use Source Link/Source Debugging using the MS Symbol Server to step through the WebApplicationFactory class to figure out why/what. It's a bit hard to grok.

I even sorta tried to use the TEST_CONTENTROOT_APPNAME trick/hack I noticed in the source code but I couldn't get that to work properly (I think i'm not correctly adding this via my custom protected override IWebHostBuilder CreateWebHostBuilder() method early on in the bootstrapping).

Anyways -> can anyone (repo members?) please provide some clues to how I can use my own appsettings.json locally in my test project ... and not the ones in the SUT.

Why?

SUT appsettings.development.json : db points to localhost
Test project appsettings.json : db will point to some 'dev' server in the cloud.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesquestion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions