Tag: shim

使用Shims for ZipFile进行unit testing

我正在尝试对使用ZipFile.OpenRead的一些代码进行unit testing,从ZIP中提取一些XML文件(用moq编写unit testing) 有没有办法用我自己的结果替换对ZipFile.OpenRead的调用? 我已经在类似的情况下使用垫片,但我无法弄清楚在这种情况下该做什么,并且关于垫片的文档非常稀疏。 这是(部分)需要unit testing的方法: public IEnumerable ExtractXmlFromZip(string fileName) { var configs = new List(); using (var archive = ZipFile.OpenRead(fileName)) { foreach (ZipArchiveEntry entry in archive.Entries) { if (entry.FullName.EndsWith(“.xml”, StringComparison.OrdinalIgnoreCase)) { LoadConfigfromZipArchiveEntry(entry, configs) } } } return configs; }