MbUnit Factory
Factories in MbUnit work in much the same way in v2 (where they have been available since the start) and v3, in v2 we would use a Factory as follows.
1: using System.Collections;
2: using MbUnit.Framework;
3:
4: public class ArrayListFactory
5: { 6: [Factory]
7: public ArrayList ProviderEmptyArrayList
8: { 9: get { return new ArrayList(); } 10: }
11:
12: [Factory]
13: public ArrayList ProviderArrayList
14: { 15: get
16: { 17: ArrayList list = new ArrayList();
18: list.Add(0);
19: list.Add(1);
20: return list;
21: }
22: }
23: }
As seen in the TypeFixture example this marks methods as Factory functions that can be reused across tests, for example by a ProviderFactory marked test etc. They are useful way of decorating methods as data providers rather than test methods. Let's look at a v3 example.
1: using System;
2: using System.Collections;
3: using MbUnit.Framework;
4:
5: [TestFixture]
6: public class FactoryTest
7: { 8: public ArrayList ProviderArrayList
9: { 10: get
11: { 12: var list = new ArrayList { 1, 2 }; 13: return list;
14: }
15: }
16:
17: [Test]
18: [Factory("ProviderArrayList")] 19: public void Test (int value)
20: { 21: Assert.GreaterThan(value, 0);
22: }
23: }
MbUnit v3 Factory attributes work differently here in that we mark a given method as a Factory by marking it's given name rather than decorating the actual method, on this example we mark the ProviderArrayList method as a Factory method but decorate our Test method instead.