更新时间:2022-06-01 01:04:52
我对于静态 System.IO.File
和目录
方法的已写入适配器。然后在我的课程中,我执行以下操作:
I've written adapters for the static System.IO.File
and Directory
methods. Then in my classes I do the following:
public class MyService {
public IFile File {private get;set;}
public MyService() {
File = new FileImpl();
}
public void DoSomething() {
File.ReadAllText("somefile");
}
}
然后,您可以将模拟注入为IFile进行测试。
Then you can inject a mock as IFile for testing.