I have a method that I want to test which expects an IEnumerable<T> as a parameter.
I’m currently mocking the contents of the IEnumerable<T> as follows (Using Moq):
var mockParent = new Mock<ICsvTreeGridExportable>();
var mockChild = new Mock<ICsvTreeGridExportable>();
How do it put these mocked objects inside an IEnumerable<T> so that I can pass them as a parameter to the method I want to test?
The method I’m testing expects to receive an IEnumerable<ICsvTreeGridExportable>
I would just create an array using the collection intialiser syntax. i.e.
Arrays in .NET implement the
IEnumerable<T>interface, so you’re all set.Note: If you want a “pure”
IEnumerable<T>(as Luke points out), you could use a little bit of LINQ to do that: