I got these classes (which reads test files and which is to be tested in several different tests for different kinds of behavior):
[UsedImplicitly]
public class TestFileFixture : IDisposable
{
public TestFileFixture()
{
....
}
public IEnumerable<TestFile> AllTestFiles { get; } = new();
<more properties>
}
[CollectionDefinition(CollectionName)]
[UsedImplicitly]
public class TestFileCollectionFixture : ICollectionFixture<TestFileFixture>
{
// THE NAME OF THE FIXTURE
public const string CollectionName = "Test Files";
// This class has no code, and is never created. Its purpose is simply
// to be the place to apply [CollectionDefinition] and all the
// ICollectionFixture<> interfaces.
}
public class TestFile
{
...
}
Which I am using as standard by adding this to the test classes:
[Collection(TestFileCollectionFixture.CollectionName)]
Which works fine.
However I have a test, which I want to parameterise over the files - one test for each file. I have found no way to utilize MemberData or ClassData attributes for this. Such as:
[Theory]
**[<Some attribute>(TestFileCollectionFixture.CollectionName))]**
public void Given_GoodTestFiles_Expect_Parsed(TestFile testfile)
{
...
}
Is there a way to do this within the framework of XUnit?