fix: persist indexer values when return setup is conditional#409
fix: persist indexer values when return setup is conditional#409
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the indexer setup mechanism to ensure that indexer values persist correctly when return setups are conditional (using modifiers like OnlyOnce(), For(), or When()). Previously, when conditional setups expired or didn't match, the mock would incorrectly return default values instead of preserving the last value that was set.
Changes:
- Refactored indexer value retrieval logic to always consult the backing storage before applying conditional return setups
- Removed the now-obsolete
HasReturnCalls()method from the indexer setup infrastructure - Added comprehensive test coverage to verify that indexer values persist correctly across various scenarios with conditional setups
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/Mockolate.Tests/SetupExtensionsTests.cs | Added new test cases to verify indexer value persistence with OnlyOnce() and For() modifiers |
| Tests/Mockolate.Tests/MockProperties/SetupPropertyTests.ReturnsThrowsTests.cs | Added tests for property value persistence with conditional setups and updated predicate range |
| Tests/Mockolate.Tests/MockIndexers/SetupIndexerTests.ReturnsThrowsTests.cs | Added comprehensive test suite with nested classes and new test helper class to verify indexer behavior with base values |
| Tests/Mockolate.Tests/MockIndexers/SetupIndexerTests.cs | Removed obsolete HasReturnCalls() override from test mock implementation |
| Tests/Mockolate.ExampleTests/ExampleTests.cs | Added example test demonstrating mock usage (appears to be development/debugging code) |
| Tests/Mockolate.Api.Tests/Expected/Mockolate_*.txt | Updated API surface expectations to reflect removal of HasReturnCalls() method |
| Source/Mockolate/Setup/Interfaces.IndexerSetup.cs | Removed HasReturnCalls() method from interface |
| Source/Mockolate/Setup/IndexerSetupResult.cs | Refactored to retrieve indexer value before applying getter callback |
| Source/Mockolate/Setup/IndexerSetup.cs | Removed HasReturnCalls() method and all its implementations |
| Source/Mockolate.SourceGenerators/Sources/Sources.IndexerSetups.cs | Updated source generator to stop emitting HasReturnCalls() method |
bc015a8 to
4d09cc5
Compare
🚀 Benchmark ResultsDetails
|
|
Test Results 21 files ± 0 21 suites ±0 5m 29s ⏱️ -44s Results for commit 4d09cc5. ± Comparison against base commit ab6f6ed. This pull request removes 24 and adds 42 tests. Note that renamed tests count towards both. |
|
This is addressed in release v1.0.4. |



This PR fixes a bug in the indexer setup mechanism to ensure that indexer values persist correctly when return setups are conditional (using modifiers like
OnlyOnce(),For(), orWhen()). Previously, when conditional setups expired or didn't match, the mock would incorrectly return default values instead of preserving the last value that was set.Key changes:
HasReturnCalls()method from the indexer setup infrastructure