Skip to content

Add regression tests for generic AddJsonFile named options (#39) - #41

Closed
gerritgoetzen wants to merge 2 commits into
adams85:masterfrom
gerritgoetzen:test/json-named-options
Closed

Add regression tests for generic AddJsonFile named options (#39)#41
gerritgoetzen wants to merge 2 commits into
adams85:masterfrom
gerritgoetzen:test/json-named-options

Conversation

@gerritgoetzen

Copy link
Copy Markdown
Contributor

Regression test for #39 (depends on #40)

Adds a regression test pinning the bug from #39: the generic AddJsonFile<TProvider> / AddJsonFile<TProvider, TOptions> overloads registered the user configure callback against Options.DefaultName instead of the named options instance the provider resolves via IOptionsMonitor.Get(optionsName), so user configuration never reached the provider's own options.

What this contains

This branch is stacked on #40 (the fix), which isn't on master yet, so the diff currently shows two commits:

  1. d866c08 — the fix from Fix incorrect registration of user configuration actions in generic AddJsonFile overloads #40 (base only; not my work)
  2. the regression test (the actual contribution)

Once #40 merges into master, this PR reduces to just the test commit. If you'd prefer, the test can instead be folded directly into #40.

Coverage

Three [Fact]s in SettingsTest.cs, one per affected overload:

  • AddJsonFile<TProvider>(configure:, optionsName:)
  • AddJsonFile<TProvider, TOptions>(configure:, optionsName:)
  • AddJsonFile<TProvider, TOptions>(bindOptions, configure:, optionsName:)

Each builds the service provider, resolves IOptionsMonitor<FileLoggerOptions>.Get(optionsName), and asserts the user-configured sentinel (BasePath) lands on the named instance and not on Options.DefaultName. BasePath is the sentinel rather than RootPath because RootPath's setter eagerly constructs a PhysicalFileAppender that validates the directory on disk.

Verification (net10.0)

Closes #39 once #40 is in.

adams85 and others added 2 commits May 29, 2026 22:53
The generic AddJsonFile overloads must apply the user configuration
callback to the named options instance that the provider resolves via
IOptionsMonitor.Get(optionsName). Before the fix the callback was
registered against Options.DefaultName, so it never reached the
provider's own options (adams85#39). Each of the three
affected overloads is pinned independently: the tests fail against the
pre-fix source and pass with the fix (adams85#40).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@adams85

adams85 commented May 31, 2026

Copy link
Copy Markdown
Owner

Thanks for the tests!

Closing as merged into #40

@adams85 adams85 closed this May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generic AddJsonFile<TProvider>(configure:) registers configure on Options.DefaultName — unfixed half of #22

2 participants