Skip to content

Class data derived from TheoryData<SomeType[]> is broken #3053

@bradwilson

Description

@bradwilson

I still experience this issue in v2.9.2 when using the ClassData attribute with a class derived from TheoryData.
See the modified example with the exceptions next to the Add calls.

    [Theory]
    [ClassData(typeof(ExampleParameters))]
    public void ExampleParameterizedTestMethod(string[] values)
    {
        Assert.All(values, s => Assert.True(s.Length < 10));
    }

    private sealed class ExampleParameters : TheoryData<string[]>
    {
        public ExampleParameters ()
        {
            Add(new string[] { "0" }); //System.ArgumentException: Object of type 'System.String' cannot be converted to type 'System.String[]'.
            Add(new string[] { "0", "2" }); //System.InvalidOperationException: The test method expected 1 parameter value, but 2 parameter values were provided.
            Add(new string[] { "0", "2", "4" }); //System.InvalidOperationException: The test method expected 1 parameter value, but 3 parameter values were provided.
        }
    }

Originally posted by @afuersch in #3031 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA fault in an existing featureCore frameworkxunit.v3.core

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions