Repository navigation
fix!: reject a null or empty needle in the dictionary key and value expectations - #1075
Merged
Merged
Conversation
… expectations `ContainsKeys`, `ContainsValues`, `DoesNotContainKeys` and `DoesNotContainValues` take `params`, so calling one with no arguments was the default call and asserted nothing at all: the empty needle made every key trivially present and every unwanted key trivially absent, so the expectation passed whatever the dictionary held. #1069 already rejected exactly that for `Contains`, `StartsWith` and `EndsWith`, and leaving the dictionary family out would ship a major in which one half of the surface validates its argument and the other half silently accepts a no-op. A `null` needle was worse than unvalidated: it surfaced as `InvalidOperationException` wrapping a `NullReferenceException` from inside the constraint, rather than as an `ArgumentNullException` naming the parameter. The single `ThrowIfNullOrEmpty` guard fixes both, and covers all sixteen overloads - each expectation exists twice per dictionary type, for the interface and the concrete class, across `ThatDictionary` and `ThatReadOnlyDictionary`. The `null` subject was never affected: these constraints derive from `WithNotNullValue`, which already forces a failure when the subject is `null`, so their `GuaranteesNotNull` markings were and remain correct.
|
Contributor
Test Results 23 files - 27 23 suites - 27 10m 58s ⏱️ +20s Results for commit f5c348a. ± Comparison against base commit f2e2904. This pull request removes 3236 and adds 3219 tests. Note that renamed tests count towards both. |
Contributor
🚀 Benchmark ResultsDetails
|
Contributor
👽 Mutation ResultsaweXpectDetails
The final mutation score is 99.16%Coverage Thresholds: high:80 low:60 break:0aweXpect.CoreDetails
The final mutation score is NaN%Coverage Thresholds: high:80 low:60 break:0 |
github-actions Bot
added a commit
that referenced
this pull request
Sep 13, 2026
…n the dictionary key and value expectations (#1075) by Valentin Breuß
github-actions Bot
added a commit
that referenced
this pull request
Sep 13, 2026
…n the dictionary key and value expectations (#1075) by Valentin Breuß
This was referenced Oct 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



ContainsKeys,ContainsValues,DoesNotContainKeysandDoesNotContainValuestakeparams, so calling one with no arguments was the default call and asserted nothing at all: the empty needle made every key trivially present and every unwanted key trivially absent, so the expectation passed whatever the dictionary held.A
nullneedle was worse than unvalidated: it surfaced asInvalidOperationExceptionwrapping aNullReferenceExceptionfrom inside the constraint, rather than as anArgumentNullExceptionnaming the parameter. The singleThrowIfNullOrEmptyguard fixes both, and covers all sixteen overloads - each expectation exists twice per dictionary type, for the interface and the concrete class, acrossThatDictionaryandThatReadOnlyDictionary.The
nullsubject was never affected: these constraints derive fromWithNotNullValue, which already forces a failure when the subject isnull, so theirGuaranteesNotNullmarkings were and remain correct.