-
-
Notifications
You must be signed in to change notification settings - Fork 0
fix: throw ArgumentOutOfRangeException when times of For is not positive
#369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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
Formethod inCallback.csto throwArgumentOutOfRangeExceptionwhentimes <= 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 |
Tests/Mockolate.Tests/MockMethods/SetupMethodTests.CallbackTests.cs
Outdated
Show resolved
Hide resolved
🚀 Benchmark ResultsDetails
|
f9924b8 to
8446014
Compare
There was a problem hiding this 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.
| sut.SetupMock.Method.Method1(It.IsAny<int>()) | ||
| .Returns("").For(times); |
Copilot
AI
Jan 17, 2026
There was a problem hiding this comment.
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.
| sut.SetupMock.Method.Method1(It.IsAny<int>()) | ||
| .Returns("").Only(times); |
Copilot
AI
Jan 17, 2026
There was a problem hiding this comment.
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.
|
|
This is addressed in release v0.52.0. |



This PR adds validation to ensure that the
timesparameter in theFormethod is positive, throwing anArgumentOutOfRangeExceptionwhen it's not. This prevents undefined behavior when users accidentally pass zero or negative values.Key Changes:
Formethod inCallback.csto throwArgumentOutOfRangeExceptionwhentimes <= 0