-
Notifications
You must be signed in to change notification settings - Fork 252
OneOrMany implementation #507
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
Adds sorted insertion and a SingleOrDefault
accessor to the OneOrMany<T>
struct, and constrains T
to reference types.
- Introduces
AddSorted
method with comprehensive tests for empty, single, and two-item states (including invalid state) - Adds
SingleOrDefault
property with tests for empty, single, and multi-item scenarios - Adds a
where T : class
constraint toOneOrMany<T>
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/Ardalis.Specification/Internals/OneOrMany.cs | Constrain T to class , implement AddSorted and SingleOrDefault |
tests/.../OneOrManyTests.cs | Add tests covering AddSorted and SingleOrDefault behaviors |
Comments suppressed due to low confidence (2)
src/Ardalis.Specification/Internals/OneOrMany.cs:3
- Adding a
class
constraint is a breaking change for value types; consider documenting this or providing an alternative overload/behavior for structs if consumers rely on value-type usages.
internal struct OneOrMany<T> where T : class
tests/Ardalis.Specification.Tests/Internals/OneOrManyTests.cs:173
- Consider adding a test for
AddSorted
inserting into a multi-element list (e.g., 3+ items) to ensure the insertion logic works beyond two-element edge cases.
value.Should().BeEquivalentTo(new string[] { "foo", "bar" });
It addresses issue #506