fix: verify that the duration is not negative#668
Conversation
Throw an `ArgumentOutOfRangeException` when using `.Within` with a negative range
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that calling .Within with a negative TimeSpan immediately throws an ArgumentOutOfRangeException, and updates all existing tests to cover that scenario and adjust expected timestamps.
- Added a guard in the generic
ThatDelegateThrows<TException>.Withinto reject negative durations. - Introduced negative-duration tests in all three
.Withintest classes (ThrowsException,ThrowsExactly,Throws). - Updated existing tests to use
0.Seconds()and expect"0:00"in failure messages.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Tests/aweXpect.Tests/Delegates/ThatDelegate.ThrowsException.Within.Tests.cs | Added negative-duration test and corrected expected timestamp strings. |
| Tests/aweXpect.Tests/Delegates/ThatDelegate.ThrowsExactly.Within.Tests.cs | Added negative-duration test and corrected expected timestamp strings. |
| Tests/aweXpect.Tests/Delegates/ThatDelegate.Throws.Within.Tests.cs | Added negative-duration test and corrected expected timestamp strings. |
| Source/aweXpect.Core/Delegates/ThatDelegateThrows.Within.cs | Added validation to throw on negative duration in generic .Within. |
Comments suppressed due to low confidence (1)
Source/aweXpect.Core/Delegates/ThatDelegateThrows.Within.cs:13
- Negative-duration validation is implemented only in the generic overload. The non-generic
.Withinoverload used by.Throws(Type)isn’t guarded and will not throw as expected. Add the same ArgumentOutOfRangeException check there.
if (duration < TimeSpan.Zero)
|
Test Results 4 files ±0 4 suites ±0 21s ⏱️ -1s Results for commit 5c9b301. ± Comparison against base commit d037b01. This pull request removes 54 and adds 54 tests. Note that renamed tests count towards both. |
|
This is addressed in release v2.18.1. |



Throw an
ArgumentOutOfRangeExceptionwhen using.Withinfrom #667 with a negative range.