Skip to content

Generic overloads for CollectionAssert - #990

Closed
Daniel Lerch (daniel-lerch) wants to merge 1 commit into
microsoft:mainfrom
daniel-lerch:generic-collectionassert
Closed

Daniel Lerch (daniel-lerch) wants to merge 1 commit into
microsoft:mainfrom
daniel-lerch:generic-collectionassert

Conversation

@daniel-lerch

@daniel-lerch Daniel Lerch (daniel-lerch) commented Oct 2, 2021 •

Copy link
Copy Markdown

This pull request aimed to implement generic overloads for CollectionAssert to fix #989.

IEnumerable<T> vs IReadOnlyCollection<T>

New assertions use IEnumerable<T> instead of ICollection. This enables users to easily combine inline LINQ statements with CollectionAssert. Compared to IReadOnlyCollection<T> this is slightly slower to fail but I don't believe that failing unit tests are a major performance concern.

Pattern of multiple overloads

Assertions with IEnumerable<T> offer the same overloads as their ICollection predecessors. This pull request would give the opportunity to omit some overloads but as this pattern of arguments is consistent within Assert and CollectionAssert I see no reason for changing it.

Ambiguous calls

Adding overloads causes problems when users call assertions with parameters which implement both ICollection and IEnumerable<T>. Casting to one of these interfaces would lead to extremely ugly code and would be a breaking change.

In order to resolve this conflict I would introduce another class EnumerableAssert. Another option would be to use different names for the existing methods like CollectionAssert.AreEqualGeneric.

Medeni Baykal (@Haplois) So far I have only implemented overloads for AreEqual and AreNotEqual. Please take a look on my design decisions and tell me whether I should continue like this.

@ghost

Deleted user (ghost) commented Oct 2, 2021 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

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.

Generic overloads for CollectionAssert

1 participant