Skip to content

Comments

fix: persist indexer values when return setup is conditional#409

Merged
vbreuss merged 1 commit intomainfrom
topic/fix-indexer-value-persistence
Jan 30, 2026
Merged

fix: persist indexer values when return setup is conditional#409
vbreuss merged 1 commit intomainfrom
topic/fix-indexer-value-persistence

Conversation

@vbreuss
Copy link
Contributor

@vbreuss vbreuss commented Jan 30, 2026

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.

Key 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

@vbreuss vbreuss self-assigned this Jan 30, 2026
@vbreuss vbreuss added the bug Something isn't working label Jan 30, 2026
Copilot AI review requested due to automatic review settings January 30, 2026 16:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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

@vbreuss vbreuss force-pushed the topic/fix-indexer-value-persistence branch from bc015a8 to 4d09cc5 Compare January 30, 2026 16:04
@vbreuss vbreuss enabled auto-merge (squash) January 30, 2026 16:05
@github-actions
Copy link

github-actions bot commented Jan 30, 2026

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
Intel Xeon Platinum 8370C CPU 2.80GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.102
[Host] : .NET 10.0.2 (10.0.2, 10.0.225.61305), X64 RyuJIT x86-64-v4

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method Mean Error StdDev Gen0 Gen1 Allocated
Simple_Mockolate 1.612 μs 0.0212 μs 0.0198 μs 0.1507 - 3.73 KB
Simple_Moq 133.345 μs 0.6558 μs 0.6135 μs 0.4883 0.2441 14.56 KB
Simple_NSubstitute 5.656 μs 0.0374 μs 0.0350 μs 0.3662 - 9.14 KB
Simple_FakeItEasy 6.048 μs 0.0412 μs 0.0385 μs 0.3281 - 8.12 KB

@sonarqubecloud
Copy link

@github-actions
Copy link

Test Results

    21 files  ±  0      21 suites  ±0   5m 29s ⏱️ -44s
 2 517 tests + 18   2 516 ✅ + 18  1 💤 ±0  0 ❌ ±0 
16 800 runs  +126  16 799 ✅ +126  1 💤 ±0  0 ❌ ±0 

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.
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests ‑ IndexerReturns_WithSpecificParameter_ShouldIterateThroughValues
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests ‑ MixReturnsAndThrows_ShouldIterateThroughBoth
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests ‑ MultipleReturns_ShouldIterateThroughAllRegisteredValues
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests ‑ Returns_CallbackWithParametersAndValue_ShouldReturnExpectedValue
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests ‑ Returns_CallbackWithParameters_ShouldReturnExpectedValue
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests ‑ Returns_Callback_ShouldReturnExpectedValue
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests ‑ Returns_For_ShouldLimitUsage_ToSpecifiedNumber
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests ‑ Returns_Forever_ShouldUseTheLastValueForever
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests ‑ Returns_ShouldReturnExpectedValue
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests ‑ Returns_WhenFor_ShouldLimitUsage_ToSpecifiedNumber
…
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests+With1Level ‑ IndexerReturns_WithSpecificParameter_ShouldIterateThroughValues
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests+With1Level ‑ MixReturnsAndThrows_ShouldIterateThroughBoth
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests+With1Level ‑ MultipleReturns_ShouldIterateThroughAllRegisteredValues
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests+With1Level ‑ Returns_CallbackWithParametersAndValue_ShouldReturnExpectedValue
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests+With1Level ‑ Returns_CallbackWithParameters_ShouldReturnExpectedValue
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests+With1Level ‑ Returns_Callback_ShouldReturnExpectedValue
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests+With1Level ‑ Returns_For_ShouldLimitUsage_ToSpecifiedNumber
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests+With1Level ‑ Returns_Forever_ShouldUseTheLastValueForever
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests+With1Level ‑ Returns_ShouldReturnExpectedValue
Mockolate.Tests.MockIndexers.SetupIndexerTests+ReturnsThrowsTests+With1Level ‑ Returns_WhenFor_ShouldLimitUsage_ToSpecifiedNumber
…

@vbreuss vbreuss merged commit 17879ef into main Jan 30, 2026
12 checks passed
@vbreuss vbreuss deleted the topic/fix-indexer-value-persistence branch January 30, 2026 16:09
@github-actions
Copy link

This is addressed in release v1.0.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant