且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

需要:.NET中的文件系统接口和实现

更新时间: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.