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?
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)
From MSDN
Use CollectionAssert.IsSubsetOf
:
var list = new List<int>(){1,2,3};
var bigList = new List<int>(){1,2,3,4,5,6,7,8,9};
CollectionAssert.IsSubsetOf(list, bigList);
Same functionality, different syntax (NUnit's constraint style, closer to natural language, which is a quality of a good test):
var list = new List<int>(){1,2,3};
var bigList = new List<int>(){1,2,3,4,5,6,7,8,9};
Assert.That( list, Is.SubsetOf( bigList ) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With