MbUnit features a specialized fixture for testing IEnumerable/IEnumerator implementations. This fixtures does a number of test automatically to ensure that the implementation follows the enumerator specification.
IEnumerable/IEnumerator
In order to use the fixture, you must
EnumerationFixture
DataProvider
CopyToProvider
In this example, we use the Data method to provide the data. The enumeration of ArrayList and int[] is tested.
ArrayList
int[]
[EnumerationFixture] public class EnumerationFixtureAttributeAttributeTest { private Random rnd = new Random(); private int count = 100; [DataProvider(typeof(ArrayList))] public ArrayList Data() { ArrayList list = new ArrayList(); for(int i=0;i<count;++i) list.Add(rnd.Next()); return list; } [CopyToProvider(typeof(ArrayList))] public ArrayList ArrayListProvider(IList source) { ArrayList list = new ArrayList(source); return list; } [CopyToProvider(typeof(int[]))] public int[] IntArrayProvider(IList source) { int[] list = new int[source.Count]; source.CopyTo(list,0); return list; } }
Page rendered at Friday, March 12, 2010 2:19:30 AM (Pacific Standard Time, UTC-08:00)
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.