Jon Jon - 3 months ago 16
C# Question

Using CollectionAssert.Contains against a collection

I want to write something like:

var list = new List<int>(){1,2,3};
var bigList = new List<int>(){1,2,3,4,5,6,7,8,9};

CollectionAssert.Contains(bigList, list);


I can get an error similar to:

Expected: collection containing < 1,2,3 >
But was: < 1,2,3,4,5,6,7,8,9 >


Is it possible to use the contains method against another collection?

Answer

The signature is

   CollectionAssert.Contains (ICollection collection, Object element) 

And it checks if element (singular) is inside collection.
It is not a method to check for sub-lists.

You should probably use:

    CollectionAssert.IsSubsetOf (ICollection subset, ICollection superset) 
Comments