IEnumerable extension method issue
I have this IEnumerable extension method that was downloaded from the
Internet and I am struggling to write a retrospective test that works
Extension Method
public static bool In<T>(this T source, params T[] list) where T :
IEnumerable
{
if (source == null) throw new ArgumentNullException("source");
return list.Contains(source);
}
Test
[TestMethod]
public void In()
{
IEnumerable<int> search = new int[] { 0 };
IEnumerable<int> found = new int[] { 0, 0, 1, 2, 3 };
IEnumerable<int> notFound = new int[] { 1, 5, 6, 7, 8 };
Assert.IsTrue(search.In(found));
Assert.IsFalse(search.In(notFound));
}
Results
All the code compiles but in both assertions the result from the extension
method returns false when I believe the first assertion search.In(found)
should return true.
Question
Am I doing something wrong in the calling code or is there an issue with
the extension?
No comments:
Post a Comment