我正在使用带有 NUnit 的 TestCaseSource。下面的代码生成表示归档条目的 TestCaseData 的 IEnumerable,它是测试的输入。
private class GithubRepositoryTestCasesFactory
{
private const string GithubRepositoryZip = "https://github.com/QualiSystems/tosca/archive/master.zip";
public static IEnumerable TestCases
{
get
{
using (var tempFile = new TempFile(Path.GetTempPath()))
using (var client = new WebClient())
{
client.DownloadFile(GithubRepositoryZip, tempFile.FilePath);
using (var zipToOpen = new FileStream(tempFile.FilePath, FileMode.Open))
using (var archive = new ZipArchive(zipToOpen, ZipArchiveMode.Read))
{
foreach (var archiveEntry in archive.Entries.Where(a =>
Path.GetExtension(a.Name).EqualsAny(".yaml", ".yml")))
{
yield return new TestCaseData(archiveEntry);
}
}
}
}
}
}
[Test, TestCaseSource(typeof (GithubRepositoryTestCasesFactory), "TestCases")]
public void Validate_Tosca_Files_In_Github_Repository_Of_Quali(ZipArchiveEntry zipArchiveEntry)
{
var toscaNetAnalyzer = new ToscaNetAnalyzer();
toscaNetAnalyzer.Analyze(new StreamReader(zipArchiveEntry.Open()));
}
上面的代码在以下行失败:
zipArchiveEntry.Open()
有一个例外:
System.ObjectDisposedException “无法访问已处置的对象。对象名称:'ZipArchive'。”
有没有办法控制为测试数据用例创建的对象的处置?