Skip to content

Conversation

fiseni
Copy link
Collaborator

@fiseni fiseni commented Jun 12, 2025

It addresses issue #506

@fiseni fiseni linked an issue Jun 12, 2025 that may be closed by this pull request
@fiseni fiseni requested a review from Copilot June 12, 2025 13:43
Copy link

@Copilot 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

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 to OneOrMany<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" });

@fiseni fiseni merged commit fde098d into main Jun 12, 2025
1 check passed
@fiseni fiseni deleted the fiseni/oneormany branch June 12, 2025 17:01
@fiseni fiseni linked an issue Jun 13, 2025 that may be closed by this pull request
This was referenced Aug 20, 2025
This was referenced Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use OneOrMany for all internal collections
1 participant