Hi I'm new to TDD and xUnit so I want to test my method that is something like :
List<T> DeleteElements<T>(this List<T> a, List<T> b);
of course that's not the real method :) Is there any Assert method that I can use ? I think something like this would be nice
List<int> values = new List<int>() { 1, 2, 3 };
List<int> expected = new List<int>() { 1 };
List<int> actual = values.DeleteElements(new List<int>() { 2, 3 });
Assert.Exact(expected, actual);
Is there something like this ?
xUnit.Net recognizes collections so you just need to do
You can see other available collection assertions in CollectionAsserts.cs
For NUnit library collection comparison methods are
and
More details here: CollectionAssert
MbUnit also has collection assertions similar to NUnit: Assert.Collections.cs
With xUnit, should you want to cherry pick properties of each element to test you can use Assert.Collection.
This tests the expected count and ensures that each action is verified.
In the current version of XUnit (1.5) you can just use
The above method will do an element by element comparison of the two lists. I'm not sure if this works for any prior version.