fix: throw ArgumentException when expected is empty in IsOneOf (2)#671
fix: throw ArgumentException when expected is empty in IsOneOf (2)#671
ArgumentException when expected is empty in IsOneOf (2)#671Conversation
Also throw the `ArgumentException` for empty expected values for enum, object and string and fix the sonar issues introduced in #669.
There was a problem hiding this comment.
Pull Request Overview
This PR introduces consistent argument validation for empty expected collections in various IsOneOf and IsNotOneOf constraints, adds corresponding tests, and addresses Sonar issues by centralizing the exception throw.
- Added tests that verify
ArgumentExceptionis thrown when the expected collection is empty for bothIsOneOfandIsNotOneOfacross strings, objects, enums, etc. - Refactored
IsOneOfimplementations to manually iterate, detect empty inputs, and use a newThrowHelper.EmptyCollection()helper. - Removed LINQ usage in these methods and cleaned up trailing commas in collection-expression literals.
Reviewed Changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| Tests/aweXpect.Tests/Strings/ThatString.IsOneOf.Tests.cs | Added tests for empty and nullable-empty expected. |
| Tests/aweXpect.Tests/Strings/ThatString.IsNotOneOf.Tests.cs | Added tests for empty and nullable-empty unexpected. |
| Tests/aweXpect.Tests/Objects/ThatObject.IsOneOf.Tests.cs | Added tests for empty and nullable-empty expected. |
| Tests/aweXpect.Tests/Objects/ThatObject.IsNotOneOf.Tests.cs | Added tests for empty and nullable-empty unexpected. |
| Tests/aweXpect.Tests/Enums/ThatEnum.Nullable.IsOneOf.Tests.cs | Added empty-expected tests for nullable enums. |
| Tests/aweXpect.Tests/Enums/ThatEnum.Nullable.IsNotOneOf.Tests.cs | Added empty-expected tests for nullable enums. |
| Tests/aweXpect.Tests/Enums/ThatEnum.IsOneOf.Tests.cs | Added empty-expected tests for enums. |
| Tests/aweXpect.Tests/Enums/ThatEnum.IsNotOneOf.Tests.cs | Added empty-expected tests for enums. |
| Source/aweXpect/That/TimeSpans/ThatTimeSpan.IsOneOf.cs | Replaced inline throw with ThrowHelper.EmptyCollection(). |
| Source/aweXpect/That/TimeSpans/ThatNullableTimeSpan.IsOneOf.cs | Replaced inline throw with ThrowHelper.EmptyCollection(). |
| Source/aweXpect/That/TimeOnlys/ThatTimeOnly.IsOneOf.cs | Replaced inline throw with ThrowHelper.EmptyCollection(). |
| Source/aweXpect/That/TimeOnlys/ThatNullableTimeOnly.IsOneOf.cs | Replaced inline throw with ThrowHelper.EmptyCollection(). |
| Source/aweXpect/That/Strings/ThatString.IsOneOf.cs | Removed LINQ, added manual loop and empty-check throw. |
| Source/aweXpect/That/Objects/ThatObject.IsOneOf.cs | Removed LINQ, added manual loop and empty-check throw. |
| Source/aweXpect/That/Numbers/ThatNumber.IsOneOf.cs | Removed LINQ, added manual loop and empty-check throw. |
| Source/aweXpect/That/Enums/ThatNullableEnum.IsOneOf.cs | Removed LINQ, added manual loop and empty-check throw. |
| Source/aweXpect/That/Enums/ThatEnum.IsOneOf.cs | Removed LINQ, added manual loop and empty-check throw. |
| Source/aweXpect/That/DateTimes/ThatNullableDateTime.IsOneOf.cs | Replaced inline throw with ThrowHelper.EmptyCollection(). |
| Source/aweXpect/That/DateTimes/ThatDateTime.IsOneOf.cs | Replaced inline throw with ThrowHelper.EmptyCollection(). |
| Source/aweXpect/That/DateTimeOffsets/ThatNullableDateTimeOffset.IsOneOf.cs | Replaced inline throw with ThrowHelper.EmptyCollection(). |
| Source/aweXpect/That/DateTimeOffsets/ThatDateTimeOffset.IsOneOf.cs | Replaced inline throw with ThrowHelper.EmptyCollection(). |
| Source/aweXpect/That/DateOnlys/ThatNullableDateOnly.IsOneOf.cs | Replaced inline throw with ThrowHelper.EmptyCollection(). |
| Source/aweXpect/That/DateOnlys/ThatDateOnly.IsOneOf.cs | Replaced inline throw with ThrowHelper.EmptyCollection(). |
| Source/aweXpect/That/Chars/ThatNullableChar.IsOneOf.cs | Replaced inline throw with ThrowHelper.EmptyCollection(). |
| Source/aweXpect/That/Chars/ThatChar.IsOneOf.cs | Replaced inline throw with ThrowHelper.EmptyCollection(). |
| Source/aweXpect/Helpers/ThrowHelper.cs | Introduced helper for consistent empty-collection exception. |
Comments suppressed due to low confidence (1)
Source/aweXpect/That/Numbers/ThatNumber.IsOneOf.cs:219
- Iterating over
expectedas non-nullableTNumbercan throw whenexpectedcontains null; revert toTNumber?in the iteration variable to match the enumerable's nullability.
foreach (TNumber value in expected)
Test Results 14 files - 24 14 suites - 24 2m 33s ⏱️ ±0s Results for commit 65e3eea. ± Comparison against base commit 07da697. This pull request removes 1446 and adds 1440 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
|
🚀 Benchmark ResultsDetails
|
👽 Mutation ResultsaweXpectDetails
The final mutation score is 99.19%Coverage Thresholds: high:80 low:60 break:0aweXpect.CoreDetails
The final mutation score is NaN%Coverage Thresholds: high:80 low:60 break:0 |
…ected is empty in `IsOneOf` (2) (#671) by Valentin Breuß
…ected is empty in `IsOneOf` (2) (#671) by Valentin Breuß
|
This is addressed in release v2.18.1. |



This PR introduces consistent argument validation for empty expected collections in various IsOneOf and IsNotOneOf constraints, adds corresponding tests, and addresses Sonar issues introduced in #669 by centralizing the exception throw.