Created
July 17, 2012 13:17
-
-
Save bartelink/3129350 to your computer and use it in GitHub Desktop.
ClassAutoData spiking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class XProvider : TupleTheoryDataProvider<int> | |
{ | |
protected override IEnumerable<int> Generate() | |
{ | |
return Enumerable.Range( 42, 2 ); | |
} | |
} | |
[Theory] | |
[ClassAutoData( typeof( XProvider ) )] | |
public static void MethodName( int x, int y ) | |
{ | |
Console.WriteLine( x + "," + y ); | |
} | |
public class ClassAutoDataAttribute : CompositeDataAttribute | |
{ | |
public ClassAutoDataAttribute( Type @class ) | |
: base( new DataAttribute[] { new ClassDataAttribute( @class ), new AutoDataAttribute() } ) | |
{ | |
} | |
} | |
public abstract class TupleTheoryDataProvider<T1> : TheoryDataProvider | |
{ | |
protected abstract IEnumerable<T1> Generate(); | |
protected override sealed IEnumerable<object[]> DataSource() | |
{ | |
return Generate().Select( x => new object[] { x } ); | |
} | |
} | |
public abstract class TheoryDataProvider : IEnumerable<object[]> | |
{ | |
public IEnumerator<object[]> GetEnumerator() | |
{ | |
return DataSource().GetEnumerator(); | |
} | |
IEnumerator IEnumerable.GetEnumerator() | |
{ | |
return DataSource().GetEnumerator(); | |
} | |
protected abstract IEnumerable<object[]> DataSource(); | |
} |
This gist now passes. Problem: It likely no longer fulfills lots of other goals now!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following makes the original (https://gist.github.com/3129350/15823b15b55ed803232a85296cbce8cc562ddcba) pass:
but that redundantly creates stuff already covered by the ClassData, which in my case is heavy