dotnet / dotnet/aspnetcore

Overriding ApplicationName on Integration Tests

Open
#50,316 3 comments 1 reaction 0 assignees View on GitHub
area-networking
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

It seems `IHostingEnvironment.ApplicationName` is always used during integration tests even if I have defined on my `appsettings` an entry of `ApplicationName`

I believe this is set via the command line args (automatically by the framework) when running the tests and overriding it via `UseSettings` with the value from your config, app will throw a `FileNotFoundException` which makes sense.

Running the app normally seems fine since the command line args is empty anyway

For context, the value on my config is just a generic description of the app (e.g. MyApp), not using minimal API but using top-level statement. Also using .NET6 and ASPNETCore 6

Already seen https://github.com/dotnet/aspnetcore/issues/11085, https://github.com/dotnet/aspnetcore/issues/7315, https://github.com/dotnet/aspnetcore/issues/34914 but none of them work for my scenario

I have tried using `WebApplication.CreateBuilder()` (without the args) however, it will always use Production settings on integration tests

Is there a proper way to override this?

### Expected Behavior

Value from appsettings should be used

### Steps To Reproduce

https://github.com/glennfordd/OverrideApplicationName

### Exceptions (if any)

_No response_

### .NET Version

6

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.