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.
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.
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é <amauryleve@microsoft.com>
…Contains.cs Co-authored-by: Amaury Levé <amauryleve@microsoft.com>
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;