应该能够做这样的事情:
[TestClass]
public class MyTestClass{
private IService _service;
[TestInitialize]
public void Setup(){
_service = MockRepository.GenerateStrictMock<IService, ICommunicationObject>();
}
[TestMethod]
public void TestWhatsGoingOn(){
_service.Expect(.....).Return(.....);
//This will test the close is called too (hence the ICommunicationObject above)
((ICommunicationObject)_service).Expect(r => r.Close());
}
[TestCleanup]
public void CleanItUp{
_service.VerifyAllExpectations();
}
这意味着您也可以测试 close 方法是否被调用(如预期的那样)
我认为你需要生成一个严格的模拟而不是部分......
当然,如果你想断言 .Abort() 调用是在异常处理等期间进行的 - 你可以这样做:
((ICommunicationObject)_service).Expect(r => r.Abort());