nunit/nunit-framework — pull request #56 by markwhitfeld (2013-11-11 14:29:56+00:00)
Title: Proposed solution for Issue #33

fixing issue #33: "TestCaseSource cannot refer to a parameterized test fixture"
- allow specifying constructor parameters after data source method name
- for the case where no method name would be required for the data source (ie, when the data source class itself implements IEnumerable), require the user to provide null for the method name
- proposed to cater for the case where the only parameter to the constructor is a string
- had a random test failure whilst working on Issue #33
- original code tried to get true/false variance in 10 attempts:
the new test attempts up to 10000 times to get variance, quitting after the first time variance is found and bailing out with a useful message if variance isn't found in 10000 attempts.

```C#
// code samples (from tests)
// class which implements IEnumerable:
[Test, TestCaseSource(typeof(DataSourceClass), null, "foo")]
public void SourceCanBeInstanceOfIEnumerableWithParameters(string source)
{
Assert.AreEqual("foo", source);
}

class DataSourceClass : IEnumerable
{
public DataSourceClass()
{
}

private readonly string enumeratorOverride;

public DataSourceClass(string enumeratorOverride)
{
this.enumeratorOverride = enumeratorOverride;
}

public IEnumerator GetEnumerator()
{
yield return this.enumeratorOverride ?? "DataSourceClass";
}
}

// using a method which returns IEnumerable on a data source class
[Test, TestCaseSource(typeof(DataSourceClassWithMethod), "GetStuff", "foo")]
public void SourceCanHaveMethodProducingIEnumerableWithParameters(string source)
{
string[] items = new[] { "foo1", "foo2", "foo3" };
bool found = false;
for (int i = 0; i < items.Length; i++)
{
if (items[i] == source)
{
found = true;
}
}
Assert.IsTrue(found);
}

class DataSourceClassWithMethod
{
private readonly string enumeratorPrepend;

public DataSourceClassWithMethod(string enumeratorPrepend)
{
this.enumeratorPrepend = enumeratorPrepend;
}
public IEnumerable GetStuff()
{
return new[] { enumeratorPrepend+"1", enumeratorPrepend+"2", enumeratorPrepend+"3" };
}
}
```