-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CombinatorialMemberData cannot be of type IEnumerable<object[]> #60
Comments
Right now I have to do something like this, which is a bit annoying. public static IEnumerable<string> GetValues
{
get
{
yield "Foo";
yield "Bar";
yield "Baz";
}
}
public static IEnumerable<object[]> GetValuesXunit
{
get { return GetValues.Select(x => new object[] { x }); }
}
[Theory]
[MemberData(nameof(GetValuesXunit))]
public void TestWithMemberData(string value)
{
}
public void TestWithCombinatorialData(
[CombinatorialMemberData(nameof(GetValues))] string value,
[CombinatorialValues(1, 2, 3)] int number)
{
} |
When I think about it, I'm not sure this is even possible to solve. It also seems like a rather odd constraint in xUnit. It should be able to verify any |
Perhaps using |
I don't see how these two would be compatible anyway. So I'd say this is By Design. |
What do you think about supporting |
I don't know anything about |
Yeah, it's also not very well documented, if at all. I haven't found any official documentation about it, but Andrew Lock has a nice blog post about it. I'm a bit reluctant whether it should be supported, given the feature itself is so poorly documented. If you think it's worth supporting, I'd be happy to create a PR for it, I just don't want to waste my time if you think the idea is pointless 🙂 |
Cool. But I still need to understand how that would be used and apply to this library. Thank you for volunteering to contribute to the library. I'd be interested to read sample code and a brief explanation of its behavior as it would apply to this library (no need to make it actually work yet). |
Supporting 1-dimensional The conversion from return new MyTheoryData().Select(d => (MyType)d.Single()); |
It's not technically impossible to support The idea is to allow this: public class Tests
{
public record MyTestCase(int Number, string Text);
public static readonly TheoryData<MyTestCase> MyTestCases = new(
new MyTestCase(1, "Foo"),
new MyTestCase(2, "Bar")
);
[Theory, CombinatorialData]
public void TestMyTestCases([CombinatorialMemberData(nameof(MyTestCases))] MyTestCase testCase, bool flag)
{
/*
This will give you:
testCase(1, "Foo"), true
testCase(1, "Foo"), false
testCase(2, "Bar"), true
testCase(2, "Bar"), false
*/
}
} |
It can also only support |
Reactivating due to recent activity. I'll review the proposal and get back to you soon. |
@AArnott have you had time to review the proposal yet? |
Reviewing this now. Sorry it took so long. public class Tests
{
public record MyTestCase(int Number, string Text);
public static readonly IEnumerable<MyTestCase> MyTestCases = [
new MyTestCase(1, "Foo"),
new MyTestCase(2, "Bar")
];
[Theory, CombinatorialData]
public void TestMyTestCases([CombinatorialMemberData(nameof(MyTestCases))] MyTestCase testCase, bool flag)
{
/*
This will give you:
testCase(1, "Foo"), true
testCase(1, "Foo"), false
testCase(2, "Bar"), true
testCase(2, "Bar"), false
*/
}
} So why then is your version so much better? |
Will this add support for |
@AArnott The difference is that using Does that make sense? :) |
The
CombinatorialMemberDataAttribute
requires the member to return an enumerable which is not anIEnumerable<object[]>
.This breaks compatibility with the Xunit
MemberData
attribute, which requires the member to return exactly anIEnumerable<object[]>
.We should figure out how to support the same member data type as Xunit support, so we can use the same member data for both
MemberData
andCombinatorialMemberData
.I think I might have broken that in the latest prerelease version.
The text was updated successfully, but these errors were encountered: