I wanted to write unit tests for all files in specific path. For example - first run will be for file x, second for file y, etc.
But I have problem with converting IEnumerable<string>
to IEnumerable<object[]>
:
public static IEnumerable<object[]> ExpectedOutputFiles;
public JsonParserTests()
{
var files = Directory.EnumerateFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, GetOutputDataFolder()));
ExpectedOutputFiles = files; // <--- Error is here
}
[Theory]
[MemberData(nameof(ExpectedOutputFiles))]
public void OutputFile_ShouldBeParsedCorrectlyAsJSON_RFC8259(string filename)
{
// Test parsing output files with Newtonsoft.Json and System.Text.Json
var json = File.ReadAllText(filename);
JToken.Parse(json);
// System.Text.Json have better default options compatible with RFC 8259 specification
JsonDocument.Parse(json);
}
Is this possible, or should I create [Fact]
unit test and read files in foreach
loop?