我目前有一个测试来测试我在 MVP 模型中的演示者。在我的演示者上,我有一个属性将调用我的视图,在我的测试中它被模拟了。在我的测试的初始化中,在我将 Presenter 上的 View 设置为模拟 View 后,我在 Presenter 上设置我的属性,它将调用此方法。
在我的测试中,我调用的方法没有 Expect.Call,但是当我运行时,我得到了这个 Rhino 模拟异常:
Rhino.Mocks.Exceptions.ExpectationViolationException: IView.MethodToInvoke(); 预期 #1,实际 #0..
根据我对 Rhino 模拟的理解,只要我在期望块之外的模拟上调用它不应该记录这个。我会想象测试通过。有没有通过的原因?
下面是一些代码来显示我的设置。
public class Presenter
{
public IView View;
public Presenter(IView view)
{
View = view
}
private int _property;
public int Property
get { return _property;}
set
{
_property = value;
View.MethodToInvoke();
}
}
...下面的测试代码...
[TestInitialize]
public void Initilize()
{
_mocks = new MockRepository();
_view = _mocks.StrictMock<IView>();
_presenter = new Presenter(_view);
_presenter.Property = 1;
}
[TestMethod]
public void Test()
{
Rhino.Mocks.With.Mocks(_mocks).Expecting(delegate
{
}).Verify(delegate
{
_presenter.SomeOtherMethod();
});
}