Skip to content

fix: For does not repeat correctly#450

Merged
vbreuss merged 2 commits into
mainfrom
topic/fix-for-to-repeat-and-not-limit
Feb 1, 2026
Merged

fix: For does not repeat correctly#450
vbreuss merged 2 commits into
mainfrom
topic/fix-for-to-repeat-and-not-limit

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented Feb 1, 2026

This PR fixes the behavior of the For modifier in the Mockolate library to properly repeat callback patterns instead of limiting usage. Previously, For would limit callbacks to execute only once for the specified number of times. Now, For repeats the entire callback pattern indefinitely.

Key Changes:

  • Modified For behavior to repeat patterns instead of limiting them to one-time execution
  • Renamed For tests to Returns_For_ShouldRepeatUsage_ForTheSpecifiedNumber to reflect new behavior
  • Moved old For tests to Only (which maintains the original limiting behavior)
  • Updated documentation to show the new repeating pattern behavior

@vbreuss vbreuss self-assigned this Feb 1, 2026
@vbreuss vbreuss added the bug Something isn't working label Feb 1, 2026
Copilot AI review requested due to automatic review settings February 1, 2026 07:40
Copy link
Copy Markdown

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 the behavior of the For modifier in the Mockolate library to properly repeat callback patterns instead of limiting usage. Previously, For would limit callbacks to execute only once for the specified number of times. Now, For repeats the entire callback pattern indefinitely.

Changes:

  • Modified For behavior to repeat patterns instead of limiting them to one-time execution
  • Renamed For tests to Returns_For_ShouldRepeatUsage_ForTheSpecifiedNumber to reflect new behavior
  • Moved old For tests to Only (which maintains the original limiting behavior)
  • Updated documentation to show the new repeating pattern behavior

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Source/Mockolate/Setup/Callback.cs Core implementation changes to enable pattern repetition via iteration counter
Tests/Mockolate.Tests/MockProperties/SetupPropertyTests.ReturnsThrowsTests.cs Updated property tests to reflect new For behavior and added Only tests
Tests/Mockolate.Tests/MockProperties/SetupPropertyTests.OnSetTests.cs Renamed For tests to Only tests for property setters
Tests/Mockolate.Tests/MockProperties/SetupPropertyTests.OnGetTests.cs Renamed For tests to Only tests for property getters
Tests/Mockolate.Tests/MockMethods/SetupMethodTests.ReturnsThrowsTests.cs Updated method tests to reflect new For behavior and added Only tests
Tests/Mockolate.Tests/MockMethods/SetupMethodTests.CallbackTests.cs Renamed For tests to Only tests for method callbacks
Tests/Mockolate.Tests/MockIndexers/SetupIndexerTests.ReturnsThrowsTests.cs Updated indexer tests to reflect new For behavior and added Only tests
Tests/Mockolate.Tests/MockIndexers/SetupIndexerTests.OnSetTests.cs Renamed For tests to Only tests for indexer setters
Tests/Mockolate.Tests/MockIndexers/SetupIndexerTests.OnGetTests.cs Renamed For tests to Only tests for indexer getters
Docs/pages/advanced-features/02-advanced-callback-features.md Updated documentation to show new repeating pattern behavior

@vbreuss vbreuss enabled auto-merge (squash) February 1, 2026 07:42
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 1, 2026

Test Results

    21 files  ± 0      21 suites  ±0   5m 12s ⏱️ - 1m 12s
 2 508 tests  - 10   2 507 ✅  - 10  1 💤 ±0  0 ❌ ±0 
16 835 runs  +28  16 834 ✅ +28  1 💤 ±0  0 ❌ ±0 

Results for commit db75dee. ± Comparison against base commit 466708f.

This pull request removes 102 and adds 92 tests. Note that renamed tests count towards both.
Mockolate.Internal.Tests.CallbackTests+InvokeForCallbacksTests ‑ ShouldIncrementIndexOnceWhenCallbackIsExhausted(forValue: 2, whenMinimum: 0, expectResult: [0, 0, 1, 1, 1, ···])
Mockolate.Internal.Tests.CallbackTests+InvokeForCallbacksTests ‑ ShouldIncrementIndexOnceWhenCallbackIsExhausted(forValue: 2, whenMinimum: 0, expectResult: [0, 0, 1, 1, 1, ┬╖┬╖┬╖])
Mockolate.Internal.Tests.CallbackTests+InvokeForCallbacksTests ‑ ShouldIncrementIndexOnceWhenCallbackIsExhausted(forValue: 2, whenMinimum: 1, expectResult: [0, 0, 0, 1, 1, ···])
Mockolate.Internal.Tests.CallbackTests+InvokeForCallbacksTests ‑ ShouldIncrementIndexOnceWhenCallbackIsExhausted(forValue: 2, whenMinimum: 1, expectResult: [0, 0, 0, 1, 1, ┬╖┬╖┬╖])
Mockolate.Internal.Tests.CallbackTests+InvokeForReturnThrowsTests ‑ ShouldIncrementIndexWhenForIsNotActive(forValue: 2, whenMinimum: 0, expectResult: [1, 1, 2, 3, 4, ···])
Mockolate.Internal.Tests.CallbackTests+InvokeForReturnThrowsTests ‑ ShouldIncrementIndexWhenForIsNotActive(forValue: 2, whenMinimum: 0, expectResult: [1, 1, 2, 3, 4, ┬╖┬╖┬╖])
Mockolate.Internal.Tests.CallbackTests+InvokeForReturnThrowsTests ‑ ShouldIncrementIndexWhenForIsNotActive(forValue: 2, whenMinimum: 1, expectResult: [1, 2, 2, 3, 4, ···])
Mockolate.Internal.Tests.CallbackTests+InvokeForReturnThrowsTests ‑ ShouldIncrementIndexWhenForIsNotActive(forValue: 2, whenMinimum: 1, expectResult: [1, 2, 2, 3, 4, ┬╖┬╖┬╖])
Mockolate.Internal.Tests.CallbackTests+InvokeForReturnThrowsTests ‑ ShouldIncrementIndexWhenForIsNotActive(forValue: 3, whenMinimum: 1, expectResult: [1, 2, 2, 2, 3, ···])
Mockolate.Internal.Tests.CallbackTests+InvokeForReturnThrowsTests ‑ ShouldIncrementIndexWhenForIsNotActive(forValue: 3, whenMinimum: 1, expectResult: [1, 2, 2, 2, 3, ┬╖┬╖┬╖])
…
Mockolate.Internal.Tests.CallbackTests+InvokeForCallbacksTests ‑ ShouldIncrementIndexOnceWhenCallbackIsExhausted(only: 2, when: 0, expectResult: [0, 1, 2, 2, 2, ···])
Mockolate.Internal.Tests.CallbackTests+InvokeForCallbacksTests ‑ ShouldIncrementIndexOnceWhenCallbackIsExhausted(only: 2, when: 0, expectResult: [0, 1, 2, 2, 2, ┬╖┬╖┬╖])
Mockolate.Internal.Tests.CallbackTests+InvokeForCallbacksTests ‑ ShouldIncrementIndexOnceWhenCallbackIsExhausted(only: 2, when: 1, expectResult: [0, 0, 1, 2, 2, ···])
Mockolate.Internal.Tests.CallbackTests+InvokeForCallbacksTests ‑ ShouldIncrementIndexOnceWhenCallbackIsExhausted(only: 2, when: 1, expectResult: [0, 0, 1, 2, 2, ┬╖┬╖┬╖])
Mockolate.Tests.MockIndexers.SetupIndexerTests+OnGetTests ‑ Only_ShouldStopExecutingCallbackAfterTheGivenTimes
Mockolate.Tests.MockIndexers.SetupIndexerTests+OnGetTests ‑ Only_WithWhen_ShouldStopExecutingCallbackAfterTheGivenTimes
Mockolate.Tests.MockIndexers.SetupIndexerTests+OnGetTests+With2Levels ‑ Only_ShouldStopExecutingCallbackAfterTheGivenTimes
Mockolate.Tests.MockIndexers.SetupIndexerTests+OnGetTests+With2Levels ‑ Only_WithWhen_ShouldStopExecutingCallbackAfterTheGivenTimes
Mockolate.Tests.MockIndexers.SetupIndexerTests+OnGetTests+With3Levels ‑ Only_ShouldStopExecutingCallbackAfterTheGivenTimes
Mockolate.Tests.MockIndexers.SetupIndexerTests+OnGetTests+With3Levels ‑ Only_WithWhen_ShouldStopExecutingCallbackAfterTheGivenTimes
…

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 1, 2026

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.61GHz, 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-v3

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

Method Mean Error StdDev Gen0 Gen1 Allocated
Simple_Mockolate 1.540 μs 0.0214 μs 0.0190 μs 0.2270 - 3.73 KB
Simple_Moq 176.690 μs 0.4548 μs 0.3551 μs 0.4883 - 14.55 KB
Simple_NSubstitute 5.590 μs 0.0340 μs 0.0266 μs 0.5493 0.0076 9.09 KB
Simple_FakeItEasy 6.631 μs 0.0621 μs 0.0581 μs 0.5035 - 8.33 KB

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Feb 1, 2026

@vbreuss vbreuss merged commit 2097b4d into main Feb 1, 2026
12 checks passed
@vbreuss vbreuss deleted the topic/fix-for-to-repeat-and-not-limit branch February 1, 2026 08:04
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 1, 2026

This is addressed in release v1.2.0.

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.

2 participants