Deepen Apizr registration generator with adapter isolation and pipeline tests#1145
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughIntroduces an adapter-based pipeline for Apizr options code generation. Two internal interfaces ( ChangesApizr Adapter-Based Options Pipeline
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
📒 Files selected for processing (19)
src/Refitter.Core/ApizrOptionsBuilder.cssrc/Refitter.Core/ApizrRegistrationGenerator.cssrc/Refitter.Core/CacheProviderAdapter.cssrc/Refitter.Core/FileTransferAdapter.cssrc/Refitter.Core/HttpMessageHandlerAdapter.cssrc/Refitter.Core/IApizrOptionsAdapter.cssrc/Refitter.Core/IApizrOptionsBuilder.cssrc/Refitter.Core/MappingProviderAdapter.cssrc/Refitter.Core/MediationAdapter.cssrc/Refitter.Core/PriorityAdapter.cssrc/Refitter.Core/RetryHandlerAdapter.cssrc/Refitter.Tests/Apizr/ApizrOptionsAdapterPipelineTests.cssrc/Refitter.Tests/Apizr/CacheProviderAdapterTests.cssrc/Refitter.Tests/Apizr/FileTransferAdapterTests.cssrc/Refitter.Tests/Apizr/HttpMessageHandlerAdapterTests.cssrc/Refitter.Tests/Apizr/MappingProviderAdapterTests.cssrc/Refitter.Tests/Apizr/MediationAdapterTests.cssrc/Refitter.Tests/Apizr/PriorityAdapterTests.cssrc/Refitter.Tests/Apizr/RetryHandlerAdapterTests.cs
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. Fixes Applied SuccessfullyFixed 2 file(s) based on 2 unresolved review comments. Files modified:
Commit: The changes have been pushed to the Time taken: |
Fixed 2 file(s) based on 2 unresolved review comments. Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
|



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 inMappingProviderAdapter.cs. The directive is now correctly scoped to the DI-only path, so generated code without DI no longer includes the unnecessaryusing MapsterMapper;statement.Summary by CodeRabbit
Summary by CodeRabbit
Refactor
Tests