-
Notifications
You must be signed in to change notification settings - Fork 15
Make configuration work independent of whether appsettings json files are provided #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Arash-Sabet
merged 8 commits into
Umplify:main
from
ChrisDoernen:get-configuration-root-regardless
Dec 21, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8c61cca
Make configuration work independent of whether appsettings json files…
ChrisDoernen 7e77c4a
Merge branch 'main' into get-configuration-root-regardless
Arash-Sabet b4dc253
Programatically set (random) user secrets using dotnet command. Then …
ChrisDoernen e266a22
Merge remote-tracking branch 'origin/get-configuration-root-regardles…
ChrisDoernen 5c94822
Revert "Programatically set (random) user secrets using dotnet comman…
ChrisDoernen 5fcbc46
Add explicit test class for testing configuration without test appset…
ChrisDoernen 16600bb
Update pipeline configs and clean up test code
Arash-Sabet 319612d
Skip empty filenames in configuration loading
Arash-Sabet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
.../Xunit.Microsoft.DependencyInjection.ExampleTests/ConfigurationTestsWithoutAppsettings.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| namespace Xunit.Microsoft.DependencyInjection.ExampleTests; | ||
|
|
||
| public class ConfigurationTestsWithoutAppsettings : TestBed<TestProjectFixtureWithoutAppsettings> | ||
| { | ||
| private const string Key = "CONFIG_KEY"; | ||
| private const string Value = "Value"; | ||
|
|
||
| public ConfigurationTestsWithoutAppsettings(ITestOutputHelper testOutputHelper, TestProjectFixtureWithoutAppsettings fixture) | ||
| : base(testOutputHelper, fixture) | ||
| { | ||
| Environment.SetEnvironmentVariable(Key, Value); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void EnvironmentVariablesViaConstructorAreAvailable() | ||
| { | ||
| _fixture.GetServiceProvider(_testOutputHelper); | ||
| var value = _fixture.Configuration!.GetValue<string>(Key); | ||
| Assert.Equal(Value, value); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...crosoft.DependencyInjection.ExampleTests/Fixtures/TestProjectFixtureWithoutAppsettings.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| namespace Xunit.Microsoft.DependencyInjection.ExampleTests.Fixtures; | ||
|
|
||
| public class TestProjectFixtureWithoutAppsettings : TestBedFixture | ||
| { | ||
| protected override void AddServices(IServiceCollection services, IConfiguration configuration) | ||
| { | ||
| } | ||
|
|
||
| protected override ValueTask DisposeAsyncCore() => new(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,12 +123,12 @@ public async ValueTask DisposeAsync() | |
| /// <summary> | ||
| /// Adds services to the service collection. Called once before building the provider. | ||
| /// </summary> | ||
| protected abstract void AddServices(IServiceCollection services, IConfiguration? configuration); | ||
| protected abstract void AddServices(IServiceCollection services, IConfiguration configuration); | ||
|
|
||
| /// <summary> | ||
| /// Returns the test application settings descriptors (JSON files) to include. | ||
| /// </summary> | ||
| protected abstract IEnumerable<TestAppSettings> GetTestAppSettings(); | ||
| protected virtual IEnumerable<TestAppSettings> GetTestAppSettings() => []; | ||
|
|
||
| /// <summary> | ||
| /// Override to asynchronously clean up resources created by the fixture. | ||
|
|
@@ -147,18 +147,15 @@ protected virtual ILoggingBuilder AddLoggingProvider(ILoggingBuilder loggingBuil | |
| /// </summary> | ||
| protected virtual void AddUserSecrets(IConfigurationBuilder configurationBuilder) { } | ||
|
|
||
| private IConfigurationRoot? GetConfigurationRoot() | ||
| private IConfigurationRoot GetConfigurationRoot() | ||
| { | ||
| var testAppSettings = GetTestAppSettings(); | ||
| return | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ChrisDoernen what is the reason for removing the condition? |
||
| testAppSettings.All(setting => !string.IsNullOrEmpty(setting.Filename)) | ||
| ? GetConfigurationRoot(testAppSettings) | ||
| : default; | ||
| return GetConfigurationRoot(testAppSettings); | ||
| } | ||
|
|
||
| private IConfigurationRoot GetConfigurationRoot(IEnumerable<TestAppSettings> configurationFiles) | ||
| { | ||
| foreach (var configurationFile in configurationFiles) | ||
| foreach (var configurationFile in configurationFiles.Where(appSetting => !string.IsNullOrEmpty(appSetting.Filename))) | ||
| { | ||
| ConfigurationBuilder.AddJsonFile(configurationFile.Filename!, optional: configurationFile.IsOptional); | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ChrisDoernen Can you please restore the original implementation of
ConfigurationTerstsclass and instead add a new configuration tests class to verifyTestProjectFixtureWithoutAppsettings's implementation?