-
Notifications
You must be signed in to change notification settings - Fork 290
implemented non-generic overload for Assert.ContainsSingle #6736
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
base: main
Are you sure you want to change the base?
implemented non-generic overload for Assert.ContainsSingle #6736
Conversation
|
@Youssef1313 do we need to hndle AssertSingleInterpolatedStringHandler for non-generic collection as well
|
…rpolationStringHandler based off Assert.HasCount
|
removed the |
Evangelink
left a comment
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.
For the 2 new APIs, we could instead call the generic version by doing .Cast<object>(). There is a potential small performance hit but I think it's ok.
WDYT @Youssef1313
test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs
Outdated
Show resolved
Hide resolved
test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs
Outdated
Show resolved
Hide resolved
Evangelink
left a comment
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.
Reviving my earlier comment, I would personally use Cast<object> to avoid to have to maintain both implementations, the perf cost is IMO neglictible.
test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs
Outdated
Show resolved
Hide resolved
test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs
Show resolved
Hide resolved
|
@Evangelink I would personally avoid unsafe
{
var x = new int*[] { (int*)1 };
IEnumerable y = x;
Assert.ContainsSingle(y);
}It might also be worth adding such test :) |
|
Actually the scenario above might be invalid either way. |
…edicate functions to removed the unnesssary list, and I also added new unit tests to cover this Assert.ContainsSingle predicate function
test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs
Outdated
Show resolved
Hide resolved
test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs
Outdated
Show resolved
Hide resolved
…Contains.cs Co-authored-by: Amaury Levé <[email protected]>
…Contains.cs Co-authored-by: Amaury Levé <[email protected]>
This Pull Request fixes Assert.ContainsSingle should accept non-generic collections #6732
This Implementation involves an overload being added to the
Assert.ContainsSinglewhich allows non-generic collections like ArrayList.Current Behaviour
Assert.ContainsSinglethrows compile time error because it only accepts generic collections.Expected Behaviour
With this Implementation, A
ssert.ContainsSinglewill allow non-generic collection as seen below;