Skip to content

Conversation

@vbreuss
Copy link
Contributor

@vbreuss vbreuss commented Jan 17, 2026

This PR adds validation to ensure that the times parameter in the For method is positive, throwing an ArgumentOutOfRangeException when it's not. This prevents undefined behavior when users accidentally pass zero or negative values.

Key Changes:

  • Added input validation to the For method in Callback.cs to throw ArgumentOutOfRangeException when times <= 0
  • Added test coverage for the validation with parameterized tests checking both negative and zero values
  • Tests verify the exception message matches the expected "Times must be greater than zero." prefix

@vbreuss vbreuss self-assigned this Jan 17, 2026
Copilot AI review requested due to automatic review settings January 17, 2026 05:24
@vbreuss vbreuss added the bug Something isn't working label Jan 17, 2026
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 adds validation to ensure that the times parameter in the For method is positive, throwing an ArgumentOutOfRangeException when it's not. This prevents undefined behavior when users accidentally pass zero or negative values.

Changes:

  • Added input validation to the For method in Callback.cs to throw ArgumentOutOfRangeException when times <= 0
  • Added test coverage for the validation with parameterized tests checking both negative and zero values
  • Tests verify the exception message matches the expected "Times must be greater than zero." prefix

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
Source/Mockolate/Setup/Callback.cs Added validation logic to throw ArgumentOutOfRangeException when times parameter is not positive
Tests/Mockolate.Tests/MockMethods/SetupMethodTests.CallbackTests.cs Added parameterized tests for For and Only methods to verify exception is thrown for invalid times values
Tests/Mockolate.Tests/MockProperties/SetupPropertyTests.OnGetTests.cs Added parameterized test for property setup For method to verify exception is thrown for invalid times values

@github-actions
Copy link

github-actions bot commented Jan 17, 2026

Test Results

    14 files  ± 0      14 suites  ±0   5m 10s ⏱️ -5s
 2 171 tests + 6   2 170 ✅ + 6  1 💤 ±0  0 ❌ ±0 
14 532 runs  +42  14 531 ✅ +42  1 💤 ±0  0 ❌ ±0 

Results for commit 8446014. ± Comparison against base commit ecb3045.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Jan 17, 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.521 μs 0.0321 μs 0.0300 μs 0.1507 - 3.72 KB
Simple_Moq 135.896 μs 0.6852 μs 0.6074 μs 0.4883 0.2441 14.72 KB
Simple_NSubstitute 5.595 μs 0.0810 μs 0.0757 μs 0.3662 - 9.14 KB
Simple_FakeItEasy 5.829 μs 0.0497 μs 0.0465 μs 0.3281 - 8.12 KB

@vbreuss vbreuss enabled auto-merge (squash) January 17, 2026 06:32
@vbreuss vbreuss force-pushed the topic/validate-throw-times branch from f9924b8 to 8446014 Compare January 17, 2026 16:00
Copilot AI review requested due to automatic review settings January 17, 2026 16:00
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment on lines +331 to +332
sut.SetupMock.Method.Method1(It.IsAny<int>())
.Returns("").For(times);
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

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

The test validates the For method but uses Returns("") which tests a different code path than the callback-focused Do() method. Consider adding a test that uses .Do(() => { }).For(times) to match the property setup test pattern and ensure validation works consistently across both setup approaches.

Copilot uses AI. Check for mistakes.
Comment on lines +406 to +407
sut.SetupMock.Method.Method1(It.IsAny<int>())
.Returns("").Only(times);
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

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

The test validates the Only method but uses Returns("") which tests a different code path than the callback-focused Do() method. Consider adding a test that uses .Do(() => { }).Only(times) to match the property setup test pattern and ensure validation works consistently across both setup approaches.

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link

@vbreuss vbreuss merged commit 697c749 into main Jan 17, 2026
12 checks passed
@vbreuss vbreuss deleted the topic/validate-throw-times branch January 17, 2026 16:07
@github-actions
Copy link

This is addressed in release v0.52.0.

@github-actions github-actions bot added the state: released The issue is released label Jan 17, 2026
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