Skip to content

Deepen Apizr registration generator with adapter isolation and pipeline tests#1145

Merged
christianhelle merged 4 commits into
mainfrom
deepen-apizr-registration-generator
Jun 15, 2026
Merged

Deepen Apizr registration generator with adapter isolation and pipeline tests#1145
christianhelle merged 4 commits into
mainfrom
deepen-apizr-registration-generator

Conversation

@christianhelle

@christianhelle christianhelle commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Adds deeper test coverage for the Apizr registration generator by isolating adapter logic and introducing pipeline-level tests.

Description:

This pull request adds adapter isolation tests and pipeline tests for the Apizr registration generator, improving confidence in the individual adapter implementations and their composition.

Additionally, fixes a regression introduced by a CodeRabbit auto-fix that incorrectly moved the using MapsterMapper; directive outside the dependency-injection conditional branch in MappingProviderAdapter.cs. The directive is now correctly scoped to the DI-only path, so generated code without DI no longer includes the unnecessary using MapsterMapper; statement.

Summary by CodeRabbit

Summary by CodeRabbit

  • Refactor

    • Updated Apizr client code generation to use an adapter-based pipeline, composing base address, delegating handlers, retry policies, cache, mapping, priority, mediation, and file transfer more consistently and in the correct order.
  • Tests

    • Added unit and pipeline tests covering adapter applicability and generated output, including combined-feature scenarios and cases for mediation/cache/file transfer with and without dependency injection.

Extract IApizrOptionsBuilder and IApizrOptionsAdapter interfaces as the
seam between the generator and individual Apizr features. Each feature
(cache, mapping, retry, file transfer, mediation, priority, message
handlers) becomes its own adapter.

The refactored ApizrRegistrationGenerator.Generate() now composes
these adapters via a pipeline, keeping the same public signature and
producing identical output.
Add unit tests for each Apizr option adapter covering CanApply and
Apply behavior. Add pipeline combination tests verifying correct
composition order and combined output.
@christianhelle christianhelle added enhancement New feature, bug fix, or request .NET Pull requests that contain changes to .NET code labels Jun 14, 2026
@christianhelle christianhelle self-assigned this Jun 14, 2026
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 17b0d2a7-5cb9-4369-b0e6-0f069a5db84f

📥 Commits

Reviewing files that changed from the base of the PR and between e1c3b47 and 0ca6004.

📒 Files selected for processing (1)
  • src/Refitter.Core/MappingProviderAdapter.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Refitter.Core/MappingProviderAdapter.cs

📝 Walkthrough

Walkthrough

Introduces an adapter-based pipeline for Apizr options code generation. Two internal interfaces (IApizrOptionsAdapter, IApizrOptionsBuilder) and an ApizrOptionsBuilder implementation replace inline option construction in ApizrRegistrationGenerator. Seven adapters handle cache, file transfer, HTTP handlers, mapping, mediation, priority, and retry. Full per-adapter and pipeline integration tests are added.

Changes

Apizr Adapter-Based Options Pipeline

Layer / File(s) Summary
Adapter and builder contracts
src/Refitter.Core/IApizrOptionsAdapter.cs, src/Refitter.Core/IApizrOptionsBuilder.cs
Defines IApizrOptionsAdapter (CanApply/Apply) and IApizrOptionsBuilder (base address, delegating handler, HTTP client builder hook, options/using/package accumulation, and finalization) as internal interfaces.
ApizrOptionsBuilder implementation
src/Refitter.Core/ApizrOptionsBuilder.cs
Implements IApizrOptionsBuilder with two StringBuilders, a package set, and an options-added flag; BuildOptionsCode conditionally appends a trailing semicolon, and GetUsings/GetPackages expose accumulated outputs.
Seven concrete adapter implementations
src/Refitter.Core/CacheProviderAdapter.cs, src/Refitter.Core/FileTransferAdapter.cs, src/Refitter.Core/HttpMessageHandlerAdapter.cs, src/Refitter.Core/MappingProviderAdapter.cs, src/Refitter.Core/MediationAdapter.cs, src/Refitter.Core/PriorityAdapter.cs, src/Refitter.Core/RetryHandlerAdapter.cs
Adds one adapter per integration concern: CacheProviderAdapter switches on CacheProviderType; FileTransferAdapter branches on DI+mediation; HttpMessageHandlerAdapter iterates HttpMessageHandlers; MappingProviderAdapter handles AutoMapper and Mapster with/without DI; MediationAdapter guards on DI presence; PriorityAdapter emits Fusillade wiring; RetryHandlerAdapter generates Polly or HttpResilience retry configuration using invariant-culture backoff values.
Generator refactoring to adapter pipeline
src/Refitter.Core/ApizrRegistrationGenerator.cs
Replaces 221 lines of manual option construction with an IApizrOptionsAdapter[] loop: seeds initialOptionsCode, instantiates ApizrOptionsBuilder, conditionally calls WithBaseAddress, runs each applicable adapter, then embeds the built optionsCode string into all four output templates (extended registry/manager, static registry/manager) with simplified using-emission.
Per-adapter unit tests
src/Refitter.Tests/Apizr/HttpMessageHandlerAdapterTests.cs, src/Refitter.Tests/Apizr/CacheProviderAdapterTests.cs, src/Refitter.Tests/Apizr/FileTransferAdapterTests.cs, src/Refitter.Tests/Apizr/MappingProviderAdapterTests.cs, src/Refitter.Tests/Apizr/MediationAdapterTests.cs, src/Refitter.Tests/Apizr/PriorityAdapterTests.cs, src/Refitter.Tests/Apizr/RetryHandlerAdapterTests.cs
Adds CanApply true/false assertions and Apply generated-output assertions for all seven adapters, covering DI-conditional behavior for cache, mapping, file transfer, and mediation.
Pipeline integration tests
src/Refitter.Tests/Apizr/ApizrOptionsAdapterPipelineTests.cs
Exercises full adapter combinations via ApizrRegistrationGenerator.Generate: cache+mapping, retry+mediation, all-features ordering, compilable output verification, and error-marker generation when extended features are used without DI settings.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant ApizrRegistrationGenerator
    participant ApizrOptionsBuilder
    participant Adapters as IApizrOptionsAdapter[]

    Caller->>ApizrRegistrationGenerator: Generate(settings)
    ApizrRegistrationGenerator->>ApizrOptionsBuilder: new(initialOptionsCode, usings)
    ApizrRegistrationGenerator->>ApizrOptionsBuilder: WithBaseAddress(baseUrl, strategy)
    loop each adapter in pipeline
        ApizrRegistrationGenerator->>Adapters: CanApply(settings)
        alt can apply
            ApizrRegistrationGenerator->>Adapters: Apply(builder, settings)
            Adapters->>ApizrOptionsBuilder: AddPackage / AddUsing / AppendOptionsCode
        end
    end
    ApizrRegistrationGenerator->>ApizrOptionsBuilder: BuildOptionsCode()
    ApizrOptionsBuilder-->>ApizrRegistrationGenerator: optionsCode (with semicolon if HasOptions)
    ApizrRegistrationGenerator->>ApizrOptionsBuilder: GetUsings() / GetPackages()
    ApizrRegistrationGenerator-->>Caller: generated source string
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐇 Hoppity-hop through the pipeline I go,
Each adapter snapping options in a row!
CacheProvider, Retry, Mediation too—
No more giant switch blocks to muddle through.
The builder collects every using with care,
Then stamps a semicolon right at the end—there! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Deepen Apizr registration generator with adapter isolation and pipeline tests' accurately captures the main refactoring effort: extracting monolithic code into adapters and adding pipeline tests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch deepen-apizr-registration-generator

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.54%. Comparing base (25407ad) to head (0ca6004).
⚠️ Report is 20 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1145      +/-   ##
==========================================
+ Coverage   94.31%   94.54%   +0.23%     
==========================================
  Files          48       67      +19     
  Lines        2796     3100     +304     
==========================================
+ Hits         2637     2931     +294     
- Misses         53       59       +6     
- Partials      106      110       +4     
Flag Coverage Δ
unittests 94.54% <100.00%> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/Refitter.Core/ApizrOptionsBuilder.cs`:
- Around line 49-52: The AddPackage method in ApizrOptionsBuilder.cs adds
packages without checking for duplicates, causing unnecessary accumulation in
the _packages collection even though ApizrRegistrationGenerator.cs later
deduplicates during code generation. To fix this at the source, either modify
the AddPackage method to check if the package already exists in _packages before
adding it using a condition like !_packages.Contains(package), or replace the
_packages list with a HashSet<ApizrPackages> to automatically prevent
duplicates. The HashSet approach is preferred as it makes the deduplication
intent explicit and avoids unnecessary memory usage from duplicate entries.

In `@src/Refitter.Core/MappingProviderAdapter.cs`:
- Around line 27-38: The non-DI Mapster branch in the switch case generates code
with new Mapper() but the required using MapsterMapper; statement is only added
in the DI if block. The Mapper type is defined in the MapsterMapper namespace,
so the non-DI else branch fails to compile due to an unresolved symbol. Move the
builder.AddUsing("using MapsterMapper;"); call outside the if-else conditional
so it is added in both DI and non-DI scenarios, ensuring the Mapper type is
properly resolved in the generated code.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d7acc8d1-fba7-4d37-a11a-601677722fc0

📥 Commits

Reviewing files that changed from the base of the PR and between e819ceb and 4c9ebf9.

📒 Files selected for processing (19)
  • src/Refitter.Core/ApizrOptionsBuilder.cs
  • src/Refitter.Core/ApizrRegistrationGenerator.cs
  • src/Refitter.Core/CacheProviderAdapter.cs
  • src/Refitter.Core/FileTransferAdapter.cs
  • src/Refitter.Core/HttpMessageHandlerAdapter.cs
  • src/Refitter.Core/IApizrOptionsAdapter.cs
  • src/Refitter.Core/IApizrOptionsBuilder.cs
  • src/Refitter.Core/MappingProviderAdapter.cs
  • src/Refitter.Core/MediationAdapter.cs
  • src/Refitter.Core/PriorityAdapter.cs
  • src/Refitter.Core/RetryHandlerAdapter.cs
  • src/Refitter.Tests/Apizr/ApizrOptionsAdapterPipelineTests.cs
  • src/Refitter.Tests/Apizr/CacheProviderAdapterTests.cs
  • src/Refitter.Tests/Apizr/FileTransferAdapterTests.cs
  • src/Refitter.Tests/Apizr/HttpMessageHandlerAdapterTests.cs
  • src/Refitter.Tests/Apizr/MappingProviderAdapterTests.cs
  • src/Refitter.Tests/Apizr/MediationAdapterTests.cs
  • src/Refitter.Tests/Apizr/PriorityAdapterTests.cs
  • src/Refitter.Tests/Apizr/RetryHandlerAdapterTests.cs

Comment thread src/Refitter.Core/ApizrOptionsBuilder.cs
Comment thread src/Refitter.Core/MappingProviderAdapter.cs
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 2 file(s) based on 2 unresolved review comments.

Files modified:

  • src/Refitter.Core/ApizrOptionsBuilder.cs
  • src/Refitter.Core/MappingProviderAdapter.cs

Commit: e1c3b471b27eb4b867e9b34c273f6e2bddb77ea1

The changes have been pushed to the deepen-apizr-registration-generator branch.

Time taken: 2m 4s

@christianhelle christianhelle changed the title Deepen ApizrRegistrationGenerator into adapter pipeline Refactor ApizrRegistrationGenerator into adapter pipeline Jun 14, 2026
Fixed 2 file(s) based on 2 unresolved review comments.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
Copilot AI changed the title Refactor ApizrRegistrationGenerator into adapter pipeline Deepen Apizr registration generator with adapter isolation and pipeline tests Jun 14, 2026
@sonarqubecloud

Copy link
Copy Markdown

@christianhelle christianhelle merged commit 5bb177f into main Jun 15, 2026
15 checks passed
@christianhelle christianhelle deleted the deepen-apizr-registration-generator branch June 15, 2026 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature, bug fix, or request .NET Pull requests that contain changes to .NET code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants