Skip to content

Allows Is.AnyOf to be called with arrays or other collections - #4356

Merged
OsirisTerje merged 1 commit into
nunit:masterfrom
manfred-brands:anyOf_Improvements
Apr 23, 2023
Merged

OsirisTerje merged 1 commit into
nunit:masterfrom
manfred-brands:anyOf_Improvements

Conversation

@manfred-brands

Copy link
Copy Markdown
Member

Fixes #4355

@SeanKilleen

Copy link
Copy Markdown
Member

That's....better, yeah. 😆

/// Returns the string representation of this constraint and the passed in arguments
/// </summary>
protected virtual string GetStringRepresentation()
protected string GetStringRepresentation(IEnumerable arguments)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Since Constraint is public, this overload technically becomes a new "public" API as a custom derived Constraint may try to call this. I usually default to protected in this case out of habit, but figured I'd ask: would private protected be wanted here instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to look up private protected because it logically didn't make sense. Since when does private mean internal?
But that is because protected internal means either derived (anywhere) or direct calls from the assembly instead of only derived classes inside the assembly

I think this can be protected in case an external Constraint has a single IEnumerable argument which by default gets formatted as just the type name.
There are at least two existing constraints: CollectionSubsetConstraint and CollectionSupersetConstraint which could benefit from this call as their current (tested against) string representation is: <s...setof System.Int32[]>

@stevenaw stevenaw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done, this looks good to me. Thanks @manfred-brands
I'd like to leave it open for another team member to take a look too, just in case I'm missing anything. I left a question about member visibility

@mikkelbu mikkelbu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also looks good to me, and @manfred-brands reasoning in the PR and the issue seems valid (at least he has given it more thought/examination than I have).

@OsirisTerje OsirisTerje left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM too.

@OsirisTerje
OsirisTerje merged commit fda616f into nunit:master Apr 23, 2023
@manfred-brands
manfred-brands deleted the anyOf_Improvements branch April 24, 2023 04:43
@ivan-gurin

Copy link
Copy Markdown
Contributor

Hey how about

public AnyOfConstraint AnyOf(params object?[]? expected)
?
I want Has.All.AnyOf() :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow Is.AnyOf to be called with arrays or other collections

6 participants