2
我在我的單元測試此代碼:如何NMock FileStream?
var file = m_Mockery.NewMock<IFile>();
Stream s = new MemoryStream();
Expect.Once.On(file).Method("OpenRead")
.With("someFile.mdb")
.Will(Return.Value(s));
...
...
...
// this runs the real code that contains the OpenRead call
productionCodeObj.DoIt("someFile.mdb");
m_Mockery.VerifyAllExpectationsHaveBeenMet();
問題是,當我打電話DOIT(它調用打開讀取),我得到一個異常說文件不能被發現。我誤解了nmock的作用嗎?我不希望我的單元測試打到真正的文件系統...