I'm trying to create AutoPropertyDataAttribute
based on CompositeDataAttribute
from this example AutoFixture: PropertyData and heterogeneous parameters.
It works with single set of parameters, but fails with more sets of parameters. Here is code:
public static IEnumerable<object[]> NumericSequence
{
get
{
yield return new object[] {1};
//yield return new object[] {2};
}
}
[Theory]
[AutoPropertyData("NumericSequence")]
public void Test(int? p1, int? p2, int? p3)
{
Assert.NotNull(p1);
Assert.NotNull(p2);
}
public class AutoPropertyDataAttribute : CompositeDataAttribute
{
public AutoPropertyDataAttribute(string propertyName)
: base(
new DataAttribute[] {
new PropertyDataAttribute(propertyName),
new AutoDataAttribute()
})
{
}
}
Trying to uncomment the second yield
will break test with message:
System.InvalidOperationException: Expected 2 parameters, got 1 parameters
at Ploeh.AutoFixture.Xunit.CompositeDataAttribute.<GetData>d__0.MoveNext()
at Xunit.Extensions.TheoryAttribute.<GetData>d__7.MoveNext()
at Xunit.Extensions.TheoryAttribute.EnumerateTestCommands(IMethodInfo method)
Same happens with ClassDataAttribute
yield
? It provides the data forp2
or it provides the data forp1
on the 2nd run? – YankeeCompositeDataAttribute
class defined in AutoFixture. However this class is programmed against the base of all data theories, theDataAttribute
class, so it looks like a violation of the LSP inPropertyData
andClassDataAttribute
classes defined in xUnit.net. I will keep this thread updated. – YankeePropertyData
orClassData
. I have provided an answer below. Hope that helps :) – Yankee