Skip to content

fix: verify that the duration is not negative#668

Merged
vbreuss merged 1 commit intomainfrom
topic/verify-range-of-duration
Jun 29, 2025
Merged

fix: verify that the duration is not negative#668
vbreuss merged 1 commit intomainfrom
topic/verify-range-of-duration

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented Jun 29, 2025

Throw an ArgumentOutOfRangeException when using .Within from #667 with a negative range.

Throw an `ArgumentOutOfRangeException` when using `.Within` with a negative range
@vbreuss vbreuss self-assigned this Jun 29, 2025
Copilot AI review requested due to automatic review settings June 29, 2025 12:43
@vbreuss vbreuss added the bug Something isn't working label Jun 29, 2025
@vbreuss vbreuss enabled auto-merge (squash) June 29, 2025 12:43
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 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>.Within to reject negative durations.
  • Introduced negative-duration tests in all three .Within test 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 .Within overload used by .Throws(Type) isn’t guarded and will not throw as expected. Add the same ArgumentOutOfRangeException check there.
		if (duration < TimeSpan.Zero)

@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown
Contributor

Test Results

    4 files  ±0      4 suites  ±0   21s ⏱️ -1s
  897 tests ±0    896 ✅ ±0  1 💤 ±0  0 ❌ ±0 
2 577 runs  ±0  2 576 ✅ ±0  1 💤 ±0  0 ❌ ±0 

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.
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message5689f412-33f6-406e-8dcf-2ee76b372183")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message57dad460-6d99-4ef2-b92b-bac15944ce46")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "messagea9de4b9f-6e77-4510-ae95-3aefa2e5e9e1")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "message17d8d8e1-190a-4b29-b859-2e3359bdf9ee")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "message86040395-491d-4a24-aadb-3746e2f04c17")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "messagefecca41b-eaab-4d3e-aa65-38ec636a3841")
aweXpect.Core.Tests.Equivalency.EquivalencyOptionsExtensionsTests ‑ Generic_For_IgnoringMember_ShouldSetOptionForType(memberToIgnore: "memberToIgnore29b6a4b5-f7d9-435b-b93f-d646a4f15540")
aweXpect.Core.Tests.Equivalency.EquivalencyOptionsExtensionsTests ‑ Generic_For_IgnoringMember_ShouldSetOptionForType(memberToIgnore: "memberToIgnore713efcdf-81bf-4c7a-855e-18697c290068")
aweXpect.Core.Tests.Equivalency.EquivalencyOptionsExtensionsTests ‑ Generic_For_IgnoringMember_ShouldSetOptionForType(memberToIgnore: "memberToIgnore8a030e9b-37ee-4a8b-9215-e697ffa0df13")
aweXpect.Core.Tests.FailTests ‑ Test_ShouldThrowException(reason: "reason75dc3587-5ee1-4a08-b5fa-16984f0c4470")
…
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message4927d1e6-7c0a-4685-bee7-ed6b8d6b122b")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message518cca3a-86d9-48f6-8ce9-79b8d8f91bec")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message5a03da32-b879-48a9-a203-11dfbfd5dc9f")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "message021d13e2-330f-4ba3-9338-59a7e084a45a")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "messageaa799524-73c5-4866-8957-54f75035c215")
aweXpect.Core.Tests.Core.Exceptions.SkipExceptionTests ‑ Message_ShouldBeSet(message: "messagee8663574-ecc1-465b-a8aa-a34a861602cb")
aweXpect.Core.Tests.Equivalency.EquivalencyOptionsExtensionsTests ‑ Generic_For_IgnoringMember_ShouldSetOptionForType(memberToIgnore: "memberToIgnore377b42b3-2f80-4c82-adb9-f1c984fec3a3")
aweXpect.Core.Tests.Equivalency.EquivalencyOptionsExtensionsTests ‑ Generic_For_IgnoringMember_ShouldSetOptionForType(memberToIgnore: "memberToIgnore6921752d-6aed-4f83-afe7-71af40274505")
aweXpect.Core.Tests.Equivalency.EquivalencyOptionsExtensionsTests ‑ Generic_For_IgnoringMember_ShouldSetOptionForType(memberToIgnore: "memberToIgnoree570938d-deda-4a4d-a386-1ce14a114eb3")
aweXpect.Core.Tests.FailTests ‑ Test_ShouldThrowException(reason: "reason481cea51-ca10-49de-a435-770f1efb3682")
…

@vbreuss vbreuss merged commit 2fd4e6e into main Jun 29, 2025
13 checks passed
@vbreuss vbreuss deleted the topic/verify-range-of-duration branch June 29, 2025 12:48
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 9, 2025

This is addressed in release v2.18.1.

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